aboutsummaryrefslogtreecommitdiff
path: root/browser
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-06 22:32:27 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-06 22:32:27 +0000
commit723a7d54bd4823b2a9876fdea7b8b08cde74f669 (patch)
tree048096d0bfbdaa9ff889143aff5f8f150e0267cc /browser
parent278082b9fe502ce1ca083db66beb2c25c4a6ca5f (diff)
Use same module for node.js and browsers
Diffstat (limited to 'browser')
-rw-r--r--browser/unzip.js32
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
+ };
+}