Skip to content

Commit 7110932

Browse files
petamorikenzebreus
authored andcommitted
feat(ext/web): add Blob.prototype.bytes() (denoland#24148)
1 parent 8ff0078 commit 7110932

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

cli/tsc/dts/lib.dom.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3121,6 +3121,8 @@ interface Blob {
31213121
readonly type: string;
31223122
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */
31233123
arrayBuffer(): Promise<ArrayBuffer>;
3124+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */
3125+
bytes(): Promise<Uint8Array>;
31243126
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
31253127
slice(start?: number, end?: number, contentType?: string): Blob;
31263128
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */

cli/tsc/dts/lib.webworker.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,8 @@ interface Blob {
10071007
readonly type: string;
10081008
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */
10091009
arrayBuffer(): Promise<ArrayBuffer>;
1010+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */
1011+
bytes(): Promise<Uint8Array>;
10101012
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
10111013
slice(start?: number, end?: number, contentType?: string): Blob;
10121014
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */

ext/web/09_file.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,9 @@ class Blob {
387387
}
388388

389389
/**
390-
* @returns {Promise<string>}
390+
* @param {number} size
391+
* @returns {Promise<Uint8Array>}
391392
*/
392-
async text() {
393-
webidl.assertBranded(this, BlobPrototype);
394-
const buffer = await this.#u8Array(this.size);
395-
return core.decode(buffer);
396-
}
397-
398393
async #u8Array(size) {
399394
const bytes = new Uint8Array(size);
400395
const partIterator = toIterator(this[_parts]);
@@ -413,6 +408,15 @@ class Blob {
413408
return bytes;
414409
}
415410

411+
/**
412+
* @returns {Promise<string>}
413+
*/
414+
async text() {
415+
webidl.assertBranded(this, BlobPrototype);
416+
const buffer = await this.#u8Array(this.size);
417+
return core.decode(buffer);
418+
}
419+
416420
/**
417421
* @returns {Promise<ArrayBuffer>}
418422
*/
@@ -422,6 +426,14 @@ class Blob {
422426
return TypedArrayPrototypeGetBuffer(buf);
423427
}
424428

429+
/**
430+
* @returns {Promise<Uint8Array>}
431+
*/
432+
async bytes() {
433+
webidl.assertBranded(this, BlobPrototype);
434+
return await this.#u8Array(this.size);
435+
}
436+
425437
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
426438
return inspect(
427439
createFilteredInspectProxy({

ext/web/lib.deno_web.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ declare interface Blob {
533533
readonly size: number;
534534
readonly type: string;
535535
arrayBuffer(): Promise<ArrayBuffer>;
536+
bytes(): Promise<Uint8Array>;
536537
slice(start?: number, end?: number, contentType?: string): Blob;
537538
stream(): ReadableStream<Uint8Array>;
538539
text(): Promise<string>;

tests/wpt/runner/expectation.json

+2-10
Original file line numberDiff line numberDiff line change
@@ -10109,8 +10109,8 @@
1010910109
"Blob-text.any.worker.html": true,
1011010110
"Blob-in-worker.worker.html": true,
1011110111
"Blob-constructor-dom.window.html": false,
10112-
"Blob-bytes.any.html": false,
10113-
"Blob-bytes.any.worker.html": false,
10112+
"Blob-bytes.any.html": true,
10113+
"Blob-bytes.any.worker.html": true,
1011410114
"Blob-constructor-endings.html": false
1011510115
},
1011610116
"file": {
@@ -10183,9 +10183,6 @@
1018310183
"filereader_result.any.worker.html": true
1018410184
},
1018510185
"idlharness.any.html": [
10186-
"Blob interface: operation bytes()",
10187-
"Blob interface: new Blob([\"TEST\"]) must inherit property \"bytes()\" with the proper type",
10188-
"Blob interface: new File([\"myFileBits\"], \"myFileName\") must inherit property \"bytes()\" with the proper type",
1018910186
"FileList interface: existence and properties of interface object",
1019010187
"FileList interface object length",
1019110188
"FileList interface object name",
@@ -10196,9 +10193,6 @@
1019610193
"FileList interface: attribute length"
1019710194
],
1019810195
"idlharness.any.worker.html": [
10199-
"Blob interface: operation bytes()",
10200-
"Blob interface: new Blob([\"TEST\"]) must inherit property \"bytes()\" with the proper type",
10201-
"Blob interface: new File([\"myFileBits\"], \"myFileName\") must inherit property \"bytes()\" with the proper type",
1020210196
"FileList interface: existence and properties of interface object",
1020310197
"FileList interface object length",
1020410198
"FileList interface object name",
@@ -10220,7 +10214,6 @@
1022010214
],
1022110215
"FileReaderSync.worker.html": false,
1022210216
"idlharness.worker.html": [
10223-
"Blob interface: operation bytes()",
1022410217
"FileList interface: existence and properties of interface object",
1022510218
"FileList interface object length",
1022610219
"FileList interface object name",
@@ -10265,7 +10258,6 @@
1026510258
"Service worker test setup"
1026610259
],
1026710260
"idlharness.html": [
10268-
"Blob interface: operation bytes()",
1026910261
"FileList interface: existence and properties of interface object",
1027010262
"FileList interface object length",
1027110263
"FileList interface object name",

0 commit comments

Comments
 (0)