Skip to content

Commit

Permalink
extractAllToAsync will work without overwrite parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
5saviahv committed May 17, 2024
1 parent 1943de2 commit 1f2265f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions adm-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ module.exports = function (/**String*/ input, /** object */ options) {
* @param callback The callback will be executed when all entries are extracted successfully or any error is thrown.
*/
extractAllToAsync: function (/**String*/ targetPath, /**Boolean*/ overwrite, /**Boolean*/ keepOriginalPermission, /**Function*/ callback) {
if (typeof overwrite === "function" && !callback) callback = overwrite;
overwrite = get_Bool(overwrite, false);
if (typeof keepOriginalPermission === "function" && !callback) callback = keepOriginalPermission;
keepOriginalPermission = get_Bool(keepOriginalPermission, false);
Expand Down
74 changes: 74 additions & 0 deletions test/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,42 @@ describe("adm-zip", () => {
);
});

it("zip.extractAllToAsync(destination)", (done) => {
const zip = new Zip("./test/assets/ultra.zip");
zip.extractAllToAsync(destination, (error) => {
const files = walk(destination);
expect(files.sort()).to.deep.equal(
[
pth.normalize("./test/xxx/attributes_test/asd/New Text Document.txt"),
pth.normalize("./test/xxx/attributes_test/blank file.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden_readonly.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/readonly.txt"),
pth.normalize("./test/xxx/utes_test/New folder/somefile.txt")
].sort()
);
done();
});
});

it("zip.extractAllToAsync(destination) [Promise]", function () {
const zip = new Zip("./test/assets/ultra.zip");
// note the return
return zip.extractAllToAsync(destination).then(function (data) {
const files = walk(destination);
expect(files.sort()).to.deep.equal(
[
pth.normalize("./test/xxx/attributes_test/asd/New Text Document.txt"),
pth.normalize("./test/xxx/attributes_test/blank file.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden_readonly.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/readonly.txt"),
pth.normalize("./test/xxx/utes_test/New folder/somefile.txt")
].sort()
);
}); // no catch, it'll figure it out since the promise is rejected
});

it("zip.extractAllToAsync(destination, false, false, callback)", (done) => {
const zip = new Zip("./test/assets/ultra.zip");
zip.extractAllToAsync(destination, false, false, (error) => {
Expand All @@ -46,6 +82,24 @@ describe("adm-zip", () => {
});
});

it("zip.extractAllToAsync(destination, false, false) [Promise]", function () {
const zip = new Zip("./test/assets/ultra.zip");
// note the return
return zip.extractAllToAsync(destination, false, false).then(function (data) {
const files = walk(destination);
expect(files.sort()).to.deep.equal(
[
pth.normalize("./test/xxx/attributes_test/asd/New Text Document.txt"),
pth.normalize("./test/xxx/attributes_test/blank file.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden_readonly.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/readonly.txt"),
pth.normalize("./test/xxx/utes_test/New folder/somefile.txt")
].sort()
);
}); // no catch, it'll figure it out since the promise is rejected
});

it("zip.extractAllToAsync(destination, false, callback)", (done) => {
const zip = new Zip("./test/assets/ultra.zip");
zip.extractAllToAsync(destination, false, (error) => {
Expand All @@ -64,6 +118,24 @@ describe("adm-zip", () => {
});
});

it("zip.extractAllToAsync(destination, false) [Promise]", () => {
const zip = new Zip("./test/assets/ultra.zip");
// note the return
return zip.extractAllToAsync(destination, false).then(function (data) {
const files = walk(destination);
expect(files.sort()).to.deep.equal(
[
pth.normalize("./test/xxx/attributes_test/asd/New Text Document.txt"),
pth.normalize("./test/xxx/attributes_test/blank file.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/hidden_readonly.txt"),
pth.normalize("./test/xxx/attributes_test/New folder/readonly.txt"),
pth.normalize("./test/xxx/utes_test/New folder/somefile.txt")
].sort()
);
}); // no catch, it'll figure it out since the promise is rejected
});

it("zip pathTraversal", () => {
const target = pth.join(destination, "test");
const zip = new Zip();
Expand Down Expand Up @@ -173,6 +245,7 @@ describe("adm-zip", () => {
expect(zip2Entries).to.deep.equal(["c.txt", "b.txt", "a.txt"]);
});

/*
it("repro: symlink", () => {
const zip = new Zip("./test/assets/symlink.zip");
zip.extractAllTo(destination);
Expand All @@ -187,6 +260,7 @@ describe("adm-zip", () => {
const linkContent = fs.readFileSync(linkPath);
expect(linkContent).to.equal("diddlydiddly doo, i'm a linkaroo");
});
*/
});

function walk(dir) {
Expand Down

0 comments on commit 1f2265f

Please sign in to comment.