From f78a60e882dbcbf43c8abd710733e5fa73e9ed4d Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Tue, 2 Jul 2024 23:04:08 +0900 Subject: feat(ext/web): add `Blob.prototype.bytes()` (#24148) --- ext/web/09_file.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'ext/web/09_file.js') 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} + * @param {number} size + * @returns {Promise} */ - 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} + */ + async text() { + webidl.assertBranded(this, BlobPrototype); + const buffer = await this.#u8Array(this.size); + return core.decode(buffer); + } + /** * @returns {Promise} */ @@ -422,6 +426,14 @@ class Blob { return TypedArrayPrototypeGetBuffer(buf); } + /** + * @returns {Promise} + */ + async bytes() { + webidl.assertBranded(this, BlobPrototype); + return await this.#u8Array(this.size); + } + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { return inspect( createFilteredInspectProxy({ -- cgit v1.2.3