Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small updates #513

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test asset seems to be faulty
  • Loading branch information
5saviahv committed Jun 24, 2024
commit b63788e0020d582a4efa47ead6aa97710c72795d
Binary file modified test/assets/ultra.zip
Binary file not shown.
129 changes: 39 additions & 90 deletions test/methods/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const rimraf = require("rimraf");
const Utils = require("../../util/utils");

describe("adm-zip.js - methods handling local files", () => {
const wrapList = (c) => pth.normalize(pth.join(destination, c));
const destination = "./test/xxx";
const testFileFolderList = [
{ name: "subfolder1/subfolder2/zipEntry1.txt", content: "zipEntry1" },
Expand All @@ -28,21 +29,21 @@ describe("adm-zip.js - methods handling local files", () => {
afterEach((done) => rimraf(destination, done));

describe(".extractAllTo() - sync", () => {
const ultrazip = [
"./attributes_test/asd/New Text Document.txt",
"./attributes_test/blank file.txt",
"./attributes_test/New folder/hidden.txt",
"./attributes_test/New folder/hidden_readonly.txt",
"./attributes_test/New folder/readonly.txt",
"./utes_test/New folder/somefile.txt"
].map(wrapList);

it("zip.extractAllTo(destination)", () => {
const zip = new Zip("./test/assets/ultra.zip");
zip.extractAllTo(destination);
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()
);
expect(files.sort()).to.deep.equal(ultrazip.sort());
});

it("zip.extractAllTo(destination) - streamed file", () => {
Expand All @@ -55,20 +56,20 @@ describe("adm-zip.js - methods handling local files", () => {
});

describe(".extractAllToAsync - sync", () => {
const ultrazip = [
"./attributes_test/asd/New Text Document.txt",
"./attributes_test/blank file.txt",
"./attributes_test/New folder/hidden.txt",
"./attributes_test/New folder/hidden_readonly.txt",
"./attributes_test/New folder/readonly.txt",
"./utes_test/New folder/somefile.txt"
].map(wrapList);

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()
);
expect(files.sort()).to.deep.equal(ultrazip.sort());
done();
});
});
Expand All @@ -78,33 +79,15 @@ describe("adm-zip.js - methods handling local files", () => {
// 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()
);
expect(files.sort()).to.deep.equal(ultrazip.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) => {
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()
);
expect(files.sort()).to.deep.equal(ultrazip.sort());
done();
});
});
Expand All @@ -114,33 +97,15 @@ describe("adm-zip.js - methods handling local files", () => {
// 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()
);
expect(files.sort()).to.deep.equal(ultrazip.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) => {
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()
);
expect(files.sort()).to.deep.equal(ultrazip.sort());
done();
});
});
Expand All @@ -150,16 +115,7 @@ describe("adm-zip.js - methods handling local files", () => {
// 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()
);
expect(files.sort()).to.deep.equal(ultrazip.sort());
}); // no catch, it'll figure it out since the promise is rejected
});
});
Expand All @@ -171,16 +127,9 @@ describe("adm-zip.js - methods handling local files", () => {
zipEntries.forEach((e) => zip.extractEntryTo(e, destination, false, true));

const files = walk(destination);
expect(files.sort()).to.deep.equal(
[
pth.normalize("./test/xxx/blank file.txt"),
pth.normalize("./test/xxx/hidden.txt"),
pth.normalize("./test/xxx/hidden_readonly.txt"),
pth.normalize("./test/xxx/New Text Document.txt"),
pth.normalize("./test/xxx/readonly.txt"),
pth.normalize("./test/xxx/somefile.txt")
].sort()
);
const ultrazip = ["blank file.txt", "hidden.txt", "hidden_readonly.txt", "New Text Document.txt", "readonly.txt", "somefile.txt"].map(wrapList);

expect(files.sort()).to.deep.equal(ultrazip.sort());
});

it("zip.extractEntryTo(entry, destination, true, true)", () => {
Expand All @@ -189,16 +138,16 @@ describe("adm-zip.js - methods handling local files", () => {
zipEntries.forEach((e) => zip.extractEntryTo(e, destination, true, true));

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()
);
const ultrazip = [
"./attributes_test/asd/New Text Document.txt",
"./attributes_test/blank file.txt",
"./attributes_test/New folder/hidden.txt",
"./attributes_test/New folder/hidden_readonly.txt",
"./attributes_test/New folder/readonly.txt",
"./utes_test/New folder/somefile.txt"
].map(wrapList);

expect(files.sort()).to.deep.equal(ultrazip.sort());
});
});

Expand Down
22 changes: 11 additions & 11 deletions util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Utils(opts) {

module.exports = Utils;

// INSTANCED functions
// INSTANTIABLE functions

Utils.prototype.makeDir = function (/*String*/ folder) {
const self = this;
Expand Down Expand Up @@ -75,10 +75,10 @@ Utils.prototype.writeFileTo = function (/*String*/ path, /*Buffer*/ content, /*B

var fd;
try {
fd = self.fs.openSync(path, "w", 438); // 0666
fd = self.fs.openSync(path, "w", 0o666); // 0666
} catch (e) {
self.fs.chmodSync(path, 438);
fd = self.fs.openSync(path, "w", 438);
self.fs.chmodSync(path, 0o666);
fd = self.fs.openSync(path, "w", 0o666);
}
if (fd) {
try {
Expand All @@ -87,7 +87,7 @@ Utils.prototype.writeFileTo = function (/*String*/ path, /*Buffer*/ content, /*B
self.fs.closeSync(fd);
}
}
self.fs.chmodSync(path, attr || 438);
self.fs.chmodSync(path, attr || 0o666);
return true;
};

Expand All @@ -111,13 +111,13 @@ Utils.prototype.writeFileToAsync = function (/*String*/ path, /*Buffer*/ content
self.fs.exists(folder, function (exists) {
if (!exists) self.makeDir(folder);

self.fs.open(path, "w", 438, function (err, fd) {
self.fs.open(path, "w", 0o666, function (err, fd) {
if (err) {
self.fs.chmod(path, 438, function () {
self.fs.open(path, "w", 438, function (err, fd) {
self.fs.chmod(path, 0o666, function () {
self.fs.open(path, "w", 0o666, function (err, fd) {
self.fs.write(fd, content, 0, content.length, 0, function () {
self.fs.close(fd, function () {
self.fs.chmod(path, attr || 438, function () {
self.fs.chmod(path, attr || 0o666, function () {
callback(true);
});
});
Expand All @@ -127,13 +127,13 @@ Utils.prototype.writeFileToAsync = function (/*String*/ path, /*Buffer*/ content
} else if (fd) {
self.fs.write(fd, content, 0, content.length, 0, function () {
self.fs.close(fd, function () {
self.fs.chmod(path, attr || 438, function () {
self.fs.chmod(path, attr || 0o666, function () {
callback(true);
});
});
});
} else {
self.fs.chmod(path, attr || 438, function () {
self.fs.chmod(path, attr || 0o666, function () {
callback(true);
});
}
Expand Down