diff --git a/adm-zip.js b/adm-zip.js index 2d8af07..92845be 100644 --- a/adm-zip.js +++ b/adm-zip.js @@ -369,9 +369,9 @@ module.exports = function (/*String*/input) { if (!content) { throw Utils.Errors.CANT_EXTRACT_FILE; } - var childName = sanitize(targetPath, child.entryName); + var childName = sanitize(targetPath, maintainEntryPath ? child.entryName : pth.basename(child.entryName)); - Utils.writeFileTo(pth.resolve(targetPath, maintainEntryPath ? childName : childName.substr(entryName.length)), content, overwrite); + Utils.writeFileTo(childName, content, overwrite); }); return true; } diff --git a/test/mocha.js b/test/mocha.js index 70bf404..7b55fde 100644 --- a/test/mocha.js +++ b/test/mocha.js @@ -31,7 +31,8 @@ describe('adm-zip', () => { "./test/xxx/utes_test/New folder/somefile.txt" ].sort()); }) - it('zip.extractEntryTo()', () => { + + it('zip.extractEntryTo(entry, destination, false, true)', () => { const destination = './test/xxx' const zip = new Zip('./test/assets/ultra.zip'); var zipEntries = zip.getEntries(); @@ -43,12 +44,25 @@ describe('adm-zip', () => { "./test/xxx/hidden.txt", "./test/xxx/hidden_readonly.txt", "./test/xxx/New Text Document.txt", - "./test/xxx/ojects/adm-zip/test/xxx/attributes_test/New folder/hidden.txt", - "./test/xxx/ojects/adm-zip/test/xxx/attributes_test/New folder/hidden_readonly.txt", - "./test/xxx/ojects/adm-zip/test/xxx/attributes_test/New folder/readonly.txt", "./test/xxx/readonly.txt", - "./test/xxx/somefile.txt", - "./test/xxx/stormProjects/adm-zip/test/xxx/attributes_test/asd/New Text Document.txt" + "./test/xxx/somefile.txt" + ].sort()); + }) + + it('zip.extractEntryTo(entry, destination, true, true)', () => { + const destination = './test/xxx' + const zip = new Zip('./test/assets/ultra.zip'); + var zipEntries = zip.getEntries(); + zipEntries.forEach(e => zip.extractEntryTo(e, destination, true, true)); + + const files = walk(destination) + expect(files.sort()).to.deep.equal([ + "./test/xxx/attributes_test/asd/New Text Document.txt", + "./test/xxx/attributes_test/blank file.txt", + "./test/xxx/attributes_test/New folder/hidden.txt", + "./test/xxx/attributes_test/New folder/hidden_readonly.txt", + "./test/xxx/attributes_test/New folder/readonly.txt", + "./test/xxx/utes_test/New folder/somefile.txt" ].sort()); }) })