@zip.js/zip.js 2.6.32 → 2.6.34

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 (47) hide show
  1. package/dist/z-worker-fflate.js +1 -1
  2. package/dist/z-worker-pako.js +1 -1
  3. package/dist/z-worker.js +1 -1
  4. package/dist/zip-fs-full.js +2441 -2287
  5. package/dist/zip-fs-full.min.js +1 -1
  6. package/dist/zip-fs.js +1970 -1816
  7. package/dist/zip-fs.min.js +1 -1
  8. package/dist/zip-full.js +1969 -1815
  9. package/dist/zip-full.min.js +1 -1
  10. package/dist/zip-no-worker-deflate.min.js +1 -1
  11. package/dist/zip-no-worker-inflate.min.js +1 -1
  12. package/dist/zip-no-worker.min.js +1 -1
  13. package/dist/zip.js +1971 -1817
  14. package/dist/zip.min.js +1 -1
  15. package/index-fflate.js +3 -1
  16. package/index.cjs +2441 -2287
  17. package/index.d.ts +36 -7
  18. package/index.js +3 -1
  19. package/lib/core/codec-pool.js +6 -5
  20. package/lib/core/codec-worker.js +321 -0
  21. package/lib/core/configuration.js +11 -8
  22. package/lib/core/constants.js +11 -5
  23. package/lib/core/io.js +150 -51
  24. package/lib/core/streams/aes-crypto-stream.js +2 -0
  25. package/lib/core/streams/codec-stream.js +60 -13
  26. package/lib/core/streams/codecs/sjcl.js +1 -1
  27. package/lib/core/streams/stream-adapter.js +55 -0
  28. package/lib/core/streams/zip-crypto-stream.js +1 -0
  29. package/lib/core/streams/zip-entry-stream.js +1 -0
  30. package/lib/core/util/stream-codec-shim.js +2 -0
  31. package/lib/core/z-worker-core.js +23 -12
  32. package/lib/core/zip-entry.js +2 -1
  33. package/lib/core/zip-fs-core.js +1 -0
  34. package/lib/core/zip-reader.js +16 -12
  35. package/lib/core/zip-writer.js +102 -54
  36. package/lib/z-worker-inline.js +1 -1
  37. package/lib/zip.js +1 -1
  38. package/package.json +5 -5
  39. package/rollup-es5.config.dev.js +199 -0
  40. package/rollup-es5.config.js +243 -0
  41. package/tests/all/test-http-split-zip.js +37 -0
  42. package/tests/all/test-readable-stream.js +1 -2
  43. package/tests/all/test-readable-zip-stream.js +1 -1
  44. package/tests/all/test-split-zip.js +25 -22
  45. package/tests/tests-data.js +2 -1
  46. package/lib/core/codec-interface.js +0 -115
  47. package/lib/core/codec-pool-worker.js +0 -289
@@ -0,0 +1,243 @@
1
+ /*
2
+ Make sure the required packages are installed before running this script.
3
+
4
+ npm i @babel/core --save-dev
5
+ npm i @babel/preset-env --save-dev
6
+ npm i core-js --save-dev
7
+ npm i @rollup/plugin-babel --save-dev
8
+ npm i @rollup/plugin-commonjs --save-dev
9
+
10
+ Then, run the command below.
11
+
12
+ npx rollup -c rollup.config.js
13
+
14
+ */
15
+
16
+ import { babel } from "@rollup/plugin-babel";
17
+ import resolve from "@rollup/plugin-node-resolve";
18
+ import commonjs from "@rollup/plugin-commonjs";
19
+ import replace from "@rollup/plugin-replace";
20
+ import { terser } from "rollup-plugin-terser";
21
+ import fs from "fs";
22
+
23
+ const babelPresets = [
24
+ [
25
+ "@babel/preset-env",
26
+ {
27
+ corejs: 3,
28
+ modules: false,
29
+ useBuiltIns: "usage",
30
+ targets: {
31
+ chrome: "58"
32
+ }
33
+ }
34
+ ]
35
+ ];
36
+
37
+ const bundledPlugins = [
38
+ commonjs(),
39
+ resolve(),
40
+ babel({
41
+ babelHelpers: "bundled",
42
+ babelrc: false,
43
+ exclude: "node_modules/**",
44
+ presets: babelPresets,
45
+ compact: false
46
+ })
47
+ ];
48
+
49
+ const inlinePlugins = [
50
+ commonjs(),
51
+ resolve(),
52
+ babel({
53
+ babelHelpers: "inline",
54
+ babelrc: false,
55
+ exclude: "node_modules/**",
56
+ presets: babelPresets,
57
+ compact: false
58
+ })
59
+ ];
60
+
61
+ const bundledTerserOptions = {
62
+ compress: {
63
+ unsafe: true,
64
+ unsafe_arrows: true,
65
+ unsafe_comps: true,
66
+ unsafe_symbols: true,
67
+ unsafe_proto: true,
68
+ keep_fargs: false,
69
+ passes: 3,
70
+ ecma: "5"
71
+ }
72
+ };
73
+
74
+ const inlineTerserOptions = {
75
+ compress: {
76
+ unsafe: true,
77
+ unsafe_comps: true,
78
+ unsafe_math: true,
79
+ unsafe_symbols: true,
80
+ unsafe_proto: true,
81
+ keep_fargs: false,
82
+ passes: 3,
83
+ ecma: "5"
84
+ },
85
+ mangle: {
86
+ properties: {
87
+ reserved: ["codecType", "config", "salt", "iterations", "keys", "password", "encryptionStrength", "encrypted", "signed", "compressed", "level", "zipCrypto", "passwordVerification", "pull", "enqueue", "close", "messageId", "chunkSize", "highWaterMark", "useCompressionStream"]
88
+ }
89
+ }
90
+ };
91
+
92
+ const GLOBALS = "const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator } = typeof globalThis !== 'undefined' ? globalThis : this || self;";
93
+ const GLOBALS_WORKER = "const { Array, Object, Math, Error, Uint8Array, Uint32Array, Int32Array, Map, DataView, Promise, TextEncoder, crypto, postMessage, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream } = self;";
94
+
95
+ export default [{
96
+ input: "lib/z-worker.js",
97
+ output: [{
98
+ intro: GLOBALS_WORKER,
99
+ file: "lib/z-worker-inline.js",
100
+ format: "es",
101
+ plugins: [terser(inlineTerserOptions)]
102
+ }],
103
+ plugins: [
104
+ inlinePlugins,
105
+ replace({
106
+ preventAssignment: true,
107
+ "`": () => "'"
108
+ })
109
+ ]
110
+ }, {
111
+ input: "lib/z-worker-inline-template.js",
112
+ output: [{
113
+ file: "lib/z-worker-inline.js",
114
+ format: "es"
115
+ }],
116
+ plugins: [
117
+ replace({
118
+ preventAssignment: true,
119
+ "__workerCode__": () => fs.readFileSync("lib/z-worker-inline.js").toString()
120
+ }),
121
+ terser(bundledTerserOptions)
122
+ ]
123
+ }, {
124
+ input: ["lib/zip.js"],
125
+ output: [{
126
+ intro: GLOBALS,
127
+ file: "dist/zip.min.js",
128
+ format: "umd",
129
+ name: "zip",
130
+ plugins: [terser(bundledTerserOptions)]
131
+ }, {
132
+ intro: GLOBALS,
133
+ file: "dist/zip.js",
134
+ format: "umd",
135
+ name: "zip"
136
+ }],
137
+ plugins: bundledPlugins
138
+ }, {
139
+ input: ["lib/zip-full.js"],
140
+ output: [{
141
+ intro: GLOBALS,
142
+ file: "dist/zip-full.min.js",
143
+ format: "umd",
144
+ name: "zip",
145
+ plugins: [terser(bundledTerserOptions)]
146
+ }, {
147
+ intro: GLOBALS,
148
+ file: "dist/zip-full.js",
149
+ format: "umd",
150
+ name: "zip"
151
+ }],
152
+ plugins: bundledPlugins
153
+ }, {
154
+ input: "lib/zip-no-worker.js",
155
+ output: [{
156
+ intro: GLOBALS,
157
+ file: "dist/zip-no-worker.min.js",
158
+ format: "umd",
159
+ name: "zip",
160
+ plugins: [terser(bundledTerserOptions)]
161
+ }],
162
+ plugins: bundledPlugins
163
+ }, {
164
+ input: "lib/zip-no-worker-deflate.js",
165
+ output: [{
166
+ intro: GLOBALS,
167
+ file: "dist/zip-no-worker-deflate.min.js",
168
+ format: "umd",
169
+ name: "zip",
170
+ plugins: [terser(bundledTerserOptions)]
171
+ }],
172
+ plugins: bundledPlugins
173
+ }, {
174
+ input: "lib/zip-no-worker-inflate.js",
175
+ output: [{
176
+ intro: GLOBALS,
177
+ file: "dist/zip-no-worker-inflate.min.js",
178
+ format: "umd",
179
+ name: "zip",
180
+ plugins: [terser(bundledTerserOptions)]
181
+ }],
182
+ plugins: bundledPlugins
183
+ }, {
184
+ input: "lib/zip-fs.js",
185
+ output: [{
186
+ intro: GLOBALS,
187
+ file: "dist/zip-fs.min.js",
188
+ format: "umd",
189
+ name: "zip",
190
+ plugins: [terser(bundledTerserOptions)]
191
+ }, {
192
+ intro: GLOBALS,
193
+ file: "dist/zip-fs.js",
194
+ format: "umd",
195
+ name: "zip"
196
+ }],
197
+ plugins: bundledPlugins
198
+ }, {
199
+ input: "index.js",
200
+ output: [{
201
+ intro: GLOBALS,
202
+ file: "dist/zip-fs-full.min.js",
203
+ format: "umd",
204
+ name: "zip",
205
+ plugins: [terser(bundledTerserOptions)]
206
+ }, {
207
+ intro: GLOBALS,
208
+ file: "dist/zip-fs-full.js",
209
+ format: "umd",
210
+ name: "zip"
211
+ }, {
212
+ file: "index.cjs",
213
+ format: "cjs"
214
+ }],
215
+ plugins: bundledPlugins
216
+ }, {
217
+ input: "lib/z-worker-bootstrap-pako.js",
218
+ output: [{
219
+ intro: GLOBALS_WORKER,
220
+ file: "dist/z-worker-pako.js",
221
+ format: "iife",
222
+ plugins: [terser(bundledTerserOptions)]
223
+ }],
224
+ plugins: inlinePlugins
225
+ }, {
226
+ input: "lib/z-worker-bootstrap-fflate.js",
227
+ output: [{
228
+ intro: GLOBALS_WORKER,
229
+ file: "dist/z-worker-fflate.js",
230
+ format: "iife",
231
+ plugins: [terser(bundledTerserOptions)]
232
+ }],
233
+ plugins: inlinePlugins
234
+ }, {
235
+ input: "lib/z-worker.js",
236
+ output: [{
237
+ intro: GLOBALS_WORKER,
238
+ file: "dist/z-worker.js",
239
+ format: "iife",
240
+ plugins: [terser(bundledTerserOptions)]
241
+ }],
242
+ plugins: inlinePlugins
243
+ }];
@@ -0,0 +1,37 @@
1
+ /* global URL */
2
+
3
+ import * as zip from "../../index.js";
4
+
5
+ const PATHS = [
6
+ "./../data/lorem-split.z01",
7
+ "./../data/lorem-split.z02",
8
+ "./../data/lorem-split.z03",
9
+ "./../data/lorem-split.z04",
10
+ "./../data/lorem-split.z05",
11
+ "./../data/lorem-split.z06",
12
+ "./../data/lorem-split.z07",
13
+ "./../data/lorem-split.zip",
14
+ ];
15
+ const UNCOMPRESSED_SIZES = [
16
+ 1162,
17
+ 204946,
18
+ 603889,
19
+ 809738
20
+ ];
21
+
22
+ export { test };
23
+
24
+ async function test() {
25
+ zip.configure({ chunkSize: 16 * 1024, useWebWorkers: true });
26
+ const readers = PATHS.map(url => new zip.HttpReader(new URL(url, import.meta.url).href, { preventHeadRequest: true }));
27
+ const zipReader = new zip.ZipReader(new zip.SplitZipReader(readers));
28
+ const entries = await zipReader.getEntries();
29
+ const results = await Promise.all(UNCOMPRESSED_SIZES.map(async (uncompressedSize, indexEntry) =>
30
+ (await entries[indexEntry].getData(new zip.TextWriter())).length == uncompressedSize
31
+ ));
32
+ await zipReader.close();
33
+ zip.terminateWorkers();
34
+ if (results.includes(false)) {
35
+ throw new Error();
36
+ }
37
+ }
@@ -12,8 +12,7 @@ async function test() {
12
12
  const blobWriter = new zip.BlobWriter("application/zip");
13
13
  const zipWriter = new zip.ZipWriter(blobWriter);
14
14
  const readable = (await fetch(new URL("../data/lorem.txt", import.meta.url))).body;
15
- const reader = { readable };
16
- await zipWriter.add(FILENAME, reader);
15
+ await zipWriter.add(FILENAME, readable);
17
16
  await zipWriter.close();
18
17
  const zipReader = new zip.ZipReader(new zip.BlobReader(await blobWriter.getData()));
19
18
  const entries = await zipReader.getEntries();
@@ -9,7 +9,7 @@ export { test };
9
9
  async function test() {
10
10
  zip.configure({ chunkSize: 128, useWebWorkers: true });
11
11
  const readable = (await fetch(new URL("../data/lorem.zip", import.meta.url))).body;
12
- const zipReader = new zip.ZipReader({ readable });
12
+ const zipReader = new zip.ZipReader(readable);
13
13
  const entries = await zipReader.getEntries();
14
14
  const data = await entries[0].getData(new zip.BlobWriter());
15
15
  await zipReader.close();
@@ -1,34 +1,37 @@
1
- /* global URL */
1
+ /* global Blob */
2
2
 
3
3
  import * as zip from "../../index.js";
4
4
 
5
- const PATHS = [
6
- "./../data/lorem-split.z01",
7
- "./../data/lorem-split.z02",
8
- "./../data/lorem-split.z03",
9
- "./../data/lorem-split.z04",
10
- "./../data/lorem-split.z05",
11
- "./../data/lorem-split.z06",
12
- "./../data/lorem-split.z07",
13
- "./../data/lorem-split.zip",
14
- ];
15
- const UNCOMPRESSED_SIZES = [
16
- 1162,
17
- 204946,
18
- 603889,
19
- 809738
20
- ];
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 TEXT_CONTENT_REPEAT = 1024;
7
+ const BLOB = new Blob([new Array(TEXT_CONTENT_REPEAT).fill(TEXT_CONTENT).join("")]);
21
8
 
22
9
  export { test };
23
10
 
11
+ const writers = [];
12
+
13
+ function* blobWriterGenerator() {
14
+ while (true) {
15
+ const writer = new zip.BlobWriter();
16
+ writers.push(writer);
17
+ yield writer;
18
+ }
19
+ }
20
+
24
21
  async function test() {
25
- zip.configure({ chunkSize: 16 * 1024, useWebWorkers: true });
26
- const readers = PATHS.map(url => new zip.HttpReader(new URL(url, import.meta.url).href, { preventHeadRequest: true }));
22
+ zip.configure({ chunkSize: 1024, useWebWorkers: true });
23
+ const splitZipWriter = new zip.SplitZipWriter(blobWriterGenerator(), 8192);
24
+ const zipWriter = new zip.ZipWriter(splitZipWriter);
25
+ await Promise.all([
26
+ zipWriter.add("lorem1.txt", new zip.BlobReader(BLOB)),
27
+ zipWriter.add("lorem2.txt", new zip.BlobReader(BLOB)),
28
+ zipWriter.add("lorem3.txt", new zip.BlobReader(BLOB))
29
+ ]);
30
+ await zipWriter.close();
31
+ const readers = await Promise.all(writers.map(async writer => new zip.BlobReader(await writer.getData())));
27
32
  const zipReader = new zip.ZipReader(new zip.SplitZipReader(readers));
28
33
  const entries = await zipReader.getEntries();
29
- const results = await Promise.all(UNCOMPRESSED_SIZES.map(async (uncompressedSize, indexEntry) =>
30
- (await entries[indexEntry].getData(new zip.TextWriter())).length == uncompressedSize
31
- ));
34
+ const results = await Promise.all(entries.map(async entry => (await entry.getData(new zip.TextWriter())).length == TEXT_CONTENT.length * TEXT_CONTENT_REPEAT));
32
35
  await zipReader.close();
33
36
  zip.terminateWorkers();
34
37
  if (results.includes(false)) {
@@ -26,6 +26,7 @@ export default ([
26
26
  { title: "Filesystem unzip uncompressed file", script: "./test-fs-unzip-store.js", env: ["deno", "browser"] },
27
27
  { title: "Filesystem test", script: "./test-fs.js" },
28
28
  { title: "HTTP crypto", script: "./test-http-crypto.js", env: ["deno", "browser"] },
29
+ { title: "HTTP split file", script: "./test-http-split-zip.js", env: ["deno", "browser"] },
29
30
  { title: "HTTP zip64", script: "./test-http-zip64.js", env: ["deno", "browser"] },
30
31
  { title: "Invalid CRC", script: "./test-invalid-crc.js", env: ["deno", "browser"] },
31
32
  { title: "Multiple writers", script: "./test-multiple-writers.js" },
@@ -41,7 +42,7 @@ export default ([
41
42
  { title: "Safe closing", script: "./test-safe-closing.js" },
42
43
  { title: "Service worker", script: "./test-sw.js", env: ["browser"] },
43
44
  { title: "Signature CRC32", script: "./test-crc.js" },
44
- { title: "Split files", script: "./test-split-zip.js", env: ["deno", "browser"] },
45
+ { title: "Split file", script: "./test-split-zip.js" },
45
46
  { title: "Store", script: "./test-store.js" },
46
47
  { title: "Streams", script: "./test-streams.js" },
47
48
  { title: "Worker timeout", script: "./test-worker-timeout.js" },
@@ -1,115 +0,0 @@
1
- /*
2
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
-
7
- 1. Redistributions of source code must retain the above copyright notice,
8
- this list of conditions and the following disclaimer.
9
-
10
- 2. Redistributions in binary form must reproduce the above copyright
11
- notice, this list of conditions and the following disclaimer in
12
- the documentation and/or other materials provided with the distribution.
13
-
14
- 3. The names of the authors may not be used to endorse or promote products
15
- derived from this software without specific prior written permission.
16
-
17
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
18
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
20
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
- */
28
-
29
- // deno-lint-ignore-file no-this-alias
30
- /* global TransformStream */
31
-
32
- import {
33
- InflateStream,
34
- DeflateStream,
35
- ERR_INVALID_PASSWORD,
36
- ERR_INVALID_SIGNATURE
37
- } from "./streams/zip-entry-stream.js";
38
- import { CodecStream } from "./streams/codec-stream.js";
39
-
40
- const CODEC_DEFLATE = "deflate";
41
- const CODEC_INFLATE = "inflate";
42
- const MESSAGE_EVENT_TYPE = "message";
43
- const MESSAGE_START = "start";
44
- const MESSAGE_PULL = "pull";
45
- const MESSAGE_DATA = "data";
46
- const MESSAGE_ACK_DATA = "ack";
47
- const MESSAGE_CLOSE = "close";
48
-
49
- export {
50
- Codec,
51
- getCodecStreamClass,
52
- CODEC_DEFLATE,
53
- CODEC_INFLATE,
54
- ERR_INVALID_SIGNATURE,
55
- ERR_INVALID_PASSWORD,
56
- MESSAGE_EVENT_TYPE,
57
- MESSAGE_START,
58
- MESSAGE_PULL,
59
- MESSAGE_DATA,
60
- MESSAGE_ACK_DATA,
61
- MESSAGE_CLOSE
62
- };
63
-
64
- class Codec {
65
-
66
- constructor(readable, writable, options, config) {
67
- const { codecType } = options;
68
- let CodecStream;
69
- if (codecType.startsWith(CODEC_DEFLATE)) {
70
- CodecStream = DeflateStream;
71
- } else if (codecType.startsWith(CODEC_INFLATE)) {
72
- CodecStream = InflateStream;
73
- }
74
- Object.assign(this, {
75
- CodecStream,
76
- readable,
77
- writable,
78
- options,
79
- config
80
- });
81
- }
82
-
83
- async run() {
84
- const {
85
- CodecStream,
86
- readable,
87
- writable,
88
- options,
89
- config
90
- } = this;
91
- const stream = new CodecStream(options, config);
92
- let size = 0;
93
- await readable
94
- .pipeThrough(stream)
95
- .pipeThrough(new TransformStream({
96
- transform(chunk, controller) {
97
- if (chunk && chunk.length) {
98
- size += chunk.length;
99
- controller.enqueue(chunk);
100
- }
101
- }
102
- }))
103
- .pipeTo(writable, { preventClose: true, preventAbort: true });
104
- const { signature } = stream;
105
- return { size, signature };
106
- }
107
- }
108
-
109
- function getCodecStreamClass(Codec) {
110
- return class extends CodecStream {
111
- constructor(algorithm, options) {
112
- super(Codec, options);
113
- }
114
- };
115
- }