summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/bench/deno_common.js4
-rw-r--r--ext/web/09_file.js28
2 files changed, 20 insertions, 12 deletions
diff --git a/cli/bench/deno_common.js b/cli/bench/deno_common.js
index 629ed7669..284f9d216 100644
--- a/cli/bench/deno_common.js
+++ b/cli/bench/deno_common.js
@@ -39,7 +39,7 @@ function benchStats(name, n, t1, t2) {
function benchB64RtLong() {
const input = "long-string".repeat(99999);
- benchSync("b64_rt_long", 1e2, () => {
+ benchSync("b64_rt_long", 100, () => {
atob(btoa(input));
});
}
@@ -58,7 +58,7 @@ function benchUrlParse() {
function benchLargeBlobText() {
const input = "long-string".repeat(999_999);
- benchSync("blob_text_large", 3, () => {
+ benchSync("blob_text_large", 100, () => {
new Blob([input]).text();
});
}
diff --git a/ext/web/09_file.js b/ext/web/09_file.js
index 2117a0835..50cce9004 100644
--- a/ext/web/09_file.js
+++ b/ext/web/09_file.js
@@ -340,8 +340,22 @@
*/
async text() {
webidl.assertBranded(this, BlobPrototype);
- const buffer = await this.arrayBuffer();
- return core.decode(new Uint8Array(buffer));
+ const buffer = await this.#u8Array(this.size);
+ return core.decode(buffer);
+ }
+
+ async #u8Array(size) {
+ const bytes = new Uint8Array(size);
+ const partIterator = toIterator(this[_parts]);
+ let offset = 0;
+ for await (const chunk of partIterator) {
+ const byteLength = chunk.byteLength;
+ if (byteLength > 0) {
+ TypedArrayPrototypeSet(bytes, chunk, offset);
+ offset += byteLength;
+ }
+ }
+ return bytes;
}
/**
@@ -349,14 +363,8 @@
*/
async arrayBuffer() {
webidl.assertBranded(this, BlobPrototype);
- const stream = this.stream();
- const bytes = new Uint8Array(this.size);
- let offset = 0;
- for await (const chunk of stream) {
- TypedArrayPrototypeSet(bytes, chunk, offset);
- offset += chunk.byteLength;
- }
- return bytes.buffer;
+ const buf = await this.#u8Array(this.size);
+ return buf.buffer;
}
[SymbolFor("Deno.customInspect")](inspect) {