@zip.js/zip.js 2.6.8 → 2.6.11

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 (45) hide show
  1. package/README.md +14 -15
  2. package/dist/z-worker-fflate.js +1 -1
  3. package/dist/z-worker-pako.js +1 -1
  4. package/dist/z-worker.js +1 -1
  5. package/dist/zip-fs-full.js +57 -15
  6. package/dist/zip-fs-full.min.js +1 -1
  7. package/dist/zip-fs.js +57 -15
  8. package/dist/zip-fs.min.js +1 -1
  9. package/dist/zip-full.js +57 -15
  10. package/dist/zip-full.min.js +1 -1
  11. package/dist/zip-no-worker-deflate.min.js +1 -1
  12. package/dist/zip-no-worker-inflate.min.js +1 -1
  13. package/dist/zip-no-worker.min.js +1 -1
  14. package/dist/zip.js +57 -15
  15. package/dist/zip.min.js +1 -1
  16. package/index.d.ts +87 -5
  17. package/lib/core/codec-pool-worker.js +5 -1
  18. package/lib/core/streams/aes-crypto-stream.js +5 -12
  19. package/lib/core/streams/common-crypto.js +50 -0
  20. package/lib/core/streams/zip-crypto-stream.js +6 -4
  21. package/lib/core/streams/zip-entry-stream.js +3 -1
  22. package/lib/core/zip-writer.js +9 -3
  23. package/lib/z-worker-inline.js +1 -1
  24. package/package.json +5 -1
  25. package/tests/all/test-abort-signal-read.js +1 -1
  26. package/tests/all/test-abort-signal-write.js +1 -1
  27. package/tests/{browser → all}/test-codecs-interoperability.js +0 -0
  28. package/tests/all/test-crypto.js +2 -0
  29. package/tests/all/test-duplicated-filename.js +24 -0
  30. package/tests/{browser → all}/test-fflate.js +0 -0
  31. package/tests/{browser → all}/test-pako.js +0 -0
  32. package/tests/all/test-parallel-reads.js +13 -27
  33. package/tests/all/test-parallel-writes-auto-buffered.js +13 -27
  34. package/tests/all/test-parallel-writes.js +13 -27
  35. package/tests/all/test-safe-closing.js +13 -27
  36. package/tests/{browser → all}/test-sw-worker.js +0 -0
  37. package/tests/{browser → all}/test-sw.js +0 -0
  38. package/tests/all/test-zipcrypto.js +2 -1
  39. package/tests/deno-runner.js +2 -2
  40. package/tests/node-runner.js +32 -0
  41. package/tests/tests-data.js +17 -16
  42. package/tests/web-runner.js +4 -2
  43. package/tests/browser/loader.html +0 -31
  44. package/tests/node/package.json +0 -5
  45. package/tests/node/test-node.js +0 -30
@@ -1,4 +1,4 @@
1
- /* global Blob, FileReader */
1
+ /* global Blob */
2
2
 
3
3
  import * as zip from "../../index.js";
4
4
 
@@ -26,32 +26,18 @@ async function test() {
26
26
  return !results.includes(false);
27
27
  }
28
28
 
29
- function compareResult(result, value) {
30
- return new Promise(resolve => {
31
- const fileReaderInput = new FileReader();
32
- const fileReaderOutput = new FileReader();
33
- let loadCount = 0;
34
- fileReaderInput.readAsArrayBuffer(value);
35
- fileReaderOutput.readAsArrayBuffer(result);
36
- fileReaderInput.onload = fileReaderOutput.onload = () => {
37
- loadCount++;
38
- if (loadCount == 2) {
39
- const valueInput = new Float64Array(fileReaderInput.result);
40
- const valueOutput = new Float64Array(fileReaderOutput.result);
41
- if (valueInput.length != valueOutput.length) {
42
- resolve(false);
43
- return;
44
- }
45
- for (let indexValue = 0, n = valueInput.length; indexValue < n; indexValue++) {
46
- if (valueInput[indexValue] != valueOutput[indexValue]) {
47
- resolve(false);
48
- return;
49
- }
50
- }
51
- resolve(true);
52
- }
53
- };
54
- });
29
+ async function compareResult(result, value) {
30
+ const valueInput = new Float64Array(await result.arrayBuffer());
31
+ const valueOutput = new Float64Array(await value.arrayBuffer());
32
+ if (valueInput.length != valueOutput.length) {
33
+ return false;
34
+ }
35
+ for (let indexValue = 0, n = valueInput.length; indexValue < n; indexValue++) {
36
+ if (valueInput[indexValue] != valueOutput[indexValue]) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
55
41
  }
56
42
 
57
43
  function getBlob(size) {
File without changes
File without changes
@@ -16,14 +16,15 @@ async function test() {
16
16
  await zipWriter.close();
17
17
  const zipReader = new zip.ZipReader(new zip.BlobReader(blobWriter.getData()));
18
18
  const entries = await zipReader.getEntries();
19
- const dataBlobWriter = new zip.BlobWriter(zip.getMimeType(entries[0].filename));
20
19
  let data;
21
20
  if (entries[0].encrypted) {
21
+ const dataBlobWriter = new zip.BlobWriter(zip.getMimeType(entries[0].filename));
22
22
  try {
23
23
  data = await entries[0].getData(dataBlobWriter, { password: "notagoodpassword" });
24
24
  data = null;
25
25
  } catch (error) {
26
26
  if (error.message == zip.ERR_INVALID_PASSWORD) {
27
+ const dataBlobWriter = new zip.BlobWriter(zip.getMimeType(entries[0].filename));
27
28
  data = await entries[0].getData(dataBlobWriter, { password: "password" });
28
29
  } else {
29
30
  throw error;
@@ -5,10 +5,10 @@
5
5
  import tests from "./tests-data.js";
6
6
 
7
7
  for (const test of tests) {
8
- if (test.env != "browser") {
8
+ if (!test.env || test.env.includes("deno")) {
9
9
  Deno.test({
10
10
  name: test.title,
11
- fn: async () => (await import("./" + (test.env || "all") + "/" + test.script)).test(),
11
+ fn: async () => (await import("./all/" + test.script)).test(),
12
12
  sanitizeResources: test.sanitizeResources === undefined || test.sanitizeResources === true
13
13
  });
14
14
  }
@@ -0,0 +1,32 @@
1
+ /* global process */
2
+ /* eslint-disable no-console */
3
+
4
+ import data from "./tests-data.js";
5
+ runTests();
6
+
7
+ async function runTests() {
8
+ let passed = true;
9
+ let passedCount = 0;
10
+ const tests = data.filter(test => !test.env || test.env.includes("node"));
11
+ console.log("running", tests.length, "tests from ./node-runner.js");
12
+ for (const test of tests) {
13
+ const fn = async () => (await import("./all/" + test.script)).test();
14
+ try {
15
+ console.log(test.title + "...", await fn() && "ok");
16
+ passedCount++;
17
+ } catch (error) {
18
+ passed = false;
19
+ console.error(test.title + "...", "FAILED");
20
+ console.error(error);
21
+ }
22
+ }
23
+ console.log("");
24
+ if (passed) {
25
+ console.log("ok", "|", passedCount, "passed");
26
+ console.log("");
27
+ } else {
28
+ console.error("error: Test failed");
29
+ console.log("");
30
+ process.exit(-1);
31
+ }
32
+ }
@@ -4,45 +4,46 @@ export default ([
4
4
  { title: "Uint8Array", script: "./test-array.js" },
5
5
  { title: "Base 64", script: "./test-base64.js" },
6
6
  { title: "Blob", script: "./test-blob.js" },
7
- { title: "Codecs interoperability", script: "./test-codecs-interoperability.js", env: "browser" },
7
+ { title: "Codecs interoperability", script: "./test-codecs-interoperability.js", env: ["browser"] },
8
8
  { title: "Crypto", script: "./test-crypto.js" },
9
9
  { title: "Custom IO classes", script: "./test-custom-io.js" },
10
10
  { title: "Data descriptor signature", script: "./test-data-descriptor-signature.js" },
11
11
  { title: "Data descriptor", script: "./test-data-descriptor.js" },
12
+ { title: "Duplicated Filename", script: "./test-duplicated-filename.js" },
12
13
  { title: "Empty zip file", script: "./test-empty.js" },
13
14
  { title: "Extended timestamp", script: "./test-extended-timestamp.js" },
14
15
  { title: "Extra field", script: "./test-extra-field.js" },
15
- { title: "Fflate", script: "./test-fflate.js", env: "browser" },
16
+ { title: "Fflate", script: "./test-fflate.js", env: ["browser"] },
16
17
  { title: "Fflate (no worker)", script: "./test-fflate-no-worker.js", sanitizeResources: false },
17
18
  { title: "Filesystem base 64", script: "./test-fs-base64.js" },
18
- { title: "Filesystem export", script: "./test-fs-export-options.js" },
19
- { title: "Filesystem HTTP import", script: "./test-fs-http-import.js" },
20
- { title: "Filesystem HTTP reader", script: "./test-fs-http-reader.js" },
21
- { title: "Filesystem replace entry", script: "./test-fs-replace.js" },
19
+ { title: "Filesystem export", script: "./test-fs-export-options.js", env: ["deno", "browser"] },
20
+ { title: "Filesystem HTTP import", script: "./test-fs-http-import.js", env: ["deno", "browser"] },
21
+ { title: "Filesystem HTTP reader", script: "./test-fs-http-reader.js", env: ["deno", "browser"] },
22
+ { title: "Filesystem replace entry", script: "./test-fs-replace.js", env: ["deno", "browser"] },
22
23
  { title: "Filesystem streams", script: "./test-fs-streams.js" },
23
24
  { title: "Filesystem text", script: "./test-fs-text.js" },
24
- { title: "Filesystem unzip uncompressed file", script: "./test-fs-unzip-store.js" },
25
+ { title: "Filesystem unzip uncompressed file", script: "./test-fs-unzip-store.js", env: ["deno", "browser"] },
25
26
  { title: "Filesystem test", script: "./test-fs.js" },
26
- { title: "HTTP crypto", script: "./test-http-crypto.js" },
27
- { title: "HTTP zip64", script: "./test-http-zip64.js" },
28
- { title: "Invalid CRC", script: "./test-invalid-crc.js" },
27
+ { title: "HTTP crypto", script: "./test-http-crypto.js", env: ["deno", "browser"] },
28
+ { title: "HTTP zip64", script: "./test-http-zip64.js", env: ["deno", "browser"] },
29
+ { title: "Invalid CRC", script: "./test-invalid-crc.js", env: ["deno", "browser"] },
29
30
  { title: "No worker", script: "./test-no-worker.js" },
30
- { title: "Pako", script: "./test-pako.js", env: "browser" },
31
- { title: "Pako (no worker)", script: "./test-pako-no-worker.js" },
31
+ { title: "Pako", script: "./test-pako.js", env: ["browser"] },
32
+ { title: "Pako (no worker)", script: "./test-pako-no-worker.js", env: ["deno", "browser"] },
32
33
  { title: "Parallel reads", script: "./test-parallel-reads.js" },
33
34
  { title: "Parallel writes (auto buffered)", script: "./test-parallel-writes-auto-buffered.js" },
34
35
  { title: "Parallel writes (ordered)", script: "./test-parallel-writes-ordered.js" },
35
36
  { title: "Parallel writes", script: "./test-parallel-writes.js" },
36
- { title: "Readable Stream", script: "./test-readable-stream.js" },
37
- { title: "Readable Zip Stream", script: "./test-readable-zip-stream.js" },
37
+ { title: "Readable Stream", script: "./test-readable-stream.js", env: ["deno", "browser"] },
38
+ { title: "Readable Zip Stream", script: "./test-readable-zip-stream.js", env: ["deno", "browser"] },
38
39
  { title: "Safe closing", script: "./test-safe-closing.js" },
39
- { title: "Service worker", script: "./test-sw.js", env: "browser" },
40
+ { title: "Service worker", script: "./test-sw.js", env: ["browser"] },
40
41
  { title: "Signature CRC32", script: "./test-crc.js" },
41
42
  { title: "Store", script: "./test-store.js" },
42
43
  { title: "Worker timeout", script: "./test-worker-timeout.js" },
43
44
  { title: "Wrapped zip file", script: "./test-wrapped.js" },
44
45
  { title: "Writable Stream", script: "./test-writable-stream.js" },
45
- { title: "Zip64 (auto)", script: "./test-zip64-auto.js" },
46
+ { title: "Zip64 (auto)", script: "./test-zip64-auto.js", env: ["deno", "browser"] },
46
47
  { title: "Zip64 crypto", script: "./test-zip64-crypto.js" },
47
48
  { title: "Zip64", script: "./test-zip64.js" },
48
49
  { title: "Zipcrypto", script: "./test-zipcrypto.js" }
@@ -20,7 +20,9 @@ if (!location.search.startsWith("?keepTests")) {
20
20
  const test = tests[indexTest];
21
21
  indexTest++;
22
22
  if (test) {
23
- addTest(test);
23
+ if (!test.env || test.env.includes("browser")) {
24
+ addTest(test);
25
+ }
24
26
  } else if (!document.querySelectorAll("tr").length) {
25
27
  document.body.innerHTML = "ok";
26
28
  }
@@ -36,7 +38,7 @@ function addTest(test) {
36
38
  link.textContent = test.title;
37
39
  link.target = test.script;
38
40
  row.dataset.script = test.script;
39
- link.href = iframe.src = (test.env || "all") + "/loader.html#" + encodeURIComponent(JSON.stringify({ script: test.script }));
41
+ link.href = iframe.src = "/tests/all/loader.html#" + encodeURIComponent(JSON.stringify({ script: test.script }));
40
42
  cellTest.appendChild(iframe);
41
43
  cellLink.appendChild(link);
42
44
  row.appendChild(cellLink);
@@ -1,31 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
4
- <head>
5
- <meta charset='utf-8'>
6
- <style>
7
- body {
8
- margin: 0;
9
- }
10
- </style>
11
- </head>
12
-
13
- <body>
14
- ...
15
- <script>
16
- const testData = JSON.parse(decodeURIComponent(location.hash.substring(1)));
17
- const script = testData.script;
18
- import(testData.script).then(async Module => {
19
- try {
20
- const result = await Module.test();
21
- if (result) {
22
- document.body.innerHTML = "ok";
23
- parent.postMessage(JSON.stringify({ script }), "*");
24
- }
25
- } catch (error) {
26
- parent.postMessage(JSON.stringify({ script, error: { message: error.message, stack: error.stack } }), "*");
27
- throw error;
28
- }
29
- })
30
- </script>
31
- </body>
@@ -1,5 +0,0 @@
1
- {
2
- "name": "test-node-zipjs",
3
- "version": "1.0.0",
4
- "type": "module"
5
- }
@@ -1,30 +0,0 @@
1
- /* global TextEncoder */
2
- /* eslint-disable no-console */
3
-
4
- import { configure, Uint8ArrayWriter, Uint8ArrayReader, TextWriter, ZipWriter, ZipReader, terminateWorkers } from "../../index.js";
5
-
6
- 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.";
7
- const FILENAME = "lorem.txt";
8
- const UINT8_ARRAY = (new TextEncoder()).encode(TEXT_CONTENT);
9
-
10
- test()
11
- .then(result => result && console.log("ok"))
12
- .catch(error => console.error(error));
13
-
14
- async function test() {
15
- configure({ useWebWorkers: false });
16
- const blobWriter = new Uint8ArrayWriter(UINT8_ARRAY);
17
- const zipWriter = new ZipWriter(blobWriter);
18
- const entry = await zipWriter.add(FILENAME, new Uint8ArrayReader(UINT8_ARRAY));
19
- if (entry.compressionMethod == 0x08) {
20
- await zipWriter.close();
21
- const zipReader = new ZipReader(new Uint8ArrayReader(blobWriter.getData()));
22
- const entries = await zipReader.getEntries();
23
- if (entries[0].compressionMethod == 0x08) {
24
- const data = await entries[0].getData(new TextWriter());
25
- await zipReader.close();
26
- terminateWorkers();
27
- return TEXT_CONTENT == data && entries[0].filename == FILENAME && entries[0].uncompressedSize == TEXT_CONTENT.length;
28
- }
29
- }
30
- }