@zip.js/zip.js 2.6.9 → 2.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/zip-fs-full.js +9 -3
  2. package/dist/zip-fs-full.min.js +1 -1
  3. package/dist/zip-fs.js +9 -3
  4. package/dist/zip-fs.min.js +1 -1
  5. package/dist/zip-full.js +9 -3
  6. package/dist/zip-full.min.js +1 -1
  7. package/dist/zip-no-worker-deflate.min.js +1 -1
  8. package/dist/zip-no-worker.min.js +1 -1
  9. package/dist/zip.js +9 -3
  10. package/dist/zip.min.js +1 -1
  11. package/index.d.ts +71 -3
  12. package/lib/core/zip-writer.js +9 -3
  13. package/package.json +16 -7
  14. package/tests/all/loader.html +2 -4
  15. package/tests/all/test-abort-signal-read.js +0 -1
  16. package/tests/all/test-abort-signal-write.js +0 -1
  17. package/tests/all/test-array.js +3 -1
  18. package/tests/all/test-base64.js +3 -1
  19. package/tests/all/test-blob.js +5 -1
  20. package/tests/all/test-codecs-interoperability.js +3 -1
  21. package/tests/all/test-crc.js +7 -12
  22. package/tests/all/test-crypto.js +3 -1
  23. package/tests/all/test-custom-io.js +3 -1
  24. package/tests/all/test-data-descriptor-signature.js +7 -1
  25. package/tests/all/test-data-descriptor.js +7 -1
  26. package/tests/all/test-duplicated-filename.js +24 -0
  27. package/tests/all/test-empty.js +3 -1
  28. package/tests/all/test-extended-timestamp.js +3 -1
  29. package/tests/all/test-extra-field.js +3 -2
  30. package/tests/all/test-fflate-no-worker.js +3 -1
  31. package/tests/all/test-fflate.js +3 -1
  32. package/tests/all/test-fs-base64.js +3 -1
  33. package/tests/all/test-fs-export-options.js +3 -1
  34. package/tests/all/test-fs-http-import.js +3 -1
  35. package/tests/all/test-fs-http-reader.js +3 -1
  36. package/tests/all/test-fs-replace.js +3 -1
  37. package/tests/all/test-fs-streams.js +3 -1
  38. package/tests/all/test-fs-text.js +3 -1
  39. package/tests/all/test-fs-unzip-store.js +3 -1
  40. package/tests/all/test-fs.js +3 -1
  41. package/tests/all/test-http-crypto.js +3 -2
  42. package/tests/all/test-http-range.js +3 -2
  43. package/tests/all/test-http-zip64.js +3 -2
  44. package/tests/all/test-invalid-crc.js +3 -1
  45. package/tests/all/test-no-worker.js +3 -1
  46. package/tests/all/test-pako-no-worker.js +3 -1
  47. package/tests/all/test-pako.js +3 -1
  48. package/tests/all/test-parallel-reads.js +3 -1
  49. package/tests/all/test-parallel-writes-auto-buffered.js +3 -1
  50. package/tests/all/test-parallel-writes-ordered.js +4 -2
  51. package/tests/all/test-parallel-writes.js +3 -1
  52. package/tests/all/test-readable-stream.js +8 -12
  53. package/tests/all/test-readable-zip-stream.js +3 -2
  54. package/tests/all/test-safe-closing.js +3 -1
  55. package/tests/all/test-store.js +9 -1
  56. package/tests/all/test-sw.js +0 -1
  57. package/tests/all/test-worker-timeout.js +7 -12
  58. package/tests/all/test-wrapped.js +4 -2
  59. package/tests/all/test-writable-stream.js +23 -25
  60. package/tests/all/test-zip64-auto.js +3 -1
  61. package/tests/all/test-zip64-crypto.js +3 -1
  62. package/tests/all/test-zip64.js +3 -1
  63. package/tests/all/test-zipcrypto.js +3 -1
  64. package/tests/node-runner.js +17 -9
  65. package/tests/tests-data.js +1 -0
  66. package/build.sh +0 -3
  67. package/tests/run-tests.sh +0 -3
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@zip.js/zip.js",
3
- "description": "A JavaScript library to zip and unzip files in the browser and Deno",
3
+ "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.6.9",
6
+ "version": "2.6.12",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",
@@ -20,16 +20,24 @@
20
20
  "compression-streams",
21
21
  "web-crypto",
22
22
  "web-workers",
23
- "deno"
23
+ "deno",
24
+ "node.js",
25
+ "multi-core"
24
26
  ],
25
27
  "engines": {
26
28
  "deno": ">=1.0.0",
27
- "node": ">=18.0.0"
29
+ "node": ">=16.5.0"
28
30
  },
29
31
  "scripts": {
30
- "build": "./build.sh",
31
- "dev": "npx rollup -c rollup.config.dev.js",
32
- "test": "cd ./tests && \"./run-tests.sh\""
32
+ "build": "npx rollup -c",
33
+ "build-dev": "npx rollup -c rollup.config.dev.js",
34
+ "build-fflate": "npm i --no-save fflate && npx rollup -c rollup-fflate.config.js",
35
+ "build-fflate-dev": "npm i --no-save fflate && npx rollup -c rollup-fflate.config.dev.js",
36
+ "build-doc-api": "npx typedoc",
37
+ "test-deno": "cd ./tests && deno test --allow-read ./deno-runner.js",
38
+ "test-node": "cd ./tests && node ./node-runner.js",
39
+ "test-firefox": "firefox http://localhost:8081/tests/ & npx http-server -p=8081",
40
+ "test-chrome": "google-chrome http://localhost:8081/tests/ & npx http-server -p=8081"
33
41
  },
34
42
  "main": "index.js",
35
43
  "types": "index.d.ts",
@@ -44,6 +52,7 @@
44
52
  "devDependencies": {
45
53
  "@rollup/plugin-node-resolve": "^13.3.0",
46
54
  "@rollup/plugin-replace": "^4.0.0",
55
+ "http-server": "^14.1.1",
47
56
  "rollup": "^2.77.2",
48
57
  "rollup-plugin-terser": "^7.0.2",
49
58
  "typedoc": "^0.23.10"
@@ -18,10 +18,8 @@
18
18
  import(testData.script).then(async Module => {
19
19
  try {
20
20
  const result = await Module.test();
21
- if (result) {
22
- document.body.innerHTML = "ok";
23
- parent.postMessage(JSON.stringify({ script }), "*");
24
- }
21
+ document.body.innerHTML = "ok";
22
+ parent.postMessage(JSON.stringify({ script }), "*");
25
23
  } catch (error) {
26
24
  parent.postMessage(JSON.stringify({ script, error: { message: error.message, stack: error.stack } }), "*");
27
25
  throw error;
@@ -27,7 +27,6 @@ async function test() {
27
27
  } catch (error) {
28
28
  if (signal.reason == error || signal.reason.code == error.code) {
29
29
  zip.terminateWorkers();
30
- return true;
31
30
  } else {
32
31
  throw error;
33
32
  }
@@ -23,7 +23,6 @@ async function test() {
23
23
  } catch (error) {
24
24
  if (signal.reason == error || signal.reason.code == error.code) {
25
25
  zip.terminateWorkers();
26
- return true;
27
26
  } else {
28
27
  throw error;
29
28
  }
@@ -17,7 +17,9 @@ async function test() {
17
17
  const data = await entries[0].getData(new zip.Uint8ArrayWriter());
18
18
  await zipReader.close();
19
19
  zip.terminateWorkers();
20
- return getArrayText(data) == TEXT_CONTENT && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
20
+ if (getArrayText(data) != TEXT_CONTENT) {
21
+ throw new Error();
22
+ }
21
23
  }
22
24
 
23
25
  function getArrayText(array) {
@@ -19,5 +19,7 @@ async function test() {
19
19
  const data = await entries[0].getData(new zip.Data64URIWriter("text/plain"));
20
20
  await zipReader.close();
21
21
  zip.terminateWorkers();
22
- return data == DATA_URI && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
22
+ if (data != DATA_URI) {
23
+ throw new Error();
24
+ }
23
25
  }
@@ -21,7 +21,11 @@ async function test() {
21
21
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
22
22
  await zipReader.close();
23
23
  zip.terminateWorkers();
24
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
24
+ if (TEXT_CONTENT != (await data.text())) {
25
+ throw new Error();
26
+ }
25
27
  }
28
+ } else {
29
+ throw new Error();
26
30
  }
27
31
  }
@@ -22,7 +22,9 @@ async function test() {
22
22
  const entries = await zipReader.getEntries();
23
23
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
24
24
  await zipReader.close();
25
- return (await getBlob(size).text()) == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == size;
25
+ if (await getBlob(size).text() != await data.text()) {
26
+ throw new Error();
27
+ }
26
28
  }
27
29
 
28
30
  function getBlob(size) {
@@ -12,16 +12,11 @@ async function test() {
12
12
  zip.configure({ chunkSize: 128, useWebWorkers: true });
13
13
  const blobWriter = new zip.BlobWriter("application/zip");
14
14
  const zipWriter = new zip.ZipWriter(blobWriter);
15
- const entry = await zipWriter.add(FILENAME, new zip.BlobReader(BLOB));
16
- if (entry.compressionMethod == 0x08) {
17
- await zipWriter.close();
18
- const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
19
- const entries = await zipReader.getEntries();
20
- if (entries[0].compressionMethod == 0x08) {
21
- const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)), { checkSignature: true });
22
- await zipReader.close();
23
- zip.terminateWorkers();
24
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
25
- }
26
- }
15
+ await zipWriter.add(FILENAME, new zip.BlobReader(BLOB));
16
+ await zipWriter.close();
17
+ const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
18
+ const entries = await zipReader.getEntries();
19
+ await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)), { checkSignature: true });
20
+ await zipReader.close();
21
+ zip.terminateWorkers();
27
22
  }
@@ -41,5 +41,7 @@ async function test() {
41
41
  }
42
42
  await zipReader.close();
43
43
  zip.terminateWorkers();
44
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
44
+ if (TEXT_CONTENT != await data.text()) {
45
+ throw new Error();
46
+ }
45
47
  }
@@ -56,5 +56,7 @@ async function test() {
56
56
  const data = await entries[0].getData(new BinaryStringWriter());
57
57
  await zipReader.close();
58
58
  zip.terminateWorkers();
59
- return TEXT_CONTENT == data;
59
+ if (TEXT_CONTENT != data) {
60
+ throw new Error();
61
+ }
60
62
  }
@@ -21,7 +21,13 @@ async function test() {
21
21
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
22
22
  await zipReader.close();
23
23
  zip.terminateWorkers();
24
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
24
+ if (TEXT_CONTENT != await data.text() || entries[0].filename != FILENAME || entries[0].uncompressedSize != TEXT_CONTENT.length) {
25
+ throw new Error();
26
+ }
27
+ } else {
28
+ throw new Error();
25
29
  }
30
+ } else {
31
+ throw new Error();
26
32
  }
27
33
  }
@@ -21,7 +21,13 @@ async function test() {
21
21
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
22
22
  await zipReader.close();
23
23
  zip.terminateWorkers();
24
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
24
+ if (TEXT_CONTENT != await data.text() || entries[0].filename != FILENAME || entries[0].uncompressedSize != TEXT_CONTENT.length) {
25
+ throw new Error();
26
+ }
27
+ } else {
28
+ throw new Error();
25
29
  }
30
+ } else {
31
+ throw new Error();
26
32
  }
27
33
  }
@@ -0,0 +1,24 @@
1
+ import * as zip from "../../index.js";
2
+
3
+ const FILENAME = "lorem.txt";
4
+
5
+ export { test };
6
+
7
+ async function test() {
8
+ zip.configure({ chunkSize: 128, useWebWorkers: true });
9
+ const zipWriter = new zip.ZipWriter(new zip.BlobWriter("application/zip"));
10
+ try {
11
+ await Promise.all([
12
+ zipWriter.add(FILENAME, new zip.TextReader("")),
13
+ zipWriter.add(FILENAME, new zip.TextReader(""))
14
+ ]);
15
+ } catch (error) {
16
+ if (error.message == zip.ERR_DUPLICATED_NAME) {
17
+ return;
18
+ }
19
+ } finally {
20
+ await zipWriter.close();
21
+ zip.terminateWorkers();
22
+ }
23
+ throw new Error();
24
+ }
@@ -10,5 +10,7 @@ async function test() {
10
10
  const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
11
11
  const entries = await zipReader.getEntries();
12
12
  await zipReader.close();
13
- return entries.length == 0;
13
+ if (entries.length != 0) {
14
+ throw new Error();
15
+ }
14
16
  }
@@ -12,7 +12,9 @@ async function test() {
12
12
  zip.configure({ chunkSize: 128, useWebWorkers: true });
13
13
  const lastModDate = new Date(2021, 0, 1, 0, 0, 1);
14
14
  const testDisabled = await testLastModDate(false, lastModDate);
15
- return !testDisabled && (await testLastModDate(true, lastModDate));
15
+ if (testDisabled || !await testLastModDate(true, lastModDate)) {
16
+ throw new Error();
17
+ }
16
18
  }
17
19
 
18
20
  async function testLastModDate(extendedTimestamp, lastModDate) {
@@ -18,8 +18,9 @@ async function test() {
18
18
  await zipWriter.close();
19
19
  const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
20
20
  const entries = await zipReader.getEntries();
21
- const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
22
21
  await zipReader.close();
23
22
  zip.terminateWorkers();
24
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length && entries[0].extraField.get(42).data.length == 42;
23
+ if (entries[0].extraField.get(42).data.length != 42) {
24
+ throw new Error();
25
+ }
25
26
  }
@@ -25,5 +25,7 @@ async function test() {
25
25
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
26
26
  await zipReader.close();
27
27
  zip.terminateWorkers();
28
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
28
+ if (TEXT_CONTENT != await data.text()) {
29
+ throw new Error();
30
+ }
29
31
  }
@@ -23,5 +23,7 @@ async function test() {
23
23
  const entries = await zipReader.getEntries();
24
24
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
25
25
  await zipReader.close();
26
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
26
+ if (TEXT_CONTENT != await data.text()) {
27
+ throw new Error();
28
+ }
27
29
  }
@@ -18,5 +18,7 @@ async function test() {
18
18
  const firstEntry = zipFs.children[0];
19
19
  const dataURI = await firstEntry.getData64URI("text/plain");
20
20
  zip.terminateWorkers();
21
- return dataURI == DATA_URI && firstEntry.name == FILENAME && firstEntry.uncompressedSize == TEXT_CONTENT.length;
21
+ if (dataURI != DATA_URI) {
22
+ throw new Error();
23
+ }
22
24
  }
@@ -28,5 +28,7 @@ async function test() {
28
28
  }
29
29
  }
30
30
  zip.terminateWorkers();
31
- return text == TEXT_CONTENT && firstEntry.uncompressedSize == TEXT_CONTENT.length;
31
+ if (text != TEXT_CONTENT || firstEntry.uncompressedSize != TEXT_CONTENT.length) {
32
+ throw new Error();
33
+ }
32
34
  }
@@ -19,5 +19,7 @@ async function test() {
19
19
  const firstEntry = directory.children[0];
20
20
  const text = await firstEntry.getText();
21
21
  zip.terminateWorkers();
22
- return text == TEXT_CONTENT && firstEntry.uncompressedSize == TEXT_CONTENT.length;
22
+ if (text != TEXT_CONTENT) {
23
+ throw new Error();
24
+ }
23
25
  }
@@ -18,5 +18,7 @@ async function test() {
18
18
  const firstEntry = zipFs.children[0];
19
19
  const text = await firstEntry.getText("text/plain");
20
20
  zip.terminateWorkers();
21
- return text == TEXT_CONTENT && firstEntry.name == FILENAME && firstEntry.uncompressedSize == TEXT_CONTENT.length;
21
+ if (text != TEXT_CONTENT || firstEntry.name != FILENAME || firstEntry.uncompressedSize != TEXT_CONTENT.length) {
22
+ throw new Error();
23
+ }
22
24
  }
@@ -21,5 +21,7 @@ async function test() {
21
21
  firstEntry = directory.children[0];
22
22
  const text = await firstEntry.getText();
23
23
  zip.terminateWorkers();
24
- return text == NEW_TEXT_CONTENT && firstEntry.uncompressedSize == NEW_TEXT_CONTENT.length;
24
+ if (text != NEW_TEXT_CONTENT) {
25
+ throw new Error();
26
+ }
25
27
  }
@@ -18,5 +18,7 @@ async function test() {
18
18
  transformStream = new TransformStream();
19
19
  const [text] = await Promise.all([new Response(transformStream.readable).text(), firstEntry.getWritable(transformStream.writable)]);
20
20
  zip.terminateWorkers();
21
- return text == TEXT_CONTENT && firstEntry.name == FILENAME && firstEntry.uncompressedSize == TEXT_CONTENT.length;
21
+ if (text != TEXT_CONTENT) {
22
+ throw new Error();
23
+ }
22
24
  }
@@ -15,5 +15,7 @@ async function test() {
15
15
  const firstEntry = zipFs.children[0];
16
16
  const text = await firstEntry.getText();
17
17
  zip.terminateWorkers();
18
- return text == TEXT_CONTENT && firstEntry.name == FILENAME && firstEntry.uncompressedSize == TEXT_CONTENT.length;
18
+ if (text != TEXT_CONTENT) {
19
+ throw new Error();
20
+ }
19
21
  }
@@ -19,5 +19,7 @@ async function test() {
19
19
  const firstEntry = directory.children[0];
20
20
  const text = await firstEntry.getText();
21
21
  zip.terminateWorkers();
22
- return text == TEXT_CONTENT && firstEntry.uncompressedSize == TEXT_CONTENT.length;
22
+ if (text != TEXT_CONTENT) {
23
+ throw new Error();
24
+ }
23
25
  }
@@ -18,5 +18,7 @@ async function test() {
18
18
  const firstEntry = zipFs.children[0];
19
19
  const unzippedBlob = await firstEntry.getBlob(zip.getMimeType(firstEntry.name));
20
20
  zip.terminateWorkers();
21
- return TEXT_CONTENT == (await unzippedBlob.text()) && firstEntry.name == FILENAME && firstEntry.uncompressedSize == TEXT_CONTENT.length;
21
+ if (TEXT_CONTENT != await unzippedBlob.text() || firstEntry.name != FILENAME || firstEntry.uncompressedSize != TEXT_CONTENT.length) {
22
+ throw new Error();
23
+ }
22
24
  }
@@ -3,7 +3,6 @@
3
3
  import * as zip from "../../index.js";
4
4
 
5
5
  const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
6
- const FILENAME = "lorem.txt";
7
6
  const url = new URL("./../data/lorem-encrypted.zip", import.meta.url).href;
8
7
 
9
8
  export { test };
@@ -26,5 +25,7 @@ async function test() {
26
25
  }
27
26
  await zipReader.close();
28
27
  zip.terminateWorkers();
29
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
28
+ if (TEXT_CONTENT != await data.text()) {
29
+ throw new Error();
30
+ }
30
31
  }
@@ -1,7 +1,6 @@
1
1
  import * as zip from "../../index.js";
2
2
 
3
3
  const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
4
- const FILENAME = "lorem.txt";
5
4
 
6
5
  export { test };
7
6
 
@@ -13,5 +12,7 @@ async function test() {
13
12
  const data = await entries[0].getData(dataBlobWriter);
14
13
  await zipReader.close();
15
14
  zip.terminateWorkers();
16
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
15
+ if (TEXT_CONTENT != await data.text()) {
16
+ throw new Error();
17
+ }
17
18
  }
@@ -3,7 +3,6 @@
3
3
  import * as zip from "../../index.js";
4
4
 
5
5
  const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
6
- const FILENAME = "lorem.txt";
7
6
  const url = new URL("./../data/lorem-zip64.zip", import.meta.url).href;
8
7
 
9
8
  export { test };
@@ -16,5 +15,7 @@ async function test() {
16
15
  const data = await entries[0].getData(dataBlobWriter);
17
16
  await zipReader.close();
18
17
  zip.terminateWorkers();
19
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
18
+ if (TEXT_CONTENT != await data.text()) {
19
+ throw new Error();
20
+ }
20
21
  }
@@ -24,5 +24,7 @@ async function test() {
24
24
  }
25
25
  }
26
26
  zip.terminateWorkers();
27
- return TEXT_CONTENT == (await data.text()) && entries[0].uncompressedSize == TEXT_CONTENT.length;
27
+ if (TEXT_CONTENT != await data.text()) {
28
+ throw new Error();
29
+ }
28
30
  }
@@ -19,5 +19,7 @@ async function test() {
19
19
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
20
20
  await zipReader.close();
21
21
  zip.terminateWorkers();
22
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
22
+ if (TEXT_CONTENT != await data.text()) {
23
+ throw new Error();
24
+ }
23
25
  }
@@ -25,5 +25,7 @@ async function test() {
25
25
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
26
26
  await zipReader.close();
27
27
  zip.terminateWorkers();
28
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
28
+ if (TEXT_CONTENT != await data.text()) {
29
+ throw new Error();
30
+ }
29
31
  }
@@ -23,5 +23,7 @@ async function test() {
23
23
  const entries = await zipReader.getEntries();
24
24
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
25
25
  await zipReader.close();
26
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
26
+ if (TEXT_CONTENT != await data.text()) {
27
+ throw new Error();
28
+ }
27
29
  }
@@ -25,7 +25,9 @@ async function test() {
25
25
  return compareResult(blob, indexEntry);
26
26
  }));
27
27
  zip.terminateWorkers();
28
- return !results.includes(false);
28
+ if (results.includes(false)) {
29
+ throw new Error();
30
+ }
29
31
  }
30
32
 
31
33
  async function compareResult(result, index) {
@@ -43,7 +43,9 @@ async function test() {
43
43
  return compareResult(blob, ENTRIES_DATA_PASS2.find(otherEntry => otherEntry.name == entry.filename).blob);
44
44
  }));
45
45
  zip.terminateWorkers();
46
- return !results.includes(false) && !results2.includes(false);
46
+ if (results.includes(false) || results2.includes(false)) {
47
+ throw new Error();
48
+ }
47
49
  }
48
50
 
49
51
  async function compareResult(result, value) {
@@ -19,8 +19,10 @@ async function test() {
19
19
  const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
20
20
  const entries = await zipReader.getEntries();
21
21
  zip.terminateWorkers();
22
- return JSON.stringify(ENTRIES_DATA.map(entry => entry.name)) ==
23
- JSON.stringify(entries.sort((entry1, entry2) => entry1.offset - entry2.offset).map(entry => entry.filename));
22
+ if (JSON.stringify(ENTRIES_DATA.map(entry => entry.name)) !=
23
+ JSON.stringify(entries.sort((entry1, entry2) => entry1.offset - entry2.offset).map(entry => entry.filename))) {
24
+ throw new Error();
25
+ }
24
26
  }
25
27
 
26
28
  function getBlob(size) {
@@ -23,7 +23,9 @@ async function test() {
23
23
  return compareResult(blob, indexEntry);
24
24
  }));
25
25
  zip.terminateWorkers();
26
- return !results.includes(false);
26
+ if (results.includes(false)) {
27
+ throw new Error();
28
+ }
27
29
  }
28
30
 
29
31
  async function compareResult(result, index) {
@@ -13,16 +13,12 @@ async function test() {
13
13
  const zipWriter = new zip.ZipWriter(blobWriter);
14
14
  const readable = (await fetch(new URL("../data/lorem.txt", import.meta.url))).body;
15
15
  const reader = { readable };
16
- const entry = await zipWriter.add(FILENAME, reader);
17
- if (entry.compressionMethod == 0x08) {
18
- await zipWriter.close();
19
- const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
20
- const entries = await zipReader.getEntries();
21
- if (entries[0].compressionMethod == 0x08) {
22
- const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
23
- await zipReader.close();
24
- zip.terminateWorkers();
25
- return TEXT_CONTENT == (await data.text()) && entries[0].uncompressedSize == TEXT_CONTENT.length;
26
- }
27
- }
16
+ await zipWriter.add(FILENAME, reader);
17
+ await zipWriter.close();
18
+ const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
19
+ const entries = await zipReader.getEntries();
20
+ const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
21
+ await zipReader.close();
22
+ zip.terminateWorkers();
23
+ return TEXT_CONTENT == (await data.text()) && entries[0].uncompressedSize == TEXT_CONTENT.length;
28
24
  }
@@ -3,7 +3,6 @@
3
3
  import * as zip from "../../index.js";
4
4
 
5
5
  const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
6
- const FILENAME = "lorem.txt";
7
6
 
8
7
  export { test };
9
8
 
@@ -15,5 +14,7 @@ async function test() {
15
14
  const data = await entries[0].getData(new zip.BlobWriter());
16
15
  await zipReader.close();
17
16
  zip.terminateWorkers();
18
- return TEXT_CONTENT == (await data.text()) && entries[0].uncompressedSize == TEXT_CONTENT.length && entries[0].filename == FILENAME;
17
+ if (TEXT_CONTENT != await data.text()) {
18
+ throw new Error();
19
+ }
19
20
  }
@@ -23,7 +23,9 @@ async function test() {
23
23
  return compareResult(blob, ENTRIES_DATA[indexEntry].blob);
24
24
  }));
25
25
  zip.terminateWorkers();
26
- return !results.includes(false);
26
+ if (results.includes(false)) {
27
+ throw new Error();
28
+ }
27
29
  }
28
30
 
29
31
  async function compareResult(result, value) {
@@ -23,8 +23,16 @@ async function test() {
23
23
  const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
24
24
  await zipReader.close();
25
25
  zip.terminateWorkers();
26
- return TEXT_CONTENT == (await data.text()) && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
26
+ if (TEXT_CONTENT != await data.text() || entries[0].uncompressedSize != TEXT_CONTENT.length) {
27
+ throw new Error();
28
+ }
29
+ } else {
30
+ throw new Error();
27
31
  }
32
+ } else {
33
+ throw new Error();
28
34
  }
35
+ } else {
36
+ throw new Error();
29
37
  }
30
38
  }
@@ -26,7 +26,6 @@ async function test() {
26
26
  }
27
27
  } else if (location.search == "?test-ok") {
28
28
  resetSearch();
29
- return true;
30
29
  }
31
30
  }
32
31