diff options
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) { |
