|
1 | 1 | "use strict";
|
2 | 2 |
|
3 |
| -(function () { |
4 |
| - var fs = require("fs"); |
5 |
| - var path = require("path"); |
6 |
| - var Zip = require("../../adm-zip"); |
| 3 | +const assert = require("assert"); |
| 4 | +const fs = require("fs"); |
| 5 | +const pth = require("path"); |
| 6 | +const Zip = require("../../adm-zip"); |
| 7 | +const rimraf = require("rimraf"); |
7 | 8 |
|
8 |
| - // init the final zip file |
9 |
| - var writeZip = new Zip(); |
| 9 | +describe("ADM-ZIP - Issues", () => { |
| 10 | + const destination = pth.resolve("./test/xxx"); |
| 11 | + const unzipped = pth.join(destination, "unzipped"); |
10 | 12 |
|
11 |
| - // file in root folder |
12 |
| - writeZip.addFile("root_file.txt", "root"); |
| 13 | + // clean up folder content |
| 14 | + afterEach((done) => rimraf(destination, done)); |
13 | 15 |
|
14 |
| - // add folder |
15 |
| - writeZip.addFile("sub/", Buffer.alloc(0)); |
| 16 | + it("Issue 130 - Created zip's under Windows are corrupt", () => { |
| 17 | + // init the final zip file |
| 18 | + const writeZip = new Zip(); |
16 | 19 |
|
17 |
| - // file in sub folder |
18 |
| - writeZip.addFile("sub/sub_file.txt", "sub"); |
| 20 | + // file in root folder |
| 21 | + writeZip.addFile("root_file.txt", "root"); |
19 | 22 |
|
20 |
| - // files from local folder |
21 |
| - writeZip.addLocalFolder("nested", "nested"); |
| 23 | + // add folder |
| 24 | + writeZip.addFile("sub/", Buffer.alloc(0)); |
22 | 25 |
|
23 |
| - // write to disk |
24 |
| - writeZip.writeZip("test.zip"); |
| 26 | + // file in sub folder |
| 27 | + writeZip.addFile("sub/sub_file.txt", "sub"); |
25 | 28 |
|
26 |
| - // read zip from disk |
27 |
| - var readZip = new Zip("test.zip"); |
| 29 | + // files from local folder |
| 30 | + writeZip.addLocalFolder(pth.resolve("./test/issue_130", "nested"), "nested"); |
28 | 31 |
|
29 |
| - // unpack everything |
30 |
| - readZip.extractAllTo("unzipped", true); |
| 32 | + // write to disk |
| 33 | + writeZip.writeZip(pth.join(destination, "test.zip")); |
31 | 34 |
|
32 |
| - // assert the files |
33 |
| - var assert = function (content, expectedContent, errMsg) { |
34 |
| - if (content !== expectedContent) { |
35 |
| - throw new Error(errMsg); |
36 |
| - } |
37 |
| - }; |
| 35 | + // read zip from disk |
| 36 | + const readZip = new Zip(pth.join(destination, "test.zip")); |
38 | 37 |
|
39 |
| - var fileRoot = fs.readFileSync(path.join("unzipped", "root_file.txt"), "utf8"); |
40 |
| - assert(fileRoot, "root", "root file not correct"); |
| 38 | + // unpack everything |
| 39 | + readZip.extractAllTo(unzipped, true); |
41 | 40 |
|
42 |
| - var fileSub = fs.readFileSync(path.join("unzipped", "sub", "sub_file.txt"), "utf8"); |
43 |
| - assert(fileSub, "sub", "sub file not correct"); |
| 41 | + // assert the files |
| 42 | + const fileRoot = fs.readFileSync(pth.join(unzipped, "root_file.txt"), "utf8"); |
| 43 | + assert(fileRoot === "root", "root file not correct"); |
44 | 44 |
|
45 |
| - var fileNested = fs.readFileSync(path.join("unzipped", "nested", "nested_file.txt"), "utf8"); |
46 |
| - assert(fileNested, "nested", "nested file not correct"); |
| 45 | + const fileSub = fs.readFileSync(pth.join(unzipped, "sub/sub_file.txt"), "utf8"); |
| 46 | + assert(fileSub === "sub", "sub file not correct"); |
47 | 47 |
|
48 |
| - var fileDeeper = fs.readFileSync(path.join("unzipped", "nested", "deeper", "deeper_file.txt"), "utf8"); |
49 |
| - assert(fileDeeper, "deeper", "deeper file not correct"); |
50 |
| -})(); |
| 48 | + const fileNested = fs.readFileSync(pth.join(unzipped, "nested/nested_file.txt"), "utf8"); |
| 49 | + assert(fileNested === "nested", "nested file not correct"); |
| 50 | + |
| 51 | + const fileDeeper = fs.readFileSync(pth.join(unzipped, "nested/deeper/deeper_file.txt"), "utf8"); |
| 52 | + assert(fileDeeper === "deeper", "deeper file not correct"); |
| 53 | + }); |
| 54 | +}); |
0 commit comments