diff --git a/adm-zip.js b/adm-zip.js index f38797d..33316f6 100644 --- a/adm-zip.js +++ b/adm-zip.js @@ -429,7 +429,7 @@ module.exports = function (/**String*/ input, /** object */ options) { // prepare new entry if (!update) { entry = new ZipEntry(); - entry.entryName = entryName; + entry.entryName = Utils.canonical(entryName); } entry.comment = comment || ""; @@ -464,6 +464,8 @@ module.exports = function (/**String*/ input, /** object */ options) { entry.setData(content); if (!update) _zip.setEntry(entry); + + return entry; }, /** diff --git a/package.json b/package.json index 8263801..54f8d2d 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "url": "https://github.com/cthackers/adm-zip.git" }, "engines": { - "node": ">=6.0" + "node": ">=12.0" }, "devDependencies": { "chai": "^4.3.4", diff --git a/test/mocha.js b/test/mocha.js index 2689766..cbc481f 100644 --- a/test/mocha.js +++ b/test/mocha.js @@ -218,6 +218,16 @@ describe("adm-zip", () => { fs.unlinkSync("./text.txt"); }); + it("passes issue-438-AddFile with windows path sepator", () => { + const zip = new Zip(); + zip.addFile("foo\\bar.txt", "test", "test"); + zip.extractAllTo(destination); + + const files = walk(destination); + + expect(files.sort()).to.deep.equal([pth.normalize("./test/xxx/foo/bar.txt")].sort()); + }); + it("testing noSort option", () => { const content = "test"; const comment = "comment"; diff --git a/zipEntry.js b/zipEntry.js index 9deed1f..486e092 100644 --- a/zipEntry.js +++ b/zipEntry.js @@ -12,7 +12,8 @@ module.exports = function (/*Buffer*/ input) { _extra = Buffer.alloc(0); function getCompressedDataFromZip() { - if (!input || !Buffer.isBuffer(input)) { + //if (!input || !Buffer.isBuffer(input)) { + if (!input || !(input instanceof Uint8Array)) { return Buffer.alloc(0); } _centralHeader.loadLocalHeaderFromBinary(input);