diff options
| author | Michael Williamson <mike@zwobble.org> | 2021-08-27 19:42:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2021-08-27 19:42:39 +0100 |
| commit | b6ab371b1f004a627f7390c442b6406d1f2be499 (patch) | |
| tree | 046ea608e145bd7c27fb203d319a08f530375ead /lib | |
| parent | e0bb3d1cdac963f2c07ab782ad945d585a9babeb (diff) | |
Update JSZip to 3.2.0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/index.js | 7 | ||||
| -rw-r--r-- | lib/zipfile.js | 52 |
2 files changed, 32 insertions, 27 deletions
diff --git a/lib/index.js b/lib/index.js index 683352b..ac9f634 100644 --- a/lib/index.js +++ b/lib/index.js @@ -92,8 +92,13 @@ function embedStyleMap(input, styleMap) { return docxStyleMap.writeStyleMap(docxFile, styleMap); }) .then(function(docxFile) { + return docxFile.toBuffer(); + }) + .then(function(buffer) { return { - toBuffer: docxFile.toBuffer + toBuffer: function() { + return buffer; + } }; }); } diff --git a/lib/zipfile.js b/lib/zipfile.js index cae9567..d38a9a4 100644 --- a/lib/zipfile.js +++ b/lib/zipfile.js @@ -1,41 +1,41 @@ var JSZip = require("jszip"); -var promises = require("./promises"); - exports.openArrayBuffer = openArrayBuffer; exports.splitPath = splitPath; exports.joinPath = joinPath; function openArrayBuffer(arrayBuffer) { - var zipFile = new JSZip(arrayBuffer); - function exists(name) { - return zipFile.file(name) !== null; - } + return JSZip.loadAsync(arrayBuffer).then(function(zipFile) { + function exists(name) { + return zipFile.file(name) !== null; + } - function read(name, encoding) { - var array = zipFile.file(name).asUint8Array(); - var buffer = uint8ArrayToBuffer(array); - if (encoding) { - return promises.when(buffer.toString(encoding)); - } else { - return promises.when(buffer); + function read(name, encoding) { + return zipFile.file(name).async("uint8array").then(function(array) { + var buffer = uint8ArrayToBuffer(array); + if (encoding) { + return buffer.toString(encoding); + } else { + return buffer; + } + }); } - } - function write(name, contents) { - zipFile.file(name, contents); - } + function write(name, contents) { + zipFile.file(name, contents); + } - function toBuffer() { - return zipFile.generate({type: "nodebuffer"}); - } + function toBuffer() { + return zipFile.generateAsync({type: "nodebuffer"}); + } - return { - exists: exists, - read: read, - write: write, - toBuffer: toBuffer - }; + return { + exists: exists, + read: read, + write: write, + toBuffer: toBuffer + }; + }); } function uint8ArrayToBuffer(array) { |
