diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/zipfile.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/zipfile.js b/lib/zipfile.js index 91c5f04..efe519c 100644 --- a/lib/zipfile.js +++ b/lib/zipfile.js @@ -8,11 +8,11 @@ exports.joinZipPath = joinZipPath; function openArrayBuffer(arrayBuffer) { var zipFile = new JSZip(arrayBuffer); function exists(name) { - return zipFile.file(name) !== null; + return zipFile.file(normaliseName(name)) !== null; } function read(name, encoding) { - var array = zipFile.file(name).asUint8Array(); + var array = zipFile.file(normaliseName(name)).asUint8Array(); var buffer = new Buffer(array); if (encoding) { return promises.when(buffer.toString(encoding)); @@ -22,7 +22,7 @@ function openArrayBuffer(arrayBuffer) { } function write(name, contents) { - zipFile.file(name, contents); + zipFile.file(normaliseName(name), contents); } function toBuffer() { @@ -37,6 +37,14 @@ function openArrayBuffer(arrayBuffer) { }; } +function normaliseName(name) { + if (name.charAt(0) === "/") { + return name.substr(1); + } else { + return name; + } +} + function joinZipPath(first, second) { if (second.charAt(0) === "/") { return second; |
