From 06a8f7548e480b3f46e979c52629601b611b5b78 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 6 Jan 2014 22:10:58 +0000 Subject: Move zip reading into unzip.js --- lib/docx-reader.js | 12 +----------- lib/unzip.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/docx-reader.js b/lib/docx-reader.js index 2215b35..e21f847 100644 --- a/lib/docx-reader.js +++ b/lib/docx-reader.js @@ -3,7 +3,6 @@ exports.read = read; var q = require("q"); var unzip = require("./unzip"); var path = require("path"); -var fs = require("fs"); var readXmlFromZipFile = require("./office-xml-reader").readXmlFromZipFile; var documents = require("./documents"); @@ -15,16 +14,7 @@ var Result = require("./results").Result; function read(options) { - var docxFile; - if (options.path) { - docxFile = unzip.unzipStream(fs.createReadStream(options.path)); - } else if (options.file) { - docxFile = options.file; - } else if (options.uint8Array) { - docxFile = unzip.unzipUint8Array(options.uint8Array); - } else { - return q.reject(new Error("Could not find file in options")); - } + var docxFile = unzip.openZip(options); return q.when(docxFile, function(docxFile) { return q.all([ readRelationshipsFromZipFile(docxFile), diff --git a/lib/unzip.js b/lib/unzip.js index 858a4da..98709e8 100644 --- a/lib/unzip.js +++ b/lib/unzip.js @@ -1,13 +1,24 @@ -exports.unzipUint8Array = unzipUint8Array; -exports.unzipStream = unzipStream; +exports.openZip = openZip; var q = require("q"); +var fs = require("fs"); var unzip = { Parse: require("unzip/lib/parse") }; var Buffers = require("buffers"); var streamBuffers = require("stream-buffers"); +function openZip(options) { + if (options.path) { + return unzipStream(fs.createReadStream(options.path)); + } else if (options.file) { + return options.file; + } else if (options.uint8Array) { + return unzipUint8Array(options.uint8Array); + } else { + return q.reject(new Error("Could not find file in options")); + } +} function unzipUint8Array(array) { var buffer = new Buffer(array); -- cgit v1.2.3