summaryrefslogtreecommitdiff
path: root/extensions/file/01_file.js
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-06-05 23:10:07 +0200
committerGitHub <noreply@github.com>2021-06-05 23:10:07 +0200
commitc73ef5fa143b473677d4cab069241ff018e0c971 (patch)
treef13f3ddb1741a81138240c36846e2a23fd562a02 /extensions/file/01_file.js
parentbb0c90cadbb99784681a2acac1fd65ac7f802297 (diff)
refactor(web): use encoding_rs for text encoding (#10844)
This commit removes all JS based text encoding / text decoding. Instead encoding now happens in Rust via encoding_rs (already in tree). This implementation retains stream support, but adds the last missing encodings. We are incredibly close to 100% WPT on text encoding now. This should reduce our baseline heap by quite a bit.
Diffstat (limited to 'extensions/file/01_file.js')
-rw-r--r--extensions/file/01_file.js8
1 files changed, 3 insertions, 5 deletions
diff --git a/extensions/file/01_file.js b/extensions/file/01_file.js
index c34561b5e..c9c66127f 100644
--- a/extensions/file/01_file.js
+++ b/extensions/file/01_file.js
@@ -12,6 +12,7 @@
"use strict";
((window) => {
+ const core = window.Deno.core;
const webidl = window.__bootstrap.webidl;
// TODO(lucacasonato): this needs to not be hardcoded and instead depend on
@@ -85,9 +86,6 @@
return finalBytes;
}
- const utf8Encoder = new TextEncoder();
- const utf8Decoder = new TextDecoder();
-
/** @typedef {BufferSource | Blob | string} BlobPart */
/**
@@ -116,7 +114,7 @@
if (endings == "native") {
s = convertLineEndingsToNative(s);
}
- bytesArrays.push(utf8Encoder.encode(s));
+ bytesArrays.push(core.encode(s));
} else {
throw new TypeError("Unreachable code (invalild element type)");
}
@@ -276,7 +274,7 @@
async text() {
webidl.assertBranded(this, Blob);
const buffer = await this.arrayBuffer();
- return utf8Decoder.decode(buffer);
+ return core.decode(new Uint8Array(buffer));
}
/**