@zip.js/zip.js 2.5.3 → 2.5.7

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 (51) 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 +470 -499
  5. package/dist/zip-fs-full.min.js +1 -1
  6. package/dist/zip-fs.js +470 -499
  7. package/dist/zip-fs.min.js +1 -1
  8. package/dist/zip-full.js +470 -499
  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 +470 -499
  14. package/dist/zip.min.js +1 -1
  15. package/index-fflate.js +1 -1
  16. package/index.d.ts +1 -1
  17. package/index.js +3 -3
  18. package/lib/core/{engine.js → codec-interface.js} +52 -50
  19. package/lib/core/{codecs/codec-pool-worker.js → codec-pool-worker.js} +55 -29
  20. package/lib/core/{codecs/codec-pool.js → codec-pool.js} +28 -9
  21. package/lib/core/configuration.js +10 -1
  22. package/lib/core/io.js +102 -100
  23. package/lib/core/{codecs → streams}/aes-crypto-stream.js +68 -54
  24. package/lib/core/{codecs → streams}/codec-stream.js +6 -6
  25. package/lib/core/{codecs → streams/codecs}/crc32.js +0 -0
  26. package/lib/core/{codecs → streams/codecs}/deflate.js +0 -0
  27. package/lib/core/{codecs → streams/codecs}/inflate.js +0 -0
  28. package/lib/core/{codecs → streams/codecs}/sjcl.js +0 -0
  29. package/lib/core/{codecs → streams}/crc32-stream.js +3 -4
  30. package/lib/core/{codecs → streams}/zip-crypto-stream.js +28 -32
  31. package/lib/core/streams/zip-entry-stream.js +185 -0
  32. package/lib/core/z-worker-core.js +30 -15
  33. package/lib/core/zip-fs-core.js +1 -1
  34. package/lib/core/zip-reader.js +21 -12
  35. package/lib/core/zip-writer.js +33 -25
  36. package/lib/z-worker-fflate.js +4 -1
  37. package/lib/z-worker-inline.js +1 -1
  38. package/lib/z-worker.js +2 -2
  39. package/lib/zip-fflate-shim.js +4 -1
  40. package/lib/zip-fs.js +6 -2
  41. package/lib/zip-full-fflate.js +6 -3
  42. package/lib/zip-full.js +8 -5
  43. package/lib/zip-no-worker-deflate.js +7 -3
  44. package/lib/zip-no-worker-fflate-deflate.js +6 -2
  45. package/lib/zip-no-worker-fflate-inflate.js +6 -3
  46. package/lib/zip-no-worker-fflate.js +6 -3
  47. package/lib/zip-no-worker-inflate.js +7 -4
  48. package/lib/zip-no-worker.js +8 -5
  49. package/lib/zip.js +6 -3
  50. package/package.json +2 -8
  51. package/lib/core/codecs/codec.js +0 -246
@@ -1,246 +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
- /* global ReadableStream, DecompressionStream, CompressionStream */
30
- // deno-lint-ignore-file no-this-alias
31
-
32
- import Crc32Stream from "./crc32-stream.js";
33
- import { AESEncryptStream, AESDecryptStream, ERR_INVALID_PASSWORD } from "./aes-crypto-stream.js";
34
- import { ZipCryptoDecryptStream, ZipCryptoEncryptStream } from "./zip-crypto-stream.js";
35
- import CodecStream from "./codec-stream.js";
36
-
37
- const CODEC_DEFLATE = "deflate";
38
- const CODEC_INFLATE = "inflate";
39
- const ERR_INVALID_SIGNATURE = "Invalid signature";
40
- const MESSAGE_EVENT_TYPE = "message";
41
- const MESSAGE_START = "start";
42
- const MESSAGE_PULL = "pull";
43
- const MESSAGE_DATA = "data";
44
- const MESSAGE_ABORT = "abort";
45
-
46
- class Inflate {
47
-
48
- constructor(codecConstructor, {
49
- signature,
50
- password,
51
- signed,
52
- compressed,
53
- zipCrypto,
54
- passwordVerification,
55
- encryptionStrength,
56
- useCompressionStream
57
- }, { chunkSize }) {
58
- const codec = this;
59
- codec.start = async () => {
60
- const encrypted = Boolean(password);
61
- Object.assign(codec, {
62
- signature,
63
- encrypted,
64
- signed,
65
- compressed,
66
- zipCrypto,
67
- stream: new ReadableStream({
68
- async pull(controller) {
69
- const { value, done } = await codec.pull();
70
- controller.enqueue(value);
71
- if (done || codec.aborted) {
72
- controller.close();
73
- }
74
- }
75
- })
76
- });
77
- if (encrypted) {
78
- if (zipCrypto) {
79
- codec.stream = codec.stream.pipeThrough(new ZipCryptoDecryptStream(password, passwordVerification));
80
- } else {
81
- codec.decryptStream = new AESDecryptStream(password, signed, encryptionStrength);
82
- codec.stream = codec.stream.pipeThrough(codec.decryptStream);
83
- }
84
- }
85
- if (compressed) {
86
- if ((useCompressionStream !== undefined && !useCompressionStream) || typeof DecompressionStream == "undefined") {
87
- pipeCodecStream();
88
- } else {
89
- try {
90
- codec.stream = codec.stream.pipeThrough(new DecompressionStream("deflate-raw"));
91
- } catch (_error) {
92
- pipeCodecStream();
93
- }
94
- }
95
- }
96
- if ((!encrypted || zipCrypto) && signed) {
97
- const tee = codec.stream.tee();
98
- codec.stream = tee[0];
99
- codec.crc32Stream = tee[1].pipeThrough(new Crc32Stream());
100
- }
101
- codec.reader = codec.stream.getReader();
102
- await codec.read();
103
- };
104
- codec.abort = () => codec.aborted = true;
105
-
106
- function pipeCodecStream() {
107
- codec.stream = codec.stream.pipeThrough(new CodecStream(codecConstructor, { chunkSize }));
108
- }
109
- }
110
-
111
- async read() {
112
- const codec = this;
113
- const { value, done } = await codec.reader.read();
114
- if (value && value.length) {
115
- codec.ondata({ value: { data: new Uint8Array(value) } });
116
- }
117
- if (done) {
118
- let signature;
119
- if (codec.encrypted && !codec.zipCrypto) {
120
- if (!codec.decryptStream.valid) {
121
- throw new Error(ERR_INVALID_SIGNATURE);
122
- }
123
- }
124
- if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
125
- signature = await codec.crc32Stream.getReader().read();
126
- const dataViewSignature = new DataView(signature.value.buffer);
127
- if (codec.signature != dataViewSignature.getUint32(0, false)) {
128
- throw new Error(ERR_INVALID_SIGNATURE);
129
- }
130
- }
131
- codec.ondata({ value: { signature }, done });
132
- } else {
133
- await codec.read();
134
- }
135
- }
136
- }
137
-
138
- class Deflate {
139
-
140
- constructor(codecConstructor, {
141
- encrypted,
142
- signed,
143
- compressed,
144
- level,
145
- zipCrypto,
146
- password,
147
- passwordVerification,
148
- encryptionStrength,
149
- useCompressionStream
150
- }, { chunkSize }) {
151
- const codec = this;
152
- codec.start = async () => {
153
- Object.assign(this, {
154
- encrypted,
155
- signed,
156
- compressed,
157
- zipCrypto,
158
- stream: new ReadableStream({
159
- async pull(controller) {
160
- const { value, done } = await codec.pull();
161
- controller.enqueue(value);
162
- if (done || codec.aborted) {
163
- controller.close();
164
- }
165
- }
166
- })
167
- });
168
- if ((!encrypted || zipCrypto) && signed) {
169
- const tee = codec.stream.tee();
170
- codec.stream = tee[0];
171
- codec.crc32Stream = tee[1].pipeThrough(new Crc32Stream({ chunkSize }));
172
- }
173
- if (compressed) {
174
- if ((useCompressionStream !== undefined && !useCompressionStream) || typeof CompressionStream == "undefined") {
175
- pipeCodecStream();
176
- } else {
177
- try {
178
- codec.stream = codec.stream.pipeThrough(new CompressionStream("deflate-raw"));
179
- } catch (_error) {
180
- pipeCodecStream();
181
- }
182
- }
183
- }
184
- if (encrypted) {
185
- if (zipCrypto) {
186
- codec.stream = codec.stream.pipeThrough(new ZipCryptoEncryptStream(password, passwordVerification));
187
- } else {
188
- codec.encryptStream = new AESEncryptStream(password, encryptionStrength);
189
- codec.stream = codec.stream.pipeThrough(codec.encryptStream);
190
- }
191
- }
192
- codec.reader = codec.stream.getReader();
193
- await codec.read();
194
- };
195
- codec.abort = () => codec.aborted = true;
196
-
197
- function pipeCodecStream() {
198
- codec.stream = codec.stream.pipeThrough(new CodecStream(codecConstructor, { chunkSize, level }));
199
- }
200
- }
201
-
202
- async read() {
203
- const codec = this;
204
- const { value, done } = await codec.reader.read();
205
- if (value && value.length) {
206
- codec.ondata({ value: { data: value } });
207
- }
208
- if (done) {
209
- let signature;
210
- if (codec.encrypted && !codec.zipCrypto) {
211
- signature = codec.encryptStream.signature;
212
- }
213
- if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
214
- signature = await codec.crc32Stream.getReader().read();
215
- signature = new DataView(signature.value.buffer).getUint32(0);
216
- }
217
- codec.ondata({ value: { signature }, done });
218
- } else {
219
- await codec.read();
220
- }
221
- }
222
-
223
- }
224
-
225
- export {
226
- Inflate,
227
- Deflate,
228
- createCodec,
229
- CODEC_DEFLATE,
230
- CODEC_INFLATE,
231
- ERR_INVALID_SIGNATURE,
232
- ERR_INVALID_PASSWORD,
233
- MESSAGE_EVENT_TYPE,
234
- MESSAGE_START,
235
- MESSAGE_PULL,
236
- MESSAGE_DATA,
237
- MESSAGE_ABORT
238
- };
239
-
240
- function createCodec(codecConstructor, options, config) {
241
- if (options.codecType.startsWith(CODEC_DEFLATE)) {
242
- return new Deflate(codecConstructor, options, config);
243
- } else if (options.codecType.startsWith(CODEC_INFLATE)) {
244
- return new Inflate(codecConstructor, options, config);
245
- }
246
- }