blob: 50cbf28c9d1cafd7abec06f4be1460bb58230694 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
var JSZip = require("jszip");
var promises = require("../lib/promises");
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 promises.when(buffer.toString(encoding));
} else {
return promises.when(buffer);
}
}
return {
exists: exists,
read: read
};
}
|