aboutsummaryrefslogtreecommitdiff
path: root/lib/docx-reader.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-11 20:21:10 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-11 20:21:10 +0100
commit1d9da5d8ed67e3f31ebda8f12082e6e607c673f0 (patch)
tree379df4a95ecafbae772d8053e5a96b2fb90e73d1 /lib/docx-reader.js
parentc57b900666a82b4ccce033a923e53906255078c0 (diff)
Allow Uint8Array to be input for conversion
Diffstat (limited to 'lib/docx-reader.js')
-rw-r--r--lib/docx-reader.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/docx-reader.js b/lib/docx-reader.js
index 832ff31..09bc8c1 100644
--- a/lib/docx-reader.js
+++ b/lib/docx-reader.js
@@ -8,6 +8,7 @@ var unzip = {
var path = require("path");
var fs = require("fs");
var Buffers = require("buffers");
+var streamBuffers = require("stream-buffers");
var xmlreader = require("./xmlreader");
var documents = require("./documents");
@@ -19,9 +20,14 @@ function read(options) {
var docxFile;
if (options.path) {
var zipPath = docxFile;
- docxFile = openZip(options.path);
+ docxFile = openZipStream(fs.createReadStream(options.path));
} else if (options.file) {
docxFile = options.file;
+ } else if (options.uint8Array) {
+ var buffer = new Buffer(options.uint8Array);
+ var stream = new streamBuffers.ReadableStreamBuffer();
+ stream.put(buffer);
+ docxFile = openZipStream(stream);
} else {
return q.reject(new Error("Could not find file in options"));
}
@@ -38,12 +44,12 @@ function read(options) {
});
}
-function openZip(zipPath) {
+function openZipStream(stream) {
var deferred = q.defer();
var names = [];
var files = {};
- fs.createReadStream(zipPath)
+ stream
.pipe(unzip.Parse())
.on("entry", function(entry) {
names.push(entry.path);