mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat(ext/web): add Blob.prototype.bytes()
(#24148)
This commit is contained in:
parent
8db420d552
commit
f78a60e882
5 changed files with 26 additions and 17 deletions
2
cli/tsc/dts/lib.dom.d.ts
vendored
2
cli/tsc/dts/lib.dom.d.ts
vendored
|
@ -3121,6 +3121,8 @@ interface Blob {
|
|||
readonly type: string;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */
|
||||
bytes(): Promise<Uint8Array>;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
||||
slice(start?: number, end?: number, contentType?: string): Blob;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */
|
||||
|
|
2
cli/tsc/dts/lib.webworker.d.ts
vendored
2
cli/tsc/dts/lib.webworker.d.ts
vendored
|
@ -1007,6 +1007,8 @@ interface Blob {
|
|||
readonly type: string;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */
|
||||
bytes(): Promise<Uint8Array>;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
|
||||
slice(start?: number, end?: number, contentType?: string): Blob;
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */
|
||||
|
|
|
@ -387,14 +387,9 @@ class Blob {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<string>}
|
||||
* @param {number} size
|
||||
* @returns {Promise<Uint8Array>}
|
||||
*/
|
||||
async text() {
|
||||
webidl.assertBranded(this, BlobPrototype);
|
||||
const buffer = await this.#u8Array(this.size);
|
||||
return core.decode(buffer);
|
||||
}
|
||||
|
||||
async #u8Array(size) {
|
||||
const bytes = new Uint8Array(size);
|
||||
const partIterator = toIterator(this[_parts]);
|
||||
|
@ -413,6 +408,15 @@ class Blob {
|
|||
return bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async text() {
|
||||
webidl.assertBranded(this, BlobPrototype);
|
||||
const buffer = await this.#u8Array(this.size);
|
||||
return core.decode(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<ArrayBuffer>}
|
||||
*/
|
||||
|
@ -422,6 +426,14 @@ class Blob {
|
|||
return TypedArrayPrototypeGetBuffer(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<Uint8Array>}
|
||||
*/
|
||||
async bytes() {
|
||||
webidl.assertBranded(this, BlobPrototype);
|
||||
return await this.#u8Array(this.size);
|
||||
}
|
||||
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
|
||||
return inspect(
|
||||
createFilteredInspectProxy({
|
||||
|
|
1
ext/web/lib.deno_web.d.ts
vendored
1
ext/web/lib.deno_web.d.ts
vendored
|
@ -533,6 +533,7 @@ declare interface Blob {
|
|||
readonly size: number;
|
||||
readonly type: string;
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
bytes(): Promise<Uint8Array>;
|
||||
slice(start?: number, end?: number, contentType?: string): Blob;
|
||||
stream(): ReadableStream<Uint8Array>;
|
||||
text(): Promise<string>;
|
||||
|
|
|
@ -10109,8 +10109,8 @@
|
|||
"Blob-text.any.worker.html": true,
|
||||
"Blob-in-worker.worker.html": true,
|
||||
"Blob-constructor-dom.window.html": false,
|
||||
"Blob-bytes.any.html": false,
|
||||
"Blob-bytes.any.worker.html": false,
|
||||
"Blob-bytes.any.html": true,
|
||||
"Blob-bytes.any.worker.html": true,
|
||||
"Blob-constructor-endings.html": false
|
||||
},
|
||||
"file": {
|
||||
|
@ -10183,9 +10183,6 @@
|
|||
"filereader_result.any.worker.html": true
|
||||
},
|
||||
"idlharness.any.html": [
|
||||
"Blob interface: operation bytes()",
|
||||
"Blob interface: new Blob([\"TEST\"]) must inherit property \"bytes()\" with the proper type",
|
||||
"Blob interface: new File([\"myFileBits\"], \"myFileName\") must inherit property \"bytes()\" with the proper type",
|
||||
"FileList interface: existence and properties of interface object",
|
||||
"FileList interface object length",
|
||||
"FileList interface object name",
|
||||
|
@ -10196,9 +10193,6 @@
|
|||
"FileList interface: attribute length"
|
||||
],
|
||||
"idlharness.any.worker.html": [
|
||||
"Blob interface: operation bytes()",
|
||||
"Blob interface: new Blob([\"TEST\"]) must inherit property \"bytes()\" with the proper type",
|
||||
"Blob interface: new File([\"myFileBits\"], \"myFileName\") must inherit property \"bytes()\" with the proper type",
|
||||
"FileList interface: existence and properties of interface object",
|
||||
"FileList interface object length",
|
||||
"FileList interface object name",
|
||||
|
@ -10220,7 +10214,6 @@
|
|||
],
|
||||
"FileReaderSync.worker.html": false,
|
||||
"idlharness.worker.html": [
|
||||
"Blob interface: operation bytes()",
|
||||
"FileList interface: existence and properties of interface object",
|
||||
"FileList interface object length",
|
||||
"FileList interface object name",
|
||||
|
@ -10265,7 +10258,6 @@
|
|||
"Service worker test setup"
|
||||
],
|
||||
"idlharness.html": [
|
||||
"Blob interface: operation bytes()",
|
||||
"FileList interface: existence and properties of interface object",
|
||||
"FileList interface object length",
|
||||
"FileList interface object name",
|
||||
|
|
Loading…
Reference in a new issue