diff options
Diffstat (limited to 'browser')
| -rw-r--r-- | browser/unzip.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/browser/unzip.js b/browser/unzip.js new file mode 100644 index 0000000..97fcdb1 --- /dev/null +++ b/browser/unzip.js @@ -0,0 +1,32 @@ +var q = require("q"); + +exports.openZip = openZip; + +function openZip(options) { + if (options.arrayBuffer) { + return openArrayBuffer(options.arrayBuffer); + } else { + return q.reject(new Error("Could not find file in options")); + } +} + +function openArrayBuffer(arrayBuffer) { + var zipFile = new JSZip(arrayBuffer); + function exists(name) { + return zipFile.file(name) !== null; + } + + function read(name, encoding) { + var array = zipFile.file(name).asUint8Array(); + var buffer = new Buffer(array); + if (encoding) { + return q.when(buffer.toString(encoding)); + } else { + return q.when(buffer); + } + } + return { + exists: exists, + read: read + }; +} |
