aboutsummaryrefslogtreecommitdiff
path: root/lib/zipfile.js
diff options
context:
space:
mode:
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) {