aboutsummaryrefslogtreecommitdiff
path: root/lib/zipfile.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-05-28 12:24:16 +0100
committerMichael Williamson <mike@zwobble.org>2023-05-28 12:24:16 +0100
commitb2b2c35715985f624e6b696fd87140fa6056318f (patch)
treea8015940e1d4b4bae1422af8e99277126e1df029 /lib/zipfile.js
parent1ce7c085668fd978f4f343b41db7f76f33145de5 (diff)
Avoid use of Buffer
Diffstat (limited to 'lib/zipfile.js')
-rw-r--r--lib/zipfile.js19
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/zipfile.js b/lib/zipfile.js
index d38a9a4..85dde81 100644
--- a/lib/zipfile.js
+++ b/lib/zipfile.js
@@ -1,3 +1,4 @@
+var base64js = require("base64-js");
var JSZip = require("jszip");
exports.openArrayBuffer = openArrayBuffer;
@@ -12,11 +13,13 @@ function openArrayBuffer(arrayBuffer) {
function read(name, encoding) {
return zipFile.file(name).async("uint8array").then(function(array) {
- var buffer = uint8ArrayToBuffer(array);
- if (encoding) {
- return buffer.toString(encoding);
+ if (encoding === "base64") {
+ return base64js.fromByteArray(array);
+ } else if (encoding) {
+ var decoder = new TextDecoder(encoding);
+ return decoder.decode(array);
} else {
- return buffer;
+ return array;
}
});
}
@@ -38,14 +41,6 @@ function openArrayBuffer(arrayBuffer) {
});
}
-function uint8ArrayToBuffer(array) {
- if (Buffer.from && Buffer.from !== Uint8Array.from) {
- return Buffer.from(array);
- } else {
- return new Buffer(array);
- }
-}
-
function splitPath(path) {
var lastIndex = path.lastIndexOf("/");
if (lastIndex === -1) {