diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-07-02 23:04:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 16:04:08 +0200 |
commit | f78a60e882dbcbf43c8abd710733e5fa73e9ed4d (patch) | |
tree | cb26a3f501cba7e40d102d2a9a4f302e4bcb7ed8 /ext/web | |
parent | 8db420d552bc1d480a21748d73b566b623a266c1 (diff) |
feat(ext/web): add `Blob.prototype.bytes()` (#24148)
Diffstat (limited to 'ext/web')
-rw-r--r-- | ext/web/09_file.js | 26 | ||||
-rw-r--r-- | ext/web/lib.deno_web.d.ts | 1 |
2 files changed, 20 insertions, 7 deletions
diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 482a14012..7c1d79ce3 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -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]); @@ -414,6 +409,15 @@ class Blob { } /** + * @returns {Promise<string>} + */ + async text() { + webidl.assertBranded(this, BlobPrototype); + const buffer = await this.#u8Array(this.size); + return core.decode(buffer); + } + + /** * @returns {Promise<ArrayBuffer>} */ async 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({ diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index 36c77ef81..2fdf1c880 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -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>; |