aboutsummaryrefslogtreecommitdiff
path: root/lib/zipfile.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-05-07 10:41:44 +0100
committerMichael Williamson <mike@zwobble.org>2014-05-07 10:41:44 +0100
commit0c11e5675f9a0d4e263afed413aa656c20734f77 (patch)
tree8132dbe91dc0bfeb9ed0ea49655cd40e39790de9 /lib/zipfile.js
parent17b1f33095c13e02bdfa5ffabd378a34d3aa0751 (diff)
Use jszip on server-side as well as browser-side
Diffstat (limited to 'lib/zipfile.js')
-rw-r--r--lib/zipfile.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/zipfile.js b/lib/zipfile.js
new file mode 100644
index 0000000..2c004b7
--- /dev/null
+++ b/lib/zipfile.js
@@ -0,0 +1,27 @@
+var JSZip = require("jszip");
+
+var promises = require("./promises");
+
+exports.openArrayBuffer = openArrayBuffer;
+
+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 promises.when(buffer.toString(encoding));
+ } else {
+ return promises.when(buffer);
+ }
+ }
+ return {
+ exists: exists,
+ read: read
+ };
+}
+