@zip.js/zip.js 2.8.52 → 2.8.54

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 (49) hide show
  1. package/README.md +1 -1
  2. package/deno.json +2 -1
  3. package/dist/zip-core-external.js +839 -528
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +847 -527
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +880 -557
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +829 -538
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +880 -557
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +895 -558
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +894 -557
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +849 -529
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +849 -529
  20. package/dist/zip-native.min.js +1 -1
  21. package/dist/zip-web-worker-native.js +1 -1
  22. package/dist/zip-web-worker.js +1 -1
  23. package/dist/zip.js +848 -528
  24. package/dist/zip.min.js +1 -1
  25. package/eslint.config.mjs +2 -1
  26. package/index-native.cjs +895 -558
  27. package/index-native.min.js +1 -1
  28. package/index.cjs +894 -557
  29. package/index.d.cts +672 -78
  30. package/index.d.ts +672 -78
  31. package/index.min.js +1 -1
  32. package/lib/core/codec-worker-web.js +13 -4
  33. package/lib/core/configuration.js +62 -21
  34. package/lib/core/constants.js +16 -1
  35. package/lib/core/io.js +44 -29
  36. package/lib/core/options.js +46 -2
  37. package/lib/core/streams/aes-crypto-stream.js +12 -12
  38. package/lib/core/util/decode-text.js +11 -2
  39. package/lib/core/web-worker-base.js +3 -2
  40. package/lib/core/web-worker-inline-native.js +1 -1
  41. package/lib/core/web-worker-inline-wasm.js +1 -1
  42. package/lib/core/zip-entry.js +8 -0
  43. package/lib/core/zip-fs.js +38 -27
  44. package/lib/core/zip-reader.js +149 -60
  45. package/lib/core/zip-writer.js +329 -189
  46. package/lib/zip-core-base.js +6 -1
  47. package/lib/zip-core-reader.js +1 -0
  48. package/lib/zip-core-writer.js +5 -0
  49. package/package.json +11 -3
package/index.cjs CHANGED
@@ -39,6 +39,7 @@ const COMPRESSION_METHOD_AES = 0x63;
39
39
 
40
40
  const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
41
41
  const SPLIT_ZIP_FILE_SIGNATURE = 0x08074b50;
42
+ const TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE = 0x30304b50;
42
43
  const DATA_DESCRIPTOR_RECORD_SIGNATURE = SPLIT_ZIP_FILE_SIGNATURE;
43
44
  const ARCHIVE_EXTRA_DATA_SIGNATURE = 0x08064b50;
44
45
  const DIGITAL_SIGNATURE_RECORD_SIGNATURE = 0x05054b50;
@@ -55,6 +56,7 @@ const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_
55
56
  const DATA_DESCRIPTOR_RECORD_LENGTH = 12;
56
57
  const DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH = 20;
57
58
  const DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH = 4;
59
+ const SPLIT_ZIP_FILE_SIGNATURE_LENGTH = 4;
58
60
 
59
61
  const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
60
62
  const EXTRAFIELD_TYPE_AES = 0x9901;
@@ -96,6 +98,9 @@ const VERSION_DEFLATE = 0x14;
96
98
  const VERSION_ZIP64 = 0x2D;
97
99
  const VERSION_AES = 0x33;
98
100
 
101
+ const VERSION_MADE_BY_MSDOS = 0x0014;
102
+ const VERSION_MADE_BY_UNIX = 0x0300;
103
+
99
104
  const DIRECTORY_SIGNATURE = "/";
100
105
 
101
106
  const HEADER_SIZE = 30;
@@ -103,6 +108,8 @@ const HEADER_OFFSET_VERSION = 0;
103
108
  const HEADER_OFFSET_SIGNATURE = 10;
104
109
  const HEADER_OFFSET_COMPRESSED_SIZE = 14;
105
110
  const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
111
+ const HEADER_OFFSET_FILENAME_LENGTH = 22;
112
+ const HEADER_OFFSET_EXTRAFIELD_LENGTH = 24;
106
113
  const LOCAL_HEADER_COMMON_OFFSET = 4;
107
114
 
108
115
  const MAX_DATE = new Date(2107, 11, 31, 23, 59, 58);
@@ -115,9 +122,116 @@ const FUNCTION_TYPE = "function";
115
122
  const OBJECT_TYPE = "object";
116
123
  const STRING_TYPE = "string";
117
124
  const NUMBER_TYPE = "number";
125
+ const BOOLEAN_TYPE = "boolean";
118
126
 
119
127
  const EMPTY_UINT8_ARRAY = new Uint8Array();
120
128
 
129
+ /*
130
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
131
+
132
+ Redistribution and use in source and binary forms, with or without
133
+ modification, are permitted provided that the following conditions are met:
134
+
135
+ 1. Redistributions of source code must retain the above copyright notice,
136
+ this list of conditions and the following disclaimer.
137
+
138
+ 2. Redistributions in binary form must reproduce the above copyright
139
+ notice, this list of conditions and the following disclaimer in
140
+ the documentation and/or other materials provided with the distribution.
141
+
142
+ 3. The names of the authors may not be used to endorse or promote products
143
+ derived from this software without specific prior written permission.
144
+
145
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
146
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
147
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
148
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
149
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
150
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
151
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
152
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
153
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
154
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155
+ */
156
+
157
+
158
+ const OPTION_FILENAME_ENCODING = "filenameEncoding";
159
+ const OPTION_COMMENT_ENCODING = "commentEncoding";
160
+ const OPTION_DECODE_TEXT = "decodeText";
161
+ const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
162
+ const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
163
+ const OPTION_PASSWORD = "password";
164
+ const OPTION_RAW_PASSWORD = "rawPassword";
165
+ const OPTION_PASS_THROUGH = "passThrough";
166
+ const OPTION_SIGNAL = "signal";
167
+ const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
168
+ const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
169
+ const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
170
+ const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
171
+ const OPTION_CHECK_LOCAL_DIRECTORY = "checkLocalDirectory";
172
+ const OPTION_CHECK_SIGNATURE = "checkSignature";
173
+ const OPTION_CHECK_CRC32 = "checkCrc32";
174
+ const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
175
+ const OPTION_USE_WEB_WORKERS = "useWebWorkers";
176
+ const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
177
+ const OPTION_TRANSFER_STREAMS = "transferStreams";
178
+ const OPTION_PREVENT_CLOSE = "preventClose";
179
+ const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
180
+ const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
181
+ const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
182
+ const OPTION_KEEP_ORDER = "keepOrder";
183
+ const OPTION_LEVEL = "level";
184
+ const OPTION_BUFFERED_WRITE = "bufferedWrite";
185
+ const OPTION_CREATE_TEMP_STREAM = "createTempStream";
186
+ const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
187
+ const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
188
+ const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
189
+ const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
190
+ const OPTION_ENCODE_TEXT = "encodeText";
191
+ const OPTION_OFFSET = "offset";
192
+ const OPTION_USDZ = "usdz";
193
+ const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
194
+ const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
195
+ const OPTION_STRICTNESS = "strictness";
196
+ const OPTION_FILENAME_VALIDATION = "filenameValidation";
197
+ const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
198
+ const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
199
+ const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
200
+ const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
201
+ const TEXT_TYPE_FILENAME = "filename";
202
+ const TEXT_TYPE_COMMENT = "comment";
203
+ const STRICTNESS_STRICT = "strict";
204
+ const STRICTNESS_BALANCED = "balanced";
205
+ const STRICTNESS_TOLERANT = "tolerant";
206
+
207
+ const ERR_INVALID_FUNCTION_OPTION = "Invalid option (must be a function)";
208
+ const ERR_INVALID_SIGNAL = "Invalid signal (must be an AbortSignal instance)";
209
+ const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
210
+
211
+ function checkFunctionOption(value) {
212
+ if (value && typeof value != FUNCTION_TYPE) {
213
+ throw new Error(ERR_INVALID_FUNCTION_OPTION);
214
+ }
215
+ return value;
216
+ }
217
+
218
+ function checkSignalOption(signal) {
219
+ if (signal && (typeof signal.addEventListener != FUNCTION_TYPE || typeof signal.aborted != BOOLEAN_TYPE)) {
220
+ throw new Error(ERR_INVALID_SIGNAL);
221
+ }
222
+ return signal || UNDEFINED_VALUE;
223
+ }
224
+
225
+ function checkPasswordOption(password, rawPassword) {
226
+ if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
227
+ throw new Error(ERR_INVALID_PASSWORD_TYPE);
228
+ }
229
+ }
230
+
231
+ function toNumber(value) {
232
+ return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
233
+ }
234
+
121
235
  /*
122
236
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
123
237
 
@@ -147,7 +261,10 @@ const EMPTY_UINT8_ARRAY = new Uint8Array();
147
261
  */
148
262
 
149
263
 
264
+ const DEFAULT_CHUNK_SIZE$1 = 64 * 1024;
150
265
  const MINIMUM_CHUNK_SIZE = 64;
266
+ const MINIMUM_PROPERTY_VALUE = 1;
267
+ const ERR_INVALID_MAX_WORKERS = "Invalid maxWorkers (must be an integer greater than 0)";
151
268
  let maxWorkers = 2;
152
269
  try {
153
270
  if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
@@ -159,7 +276,7 @@ try {
159
276
  const DEFAULT_CONFIGURATION = {
160
277
  workerURI: "./core/web-worker-wasm.js",
161
278
  wasmURI: "./core/streams/zlib-wasm/zlib-streams.wasm",
162
- chunkSize: 64 * 1024,
279
+ chunkSize: DEFAULT_CHUNK_SIZE$1,
163
280
  maxWorkers,
164
281
  terminateWorkerTimeout: 5000,
165
282
  workerStarvationTimeout: 5000,
@@ -171,24 +288,38 @@ const DEFAULT_CONFIGURATION = {
171
288
  DecompressionStream: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
172
289
  };
173
290
 
174
- const CONFIGURABLE_PROPERTY_NAMES = [
291
+ const PROPERTY_NAME_MAX_WORKERS = "maxWorkers";
292
+
293
+ const STRING_PROPERTY_NAMES = [
175
294
  "baseURI",
176
295
  "wasmURI",
177
- "workerURI",
178
- "createWorker",
296
+ "workerURI"
297
+ ];
298
+ const BOOLEAN_PROPERTY_NAMES = [
299
+ "useCompressionStream",
300
+ "useWebWorkers",
301
+ "transferStreams"
302
+ ];
303
+ const NUMBER_PROPERTY_NAMES = [
179
304
  "chunkSize",
180
- "maxWorkers",
305
+ PROPERTY_NAME_MAX_WORKERS,
181
306
  "terminateWorkerTimeout",
182
307
  "workerStarvationTimeout",
183
- "workerStartupTimeout",
184
- "useCompressionStream",
185
- "useWebWorkers",
186
- "transferStreams",
308
+ "workerStartupTimeout"
309
+ ];
310
+ const FUNCTION_PROPERTY_NAMES = [
311
+ "createWorker",
187
312
  "CompressionStream",
188
313
  "DecompressionStream",
189
314
  "CompressionStreamFallback",
190
315
  "DecompressionStreamFallback"
191
316
  ];
317
+ const CONFIGURABLE_PROPERTY_NAMES = [
318
+ ...STRING_PROPERTY_NAMES,
319
+ ...BOOLEAN_PROPERTY_NAMES,
320
+ ...NUMBER_PROPERTY_NAMES,
321
+ ...FUNCTION_PROPERTY_NAMES
322
+ ];
192
323
 
193
324
  const config = { ...DEFAULT_CONFIGURATION };
194
325
 
@@ -197,20 +328,43 @@ function getConfiguration() {
197
328
  }
198
329
 
199
330
  function getChunkSize(config) {
200
- return Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
331
+ return normalizeChunkSize(config.chunkSize);
332
+ }
333
+
334
+ function normalizeChunkSize(chunkSize) {
335
+ chunkSize = toNumber(chunkSize);
336
+ return Number.isInteger(chunkSize) && chunkSize >= MINIMUM_PROPERTY_VALUE ? Math.max(chunkSize, MINIMUM_CHUNK_SIZE) : DEFAULT_CHUNK_SIZE$1;
201
337
  }
202
338
 
203
339
  function configure(configuration) {
204
- configuration = normalizeConfiguration(configuration);
340
+ Object.assign(config, checkConfiguration(normalizeConfiguration(configuration)));
341
+ }
342
+
343
+ function checkConfiguration(configuration) {
344
+ const checkedConfiguration = {};
205
345
  for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
206
346
  const propertyValue = configuration[propertyName];
207
347
  if (propertyValue !== UNDEFINED_VALUE) {
208
- config[propertyName] = propertyValue;
348
+ checkedConfiguration[propertyName] = checkPropertyValue(propertyName, propertyValue);
349
+ }
350
+ }
351
+ return checkedConfiguration;
352
+ }
353
+
354
+ function checkPropertyValue(propertyName, propertyValue) {
355
+ if (NUMBER_PROPERTY_NAMES.includes(propertyName)) {
356
+ propertyValue = toNumber(propertyValue);
357
+ if (propertyName == PROPERTY_NAME_MAX_WORKERS && (!Number.isInteger(propertyValue) || propertyValue < MINIMUM_PROPERTY_VALUE)) {
358
+ throw new Error(ERR_INVALID_MAX_WORKERS);
209
359
  }
360
+ } else if (FUNCTION_PROPERTY_NAMES.includes(propertyName)) {
361
+ checkFunctionOption(propertyValue);
210
362
  }
363
+ return propertyValue;
211
364
  }
212
365
 
213
366
  function normalizeConfiguration(configuration) {
367
+ configuration = configuration || {};
214
368
  const { CompressionStreamZlib, DecompressionStreamZlib } = configuration;
215
369
  if (CompressionStreamZlib === UNDEFINED_VALUE && DecompressionStreamZlib === UNDEFINED_VALUE) {
216
370
  return configuration;
@@ -226,14 +380,9 @@ function normalizeConfiguration(configuration) {
226
380
  }
227
381
 
228
382
  function setDefaultConfiguration(configuration) {
229
- configuration = normalizeConfiguration(configuration);
230
- for (const propertyName of CONFIGURABLE_PROPERTY_NAMES) {
231
- const propertyValue = configuration[propertyName];
232
- if (propertyValue !== UNDEFINED_VALUE) {
233
- DEFAULT_CONFIGURATION[propertyName] = propertyValue;
234
- }
235
- }
236
- configure(configuration);
383
+ const checkedConfiguration = checkConfiguration(normalizeConfiguration(configuration));
384
+ Object.assign(DEFAULT_CONFIGURATION, checkedConfiguration);
385
+ Object.assign(config, checkedConfiguration);
237
386
  }
238
387
 
239
388
  function resetConfiguration() {
@@ -243,7 +392,7 @@ function resetConfiguration() {
243
392
  Object.assign(config, DEFAULT_CONFIGURATION);
244
393
  }
245
394
 
246
- const t$1=new Uint8Array(288);t$1.fill(8,0,144),t$1.fill(9,144,256),t$1.fill(7,256,280),t$1.fill(8,280,288),new Uint8Array(30).fill(5);const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n$1=t=>t({workerURI:t=>{const n="text/javascript";let s='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:c,Uint32Array:i,Int32Array:a,Map:f,DataView:l,Promise:w,TextEncoder:u,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:S,DecompressionStream:g}=self,v=void 0,b="undefined",k="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[A,I,x,M,P,D,F,B]=C;class R{constructor(t){this.o=t||-1}append(t){let e=0|this.o;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=B[255&t]^F[t>>>8&255]^D[t>>>16&255]^P[t>>>24&255]^M[255&n]^x[n>>>8&255]^I[n>>>16&255]^A[n>>>24&255]}}for(;n>s;s++)e=e>>>8^A[255&(e^t[s])];this.o=e}get(){return~this.o}}class U extends d{constructor(){let t;const e=new R;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}function W(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}function _(t){return new l(t.buffer,t.byteOffset,t.byteLength)}const T={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=T.l(n);return 32===s?t.concat(e):T.h(e,s,0|n,t.slice(0,t.length-1))},bitLength(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+T.l(n)},m(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=T.S(e,t[n-1]&2147483648>>e-1,1)),t},S:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=T.l(r);return s.push(T.S(e+o&31,e+o>32?n:s.pop(),1)),s}},V={bytes:{v(t){const e=T.bitLength(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},C(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(T.S(8*(3&n),s)),e}}},K=class{constructor(t){const e=this;e.blockSize=512,e.A=[1732584193,4023233417,2562383102,271733878,3285377520],e.I=[1518500249,1859775393,2400959708,3395469782],t?(e.M=t.M.slice(0),e.P=t.P.slice(0),e.D=t.D):e.reset()}reset(){const t=this;return t.M=t.A.slice(0),t.P=[],t.D=0,t}update(t){const e=this;"string"==typeof t&&(t=V.F.C(t));const n=e.P=T.concat(e.P,t),s=e.D,o=e.D=s+T.bitLength(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new i(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.B(c.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}R(){const t=this;let e=t.P;const n=t.M;e=T.concat(e,[T.S(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.D/4294967296)),e.push(0|t.D);e.length;)t.B(e.splice(0,16));return t.reset(),n}U(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}B(e){const n=this,r=n.M,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let c=r[0],i=r[1],a=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,c)+n.U(t,i,a,f)+l+o[t]+n.I[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,i),i=c,c=e}r[0]=r[0]+c|0,r[1]=r[1]+i|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},E={importKey:t=>new E._(V.bytes.C(t)),T(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let c,i,a,f,w;const u=new ArrayBuffer(o),h=new l(u);let p=0;const d=T;for(e=V.bytes.C(e),w=1;(o||1)>p;w++){for(c=i=t.encrypt(d.concat(e,[w])),a=1;n>a;a++)for(i=t.encrypt(i),f=0;f<i.length;f++)c[f]^=i[f];for(a=0;(o||1)>p&&a<c.length;a++)h.setInt32(p,c[a]),p+=4}return u.slice(0,s/8)},_:class{constructor(t){const e=this,n=e.V=K,s=[[],[]];e.K=[new n,new n];const r=e.K[0].blockSize/32;t.length>r&&(t=(new n).update(t).R());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.K[0].update(s[0]),e.K[1].update(s[1]),e.L=new n(e.K[0])}reset(){const t=this;t.L=new t.V(t.K[0]),t.O=!1}update(t){this.O=!0,this.L.update(t)}digest(){const t=this,e=t.L.R(),n=new t.V(t.K[1]).update(e).R();return t.reset(),n}encrypt(t){if(this.O)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},L=typeof h!=b&&typeof h.getRandomValues==k,O="Invalid password",j="Invalid signature",H=j,N="zipjs-abort-check-password";function q(t){if(L)return h.getRandomValues(t);throw new r("Crypto API not supported")}const G=16,J={name:"PBKDF2"},Q=e.assign({hash:{name:"HMAC"}},J),X=e.assign({iterations:1e3,hash:{name:"SHA-1"}},J),Y=["deriveBits"],Z=[8,12,16],$=[16,24,32],tt=10,et=[0,0,0,0],nt=typeof h!=b,st=nt&&h.subtle,rt=nt&&typeof st!=b,ot=V.bytes,ct=class{constructor(t){const e=this;e.j=[[[],[],[],[],[]],[[],[],[],[],[]]],e.j[0][0][0]||e.H();const n=e.j[0][4],s=e.j[1],o=t.length;let c,i,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.I=[i=t.slice(0),a=[]],c=o;4*o+28>c;c++){let t=i[c-1];(c%o===0||8===o&&c%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],c%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),i[c]=i[c-o]^t}for(let t=0;c;t++,c--){const e=i[3&t?c:c-4];a[t]=4>=c||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}H(){const t=this.j[0],e=this.j[1],n=t[4],s=e[4],r=[],o=[];let c,i,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=c=0;!n[l];l^=i||1,c=o[c]||1){let o=c^c<<1^c<<2^c<<3^c<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[i=r[l]]];let w=16843009*f^65537*a^257*i^16843008*l,u=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=u=u<<24^u>>>8,e[n][o]=w=w<<24^w>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.I[e],s=n.length/4-2,o=[0,0,0,0],c=this.j[e],i=c[0],a=c[1],f=c[2],l=c[3],w=c[4];let u,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],S=t[e?1:3]^n[3],g=4;for(let t=0;s>t;t++)u=i[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&S]^n[g],h=i[y>>>24]^a[m>>16&255]^f[S>>8&255]^l[255&d]^n[g+1],p=i[m>>>24]^a[S>>16&255]^f[d>>8&255]^l[255&y]^n[g+2],S=i[S>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[g+3],g+=4,d=u,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=w[d>>>24]<<24^w[y>>16&255]<<16^w[m>>8&255]<<8^w[255&S]^n[g++],u=d,d=y,y=m,m=S,S=u;return o}},it=class{constructor(t,e){this.G=t,this.J=e,this.X=e}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}Z(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}$(t){0===(t[0]=this.Z(t[0]))&&(t[1]=this.Z(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=T.bitLength(e);for(let r=0;s>r;r+=4){this.$(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return T.m(e,r)}},at=E._;let ft=nt&&rt&&typeof st.importKey==k,lt=nt&&rt&&typeof st.deriveBits==k;class wt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s,checkAuthenticationCode:c=!0}){super({start(){ht(this,t,e,n)},async transform(t,e){const n=this,{password:c,strength:i,et:a,ready:f}=n;c?(await(async(t,e,n,s)=>{const o=await dt(t,e,n,mt(s,0,Z[e])),c=mt(s,Z[e]);if(o[0]!=c[0]||o[1]!=c[1])throw new r(O)})(n,i,c,mt(t,0,Z[i]+2)),t=mt(t,Z[i]+2),s?e.error(new r(N)):a()):await f;const l=new o(t.length-tt-(t.length-tt)%G);e.enqueue(pt(n,t,l,0,tt,!0))},async flush(t){const{nt:e,st:n,pending:s,ready:o}=this;if(n&&e){await o;const i=mt(s,0,s.length-tt),a=mt(s,s.length-tt);let f=z;if(i.length){const t=gt(ot,i);n.update(t);const s=e.update(t);f=St(ot,s)}const l=mt(St(ot,n.digest()),0,tt);let w=s.length<tt?1:0;for(let t=0;tt>t;t++)w|=l[t]^a[t];if(w&&c)throw new r(H);t.enqueue(f)}}})}}class ut extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){super({start(){ht(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,et:c,ready:i}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=q(new o(Z[e]));return W(s,await dt(t,e,n,s))})(n,r,s),c()):await i;const f=new o(a.length+t.length-t.length%G);f.set(a,0),e.enqueue(pt(n,t,f,a.length,0))},async flush(t){const{nt:e,st:n,pending:s,ready:r}=this;if(n&&e){await r;let o=z;if(s.length){const t=e.update(gt(ot,s));n.update(t),o=St(ot,t)}const c=St(ot,n.digest()).slice(0,tt);t.enqueue(W(o,c))}}})}}function ht(t,n,s,r){e.assign(t,{ready:new w(e=>t.et=e),password:yt(n,s),strength:r-1,pending:z})}function pt(t,e,n,s,r,c){const{nt:i,st:a,pending:f}=t;f.length&&(e=W(f,e));const l=e.length-r;let w;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%G)),w=0;l-G>=w;w+=G){const t=gt(ot,mt(e,w,w+G));c&&a.update(t);const r=i.update(t);c||a.update(r),n.set(St(ot,r),w+s)}return t.pending=mt(e,w),n}async function dt(n,s,r,c){n.password=null;const i=await(async(t,e,n,s,r)=>{if(!ft)return E.importKey(e);try{return await st.importKey("raw",e,n,!1,r)}catch{return ft=!1,E.importKey(e)}})(0,r,Q,0,Y),a=await(async(t,e,n)=>{if(!lt)return E.T(e,t.salt,X.iterations,n);try{return await st.deriveBits(t,e,n)}catch{return lt=!1,E.T(e,t.salt,X.iterations,n)}})(e.assign({salt:c},X),i,8*(2*$[s]+2)),f=new o(a),l=gt(ot,mt(f,0,$[s])),w=gt(ot,mt(f,$[s],2*$[s])),u=mt(f,2*$[s]);return e.assign(n,{keys:{key:l,ot:w,passwordVerification:u},nt:new it(new ct(l),t.from(et)),st:new at(w)}),u}function yt(t,e){return e===v?(t=>{if(typeof u==b){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new u).encode(t)})(t):e}function mt(t,e,n){return t.subarray(e,n)}function St(t,e){return t.v(e)}function gt(t,e){return t.C(e)}class vt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){kt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=zt(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e[11]^n.passwordVerification))throw new r(O);t=t.subarray(12)}s?e.error(new r(N)):e.enqueue(zt(n,t))}})}}class bt extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){kt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=q(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(Ct(n,e),0),r=12}else s=new o(t.length),r=0;s.set(Ct(n,t),r),e.enqueue(s)}})}}function kt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,ct:new R(r[0]),it:new R(r[2])}),s)for(let e=0;e<s.length;e++)At(t,s[e]);else for(let e=0;e<n.length;e++)At(t,n.charCodeAt(e))})(t,n,s)}function zt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=It(t)^e[s],At(t,n[s]);return n}function Ct(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=It(t)^e[s],At(t,e[s]);return n}function At(t,e){let[,n]=t.keys;t.ct.append([e]);const r=~t.ct.get();n=Mt(s.imul(Mt(n+xt(r)),134775813)+1),t.it.append([n>>>24]);const o=~t.it.get();t.keys=[r,n,o]}function It(t){const e=2|t.keys[2];return xt(s.imul(e,1^e)>>>8)}function xt(t){return 255&t}function Mt(t){return 4294967295&t}const Pt=new f;function Dt(t){return Pt.get(t)}const Ft="Invalid uncompressed size",Bt=j,Rt="deflate-raw",Ut="gzip",Wt=[31,139,8];class _t extends d{constructor(t,{chunkSize:e,CompressionStreamFallback:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:c,zipCrypto:i,computeCrc32:a,level:f,deflate64:w,format:u,compressionMethod:h}=t,p=this;let d,y,m,S=super.readable;const g=u&&Dt(u),v=a&&r&&!w&&!g&&(!o||i)&&!(!c||!s);if(o&&!i||!a||v||(d=new U,S=jt(S,d)),r)if(g)S=Ht(S,Lt(g.CompressionStream,u,{level:f,chunkSize:e,compressionMethod:h}));else if(v)m=new Tt,S=Ht(S,new s(Ut)),S=jt(S,m);else try{S=Ot(S,c,{level:f,chunkSize:e},s,n)}catch(t){let e;try{e=new s(Ut)}catch{throw t}S=Ht(S,e),S=jt(S,new Tt)}o&&(i?S=jt(S,new bt(t)):(y=new ut(t),S=jt(S,y))),Et(p,S,()=>{o&&!i||!a||(p.crc32=v?m.crc32:new l(d.value.buffer).getUint32(0))})}}class Tt extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const o=n.length+t.length;if(8>=o)return void(n=W(n,t));const c=o-8,i=s.min(c,n.length);r.enqueue(W(n.subarray(0,i),t.subarray(0,c-i))),n=W(n.subarray(i),t.subarray(c-i))},flush(){const e=_(n);t.crc32=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Vt extends d{constructor(t,{chunkSize:e,DecompressionStreamFallback:n,DecompressionStream:s}){super({});const{zipCrypto:c,encrypted:i,checkCrc32:a,crc32:f,compressed:u,useCompressionStream:h,deflate64:p,format:m,compressionMethod:S,rawBitFlag:g,outputSize:b}=t;let k,z,C=super.readable;if(i&&(c?C=jt(C,new vt(t)):(z=new wt(t),C=jt(C,z))),u){const t=m&&Dt(m);if(t)C=Ht(C,Lt(t.DecompressionStream,m,{chunkSize:e,compressionMethod:S,rawBitFlag:g,uncompressedSize:b}));else try{C=Ot(C,h,{chunkSize:e,deflate64:p},s,n)}catch(t){if(p||b===v)throw t;let e;try{e=new s(Ut)}catch{throw t}C=((t,e,n)=>{const s=new R;let c,i,a,f=0,l=!1;const u=new w((t,e)=>{i=t,a=e});u.catch(()=>{}),n||i();const h=new d({start(t){const e=new o(10);e.set(Wt),t.enqueue(e)},transform(t,e){e.enqueue(t)},async flush(t){l=!0,y();try{await u}finally{m()}const e=new o(8),r=_(e);r.setUint32(0,s.get(),!0),r.setUint32(4,n,!0),t.enqueue(e)},cancel(t){a(t)}}),p=new d({transform(t,e){s.append(t),f+=t.length,n>f?l&&y():i(),e.enqueue(t)},cancel(t){a(t)}});return t=jt(t,h),jt(t=Ht(t,e),p);function y(){m(),c=setTimeout(()=>a(new r(Ft)),5e3)}function m(){clearTimeout(c)}})(C,e,b)}C=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(C)}a&&(k=new U,C=jt(C,k)),Et(this,C,()=>{if(a){const t=new l(k.value.buffer);if(f!=t.getUint32(0,!1))throw new r(Bt)}})}}const Kt=new f;function Et(t,n,s){n=jt(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Lt(t,e,n){if(!t)throw new r("Compression method not supported");return new t(e,n)}function Ot(t,e,n,s,r){const o=e&&s?s:r||s,c=n.deflate64?"deflate64-raw":Rt;let i;try{i=new o(c,n)}catch(t){if(!e||!r||o==r)throw t;i=new r(c,n)}return Ht(t,i)}function jt(t,e){return(t=>{if(t instanceof y)return t;const e=t.getReader();return new y({async pull(t){const{value:n,done:s}=await e.read();s?t.close():t.enqueue(n)},cancel:t=>e.cancel(t)})})(t).pipeThrough(e)}function Ht(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const Nt="data",qt="close",Gt="deflate";class Jt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let c;o.startsWith(Gt)?c=_t:o.startsWith("inflate")&&(c=Vt),s.outputSize=0;let i=0;const a=new c(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(i+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:i})}}),w=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==v&&s.outputSize>t.outputSize))throw new r(Ft)},flush(){const{crc32:t}=a;e.assign(s,{crc32:t,inputSize:i})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(w)})}}class Qt extends d{constructor(t){const e=[];let s=0;function r(){const n=new o(t);let r=0;for(;t>r;){const s=e[0],o=t-r;s.length>o?(n.set(s.subarray(0,o),r),e[0]=s.subarray(o),r+=o):(n.set(s,r),r+=s.length,e.shift())}return s-=t,n}n.isFinite(t)&&t>=1||(t=65536),super({transform(n,o){for(e.push(n),s+=n.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(((t,e)=>{const n=new o(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n})(e,s))}})}}let Xt=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(Xt=navigator.hardwareConcurrency)}catch{}const Yt=new f,Zt=new f;let $t,te,ee,ne,se,re,oe=0;async function ce(t){let e,o;try{const{options:c,config:i}=t;if(c.format)try{await(async(t,e)=>{!Pt.has(t)&&e&&((t,e)=>{const{CompressionStream:n,DecompressionStream:s}=e;if(typeof n!=k&&typeof s!=k)throw new r("Invalid codec module");Pt.set(t,{CompressionStream:n,DecompressionStream:s})})(t,await(import(e)))})(c.format,c.codecURI)}catch(t){throw t.codecImportFailed=!0,t}if(i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream,c.compressed&&!c.format)if(c.useCompressionStream){if(!((t,e)=>{if(!t)return!1;let n=Kt.get(t);n||(n=new f,Kt.set(t,n));let s=n.get(e);if(s===v){try{new t(e),s=!0}catch{s=!1}n.set(e,s)}return s})(c.codecType.startsWith(Gt)?i.CompressionStream:i.DecompressionStream,Rt))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{c.useCompressionStream=!0}!i.CompressionStreamFallback&&i.CompressionStreamZlib&&(i.CompressionStreamFallback=i.CompressionStreamZlib),!i.DecompressionStreamFallback&&i.DecompressionStreamZlib&&(i.DecompressionStreamFallback=i.DecompressionStreamZlib);const a={highWaterMark:1},l=t.readable||new y({async pull(t){const e=new w(t=>Yt.set(oe,t));ie({type:"pull",messageId:oe}),oe=(oe+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},a);o=t.writable||new m({async write(t){let e;const s=new w(t=>e=t);Zt.set(oe,e),ie({type:Nt,value:t,messageId:oe}),oe=(oe+1)%n.MAX_SAFE_INTEGER,await s}},a),e=new Jt(c,i),$t=new AbortController;const{signal:u}=$t;await l.pipeThrough(e).pipeThrough(new Qt((t=>s.max(t.chunkSize,64))(i))).pipeTo(o,{signal:u,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{crc32:h,inputSize:p,outputSize:d}=e;ie({type:qt,result:{crc32:h,inputSize:p,outputSize:d}})}catch(t){if(t.outputSize=e?e.outputSize:0,o&&!o.locked)try{await o.getWriter().close()}catch{}ae(t)}}function ie(t){const{value:e}=t;if(e)if(e.length)try{t.value=(n=e,n.byteOffset||n.byteLength!=n.buffer.byteLength?new o(n):n).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var n}function ae(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:c,cause:i,codecImportFailed:a}=t,f={message:e,stack:n,code:s,name:o,outputSize:c};i&&(f.cause={name:i.name,message:i.message}),a&&(f.codecImportFailed=!0),p({error:f})}function fe(t,e,n={}){if(!te){const t=new r("WASM module not loaded");throw t.cause=re,t}const c="number"==typeof n.level?n.level:-1,i="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.ft=ee(i),this.in=ee(a),this.inBufferSize=a,!this.ft||!this.in)throw new r("allocation failed");if(this.lt=new o(i),t?(this.wt=te.deflate_process,this.ut=te.deflate_last_consumed,this.ht=te.deflate_end,this.yt=te.deflate_new(),n="gzip"===e?te.deflate_init_gzip(this.yt,c):"deflate-raw"===e?te.deflate_init_raw(this.yt,c):te.deflate_init(this.yt,c)):"deflate64-raw"===e?(this.wt=te.inflate9_process,this.ut=te.inflate9_last_consumed,this.ht=te.inflate9_end,this.yt=te.inflate9_new(),n=te.inflate9_init_raw(this.yt)):(this.wt=te.inflate_process,this.ut=te.inflate_last_consumed,this.ht=te.inflate_end,this.yt=te.inflate_new(),n="deflate-raw"===e?te.inflate_init_raw(this.yt):"gzip"===e?te.inflate_init_gzip(this.yt):te.inflate_init(this.yt)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const c=e,a=new o(se.buffer),f=this.wt,l=this.ut,w=this.ft,u=this.lt;let h=0;for(;h<c.length;){const e=s.min(c.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&ne&&(ne(this.in),this.in=0),this.in=ee(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(c.subarray(h,h+e),this.in);const o=f(this.yt,this.in,e,w,i,0),p=16777215&o;if(p&&(u.set(a.subarray(w,w+p),0),n.enqueue(u.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.yt);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(se.buffer),s=this.wt,c=this.ft,a=this.lt;for(;;){const o=s(this.yt,0,0,c,i,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(a.set(n.subarray(c,c+f),0),e.enqueue(a.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.yt&&t.ht&&(e=t.ht(t.yt)),t.yt=0,t.in&&ne&&ne(t.in),t.in=0,t.ft&&ne&&ne(t.ft),t.ft=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&ce(t),e==Nt){const t=Yt.get(n);Yt.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=Zt.get(n);Zt.delete(n),t()}e==qt&&$t.abort()}catch(t){ae(t)}}),p({type:"ready"});class le{constructor(t="deflate",e){return fe(!0,t,e)}}class we{constructor(t="deflate",e){return fe(!1,t,e)}}le.St=!0,we.St=!0;let ue=!1;((t={})=>{const{init:e}=t,n=t.CompressionStreamFallback||t.CompressionStreamZlib,s=t.DecompressionStreamFallback||t.DecompressionStreamZlib;self.initModule=async t=>{e&&await e(t),n&&(t.CompressionStreamFallback=n),s&&(t.DecompressionStreamFallback=s)}})({CompressionStreamFallback:le,DecompressionStreamFallback:we,init:t=>(async(t,{baseURI:e})=>{if(!ue)try{await(async(t,e)=>{let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(te=t,({malloc:ee,free:ne,memory:se}=te),"function"!=typeof ee||"function"!=typeof ne||!se)throw te=ee=ne=se=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports)})(t,e),ue=!0}catch(t){throw(t=>{re=t})(t),t}})(t.wasmURI,t)})});\n';if("string"==typeof s&&(s=(new TextEncoder).encode(s)),t){const t=new Blob([s],{type:n});return URL.createObjectURL(t)}return "data:"+n+";base64,"+(t=>{let n="";const s=t.length;let r=0;for(;s>r+2;r+=3){const s=t[r]<<16|t[r+1]<<8|t[r+2];n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+e[63&s];}const o=s-r;if(1===o){const s=t[r]<<16;n+=e[s>>18&63]+e[s>>12&63]+"==";}else if(2===o){const s=t[r]<<16|t[r+1]<<8;n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+"=";}return n})(s)}});
395
+ const t$1=new Uint8Array(288);t$1.fill(8,0,144),t$1.fill(9,144,256),t$1.fill(7,256,280),t$1.fill(8,280,288),new Uint8Array(30).fill(5);const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n$1=t=>t({workerURI:t=>{const n="text/javascript";let s='(t=>{"function"==typeof define&&define.amd?define(t):t()})(function(){"use strict";const{Array:t,Object:e,Number:n,Math:s,Error:r,Uint8Array:o,Uint16Array:c,Uint32Array:i,Int32Array:a,Map:f,DataView:l,Promise:u,TextEncoder:w,crypto:h,postMessage:p,TransformStream:d,ReadableStream:y,WritableStream:m,CompressionStream:S,DecompressionStream:g}=self,v=void 0,b="undefined",k="function",z=new o,C=[[],[],[],[],[],[],[],[]];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)e=1&e?e>>>1^3988292384:e>>>1;C[0][t]=e}for(let t=0;256>t;t++)for(let e=1;8>e;e++){const n=C[e-1][t];C[e][t]=n>>>8^C[0][255&n]}const[I,A,x,M,P,D,F,B]=C;class R{constructor(t){this.o=t||-1}append(t){let e=0|this.o;const n=0|t.length;let s=0;if(n>=8&&t.buffer){const r=new l(t.buffer,t.byteOffset,n),o=n-8;for(;o>=s;s+=8){const t=e^r.getInt32(s,!0),n=r.getInt32(s+4,!0);e=B[255&t]^F[t>>>8&255]^D[t>>>16&255]^P[t>>>24&255]^M[255&n]^x[n>>>8&255]^A[n>>>16&255]^I[n>>>24&255]}}for(;n>s;s++)e=e>>>8^I[255&(e^t[s])];this.o=e}get(){return~this.o}}class U extends d{constructor(){let t;const e=new R;super({transform(t,n){e.append(t),n.enqueue(t)},flush(){const n=new o(4);new l(n.buffer).setUint32(0,e.get()),t.value=n}}),t=this}}function W(t,e){const n=new o(t.length+e.length);return n.set(t),n.set(e,t.length),n}function _(t){return new l(t.buffer,t.byteOffset,t.byteLength)}const T={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],s=T.l(n);return 32===s?t.concat(e):T.h(e,s,0|n,t.slice(0,t.length-1))},bitLength(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+T.l(n)},m(t,e){if(32*t.length<e)return t;const n=(t=t.slice(0,s.ceil(e/32))).length;return e&=31,n>0&&e&&(t[n-1]=T.S(e,t[n-1]&2147483648>>e-1,1)),t},S:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,l:t=>s.round(t/1099511627776)||32,h(t,e,n,s){for(void 0===s&&(s=[]);e>=32;e-=32)s.push(n),n=0;if(0===e)return s.concat(t);for(let r=0;r<t.length;r++)s.push(n|t[r]>>>e),n=t[r]<<32-e;const r=t.length?t[t.length-1]:0,o=T.l(r);return s.push(T.S(e+o&31,e+o>32?n:s.pop(),1)),s}},V={bytes:{v(t){const e=T.bitLength(t)/8,n=new o(e);let s;for(let r=0;e>r;r++)3&r||(s=t[r/4]),n[r]=s>>>24,s<<=8;return n},C(t){const e=[];let n,s=0;for(n=0;n<t.length;n++)s=s<<8|t[n],3&~n||(e.push(s),s=0);return 3&n&&e.push(T.S(8*(3&n),s)),e}}},K=class{constructor(t){const e=this;e.blockSize=512,e.I=[1732584193,4023233417,2562383102,271733878,3285377520],e.A=[1518500249,1859775393,2400959708,3395469782],t?(e.M=t.M.slice(0),e.P=t.P.slice(0),e.D=t.D):e.reset()}reset(){const t=this;return t.M=t.I.slice(0),t.P=[],t.D=0,t}update(t){const e=this;"string"==typeof t&&(t=V.F.C(t));const n=e.P=T.concat(e.P,t),s=e.D,o=e.D=s+T.bitLength(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const c=new i(n);let a=0;for(let t=e.blockSize+s-(e.blockSize+s&e.blockSize-1);o>=t;t+=e.blockSize)e.B(c.subarray(16*a,16*(a+1))),a+=1;return n.splice(0,16*a),e}R(){const t=this;let e=t.P;const n=t.M;e=T.concat(e,[T.S(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(s.floor(t.D/4294967296)),e.push(0|t.D);e.length;)t.B(e.splice(0,16));return t.reset(),n}U(t,e,n,s){return t>19?t>39?t>59?t>79?void 0:e^n^s:e&n|e&s|n&s:e^n^s:e&n|~e&s}W(t,e){return e<<t|e>>>32-t}B(e){const n=this,r=n.M,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let c=r[0],i=r[1],a=r[2],f=r[3],l=r[4];for(let t=0;79>=t;t++){16>t||(o[t]=n.W(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=n.W(5,c)+n.U(t,i,a,f)+l+o[t]+n.A[s.floor(t/20)]|0;l=f,f=a,a=n.W(30,i),i=c,c=e}r[0]=r[0]+c|0,r[1]=r[1]+i|0,r[2]=r[2]+a|0,r[3]=r[3]+f|0,r[4]=r[4]+l|0}},E={importKey:t=>new E._(V.bytes.C(t)),T(t,e,n,s){if(n=n||1e4,0>s||0>n)throw new r("invalid params to pbkdf2");const o=1+(s>>5)<<2;let c,i,a,f,u;const w=new ArrayBuffer(o),h=new l(w);let p=0;const d=T;for(e=V.bytes.C(e),u=1;(o||1)>p;u++){for(c=i=t.encrypt(d.concat(e,[u])),a=1;n>a;a++)for(i=t.encrypt(i),f=0;f<i.length;f++)c[f]^=i[f];for(a=0;(o||1)>p&&a<c.length;a++)h.setInt32(p,c[a]),p+=4}return w.slice(0,s/8)},_:class{constructor(t){const e=this,n=e.V=K,s=[[],[]];e.K=[new n,new n];const r=e.K[0].blockSize/32;t.length>r&&(t=(new n).update(t).R());for(let e=0;r>e;e++)s[0][e]=909522486^t[e],s[1][e]=1549556828^t[e];e.K[0].update(s[0]),e.K[1].update(s[1]),e.L=new n(e.K[0])}reset(){const t=this;t.L=new t.V(t.K[0]),t.O=!1}update(t){this.O=!0,this.L.update(t)}digest(){const t=this,e=t.L.R(),n=new t.V(t.K[1]).update(e).R();return t.reset(),n}encrypt(t){if(this.O)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},L=typeof h!=b&&typeof h.getRandomValues==k,O="Invalid password",j="Invalid signature",H=j,N="zipjs-abort-check-password";function q(t){if(L)return h.getRandomValues(t);throw new r("Crypto API not supported")}const G=16,J={name:"PBKDF2"},Q=e.assign({hash:{name:"HMAC"}},J),X=e.assign({iterations:1e3,hash:{name:"SHA-1"}},J),Y=["deriveBits"],Z=[8,12,16],$=[16,24,32],tt=10,et=[0,0,0,0],nt=typeof h!=b,st=nt&&h.subtle,rt=nt&&typeof st!=b,ot=V.bytes,ct=class{constructor(t){const e=this;e.j=[[[],[],[],[],[]],[[],[],[],[],[]]],e.j[0][0][0]||e.H();const n=e.j[0][4],s=e.j[1],o=t.length;let c,i,a,f=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.A=[i=t.slice(0),a=[]],c=o;4*o+28>c;c++){let t=i[c-1];(c%o===0||8===o&&c%o===4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],c%o===0&&(t=t<<8^t>>>24^f<<24,f=f<<1^283*(f>>7))),i[c]=i[c-o]^t}for(let t=0;c;t++,c--){const e=i[3&t?c:c-4];a[t]=4>=c||4>t?e:s[0][n[e>>>24]]^s[1][n[e>>16&255]]^s[2][n[e>>8&255]]^s[3][n[255&e]]}}encrypt(t){return this.N(t,0)}decrypt(t){return this.N(t,1)}H(){const t=this.j[0],e=this.j[1],n=t[4],s=e[4],r=[],o=[];let c,i,a,f;for(let t=0;256>t;t++)o[(r[t]=t<<1^283*(t>>7))^t]=t;for(let l=c=0;!n[l];l^=i||1,c=o[c]||1){let o=c^c<<1^c<<2^c<<3^c<<4;o=o>>8^255&o^99,n[l]=o,s[o]=l,f=r[a=r[i=r[l]]];let u=16843009*f^65537*a^257*i^16843008*l,w=257*r[o]^16843008*o;for(let n=0;4>n;n++)t[n][l]=w=w<<24^w>>>8,e[n][o]=u=u<<24^u>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}N(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.A[e],s=n.length/4-2,o=[0,0,0,0],c=this.j[e],i=c[0],a=c[1],f=c[2],l=c[3],u=c[4];let w,h,p,d=t[0]^n[0],y=t[e?3:1]^n[1],m=t[2]^n[2],S=t[e?1:3]^n[3],g=4;for(let t=0;s>t;t++)w=i[d>>>24]^a[y>>16&255]^f[m>>8&255]^l[255&S]^n[g],h=i[y>>>24]^a[m>>16&255]^f[S>>8&255]^l[255&d]^n[g+1],p=i[m>>>24]^a[S>>16&255]^f[d>>8&255]^l[255&y]^n[g+2],S=i[S>>>24]^a[d>>16&255]^f[y>>8&255]^l[255&m]^n[g+3],g+=4,d=w,y=h,m=p;for(let t=0;4>t;t++)o[e?3&-t:t]=u[d>>>24]<<24^u[y>>16&255]<<16^u[m>>8&255]<<8^u[255&S]^n[g++],w=d,d=y,y=m,m=S,S=w;return o}},it=class{constructor(t,e){this.G=t,this.J=e,this.X=e}reset(){this.X=this.J}update(t){return this.Y(this.G,t,this.X)}Z(t){if(255&~(t>>24))t+=1<<24;else{let e=t>>16&255,n=t>>8&255,s=255&t;255===e?(e=0,255===n?(n=0,255===s?s=0:++s):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=s}return t}$(t){0===(t[0]=this.Z(t[0]))&&(t[1]=this.Z(t[1]))}Y(t,e,n){let s;if(!(s=e.length))return[];const r=T.bitLength(e);for(let r=0;s>r;r+=4){this.$(n);const s=t.encrypt(n);e[r]^=s[0],e[r+1]^=s[1],e[r+2]^=s[2],e[r+3]^=s[3]}return T.m(e,r)}},at=E._;let ft=nt&&rt&&typeof st.importKey==k,lt=nt&&rt&&typeof st.deriveBits==k;class ut extends d{constructor({password:t,rawPassword:e,encryptionStrength:n,checkPasswordOnly:s,checkAuthenticationCode:c=!0}){super({start(){ht(this,t,e,n)},async transform(t,e){const n=this,{password:c,strength:i,et:a,ready:f}=n;c?(await(async(t,e,n,s)=>{const o=await dt(t,e,n,mt(s,0,Z[e])),c=mt(s,Z[e]);if(o[0]!=c[0]||o[1]!=c[1])throw new r(O)})(n,i,c,mt(t,0,Z[i]+2)),t=mt(t,Z[i]+2),s?e.error(new r(N)):a()):await f;const l=new o(t.length-tt-(t.length-tt)%G);e.enqueue(pt(n,t,l,0,tt,!0))},async flush(t){const{nt:e,st:n,ot:s,ready:o}=this;if(n&&e){await o;const i=mt(s,0,s.length-tt),a=mt(s,s.length-tt);let f=z;if(i.length){const t=gt(ot,i);n.update(t);const s=e.update(t);f=St(ot,s)}const l=mt(St(ot,n.digest()),0,tt);let u=s.length<tt?1:0;for(let t=0;tt>t;t++)u|=l[t]^a[t];if(u&&c)throw new r(H);t.enqueue(f)}}})}}class wt extends d{constructor({password:t,rawPassword:e,encryptionStrength:n}){super({start(){ht(this,t,e,n)},async transform(t,e){const n=this,{password:s,strength:r,et:c,ready:i}=n;let a=z;s?(a=await(async(t,e,n)=>{const s=q(new o(Z[e]));return W(s,await dt(t,e,n,s))})(n,r,s),c()):await i;const f=new o(a.length+t.length-t.length%G);f.set(a,0),e.enqueue(pt(n,t,f,a.length,0))},async flush(t){const{nt:e,st:n,ot:s,ready:r}=this;if(n&&e){await r;let o=z;if(s.length){const t=e.update(gt(ot,s));n.update(t),o=St(ot,t)}const c=St(ot,n.digest()).slice(0,tt);t.enqueue(W(o,c))}}})}}function ht(t,n,s,r){e.assign(t,{ready:new u(e=>t.et=e),password:yt(n,s),strength:r-1,ot:z})}function pt(t,e,n,s,r,c){const{nt:i,st:a,ot:f}=t;f.length&&(e=W(f,e));const l=e.length-r;let u;for(n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new o(e)).set(n,0)}return t})(n,s+(l-l%G)),u=0;l-G>=u;u+=G){const t=gt(ot,mt(e,u,u+G));c&&a.update(t);const r=i.update(t);c||a.update(r),n.set(St(ot,r),u+s)}return t.ot=mt(e,u),n}async function dt(n,s,r,c){n.password=null;const i=await(async(t,e,n,s,r)=>{if(!ft)return E.importKey(e);try{return await st.importKey("raw",e,n,!1,r)}catch{return ft=!1,E.importKey(e)}})(0,r,Q,0,Y),a=await(async(t,e,n)=>{if(!lt)return E.T(e,t.salt,X.iterations,n);try{return await st.deriveBits(t,e,n)}catch{return lt=!1,E.T(e,t.salt,X.iterations,n)}})(e.assign({salt:c},X),i,8*(2*$[s]+2)),f=new o(a),l=gt(ot,mt(f,0,$[s])),u=gt(ot,mt(f,$[s],2*$[s])),w=mt(f,2*$[s]);return e.assign(n,{keys:{key:l,ct:u,passwordVerification:w},nt:new it(new ct(l),t.from(et)),st:new at(u)}),w}function yt(t,e){return e===v?(t=>{if(typeof w==b){const e=new o((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new w).encode(t)})(t):e}function mt(t,e,n){return t.subarray(e,n)}function St(t,e){return t.v(e)}function gt(t,e){return t.C(e)}class vt extends d{constructor({password:t,rawPassword:e,passwordVerification:n,checkPasswordOnly:s}){super({start(){kt(this,t,e,n)},transform(t,e){const n=this;if(n.password||n.rawPassword){const e=zt(n,t.subarray(0,12));if(n.password=n.rawPassword=null,0!=(e[11]^n.passwordVerification))throw new r(O);t=t.subarray(12)}s?e.error(new r(N)):e.enqueue(zt(n,t))}})}}class bt extends d{constructor({password:t,rawPassword:e,passwordVerification:n}){super({start(){kt(this,t,e,n)},transform(t,e){const n=this;let s,r;if(n.password||n.rawPassword){n.password=n.rawPassword=null;const e=q(new o(12));e[11]=n.passwordVerification,s=new o(t.length+e.length),s.set(Ct(n,e),0),r=12}else s=new o(t.length),r=0;s.set(Ct(n,t),r),e.enqueue(s)}})}}function kt(t,n,s,r){e.assign(t,{password:n,rawPassword:s,passwordVerification:r}),((t,n,s)=>{const r=[305419896,591751049,878082192];if(e.assign(t,{keys:r,it:new R(r[0]),ft:new R(r[2])}),s)for(let e=0;e<s.length;e++)It(t,s[e]);else for(let e=0;e<n.length;e++)It(t,n.charCodeAt(e))})(t,n,s)}function zt(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=At(t)^e[s],It(t,n[s]);return n}function Ct(t,e){const n=new o(e.length);for(let s=0;s<e.length;s++)n[s]=At(t)^e[s],It(t,e[s]);return n}function It(t,e){let[,n]=t.keys;t.it.append([e]);const r=~t.it.get();n=Mt(s.imul(Mt(n+xt(r)),134775813)+1),t.ft.append([n>>>24]);const o=~t.ft.get();t.keys=[r,n,o]}function At(t){const e=2|t.keys[2];return xt(s.imul(e,1^e)>>>8)}function xt(t){return 255&t}function Mt(t){return 4294967295&t}function Pt(t){if(t instanceof y)return t;const e=t.getReader();return new y({async pull(t){const{value:n,done:s}=await e.read();s?t.close():t.enqueue(n)},cancel:t=>e.cancel(t)})}const Dt=new f;function Ft(t){return Dt.get(t)}const Bt="Invalid uncompressed size",Rt=j,Ut="deflate-raw",Wt="gzip",_t=[31,139,8];class Tt extends d{constructor(t,{chunkSize:e,CompressionStreamFallback:n,CompressionStream:s}){super({});const{compressed:r,encrypted:o,useCompressionStream:c,zipCrypto:i,computeCrc32:a,level:f,deflate64:u,format:w,compressionMethod:h}=t,p=this;let d,y,m,S=super.readable;const g=w&&Ft(w),v=a&&r&&!u&&!g&&(!o||i)&&!(!c||!s);if(o&&!i||!a||v||(d=new U,S=Ht(S,d)),r)if(g)S=Nt(S,Ot(g.CompressionStream,w,{level:f,chunkSize:e,compressionMethod:h}));else if(v)m=new Vt,S=Nt(S,new s(Wt)),S=Ht(S,m);else try{S=jt(S,c,{level:f,chunkSize:e},s,n)}catch(t){let e;try{e=new s(Wt)}catch{throw t}S=Nt(S,e),S=Ht(S,new Vt)}o&&(i?S=Ht(S,new bt(t)):(y=new wt(t),S=Ht(S,y))),Lt(p,S,()=>{o&&!i||!a||(p.crc32=v?m.crc32:new l(d.value.buffer).getUint32(0))})}}class Vt extends d{constructor(){let t,e=10,n=new o(0);super({transform(t,r){if(e){const n=s.min(e,t.length);if(e-=n,!(t=t.subarray(n)).length)return}const o=n.length+t.length;if(8>=o)return void(n=W(n,t));const c=o-8,i=s.min(c,n.length);r.enqueue(W(n.subarray(0,i),t.subarray(0,c-i))),n=W(n.subarray(i),t.subarray(c-i))},flush(){const e=_(n);t.crc32=e.getUint32(0,!0),t.uncompressedSize=e.getUint32(4,!0)}}),t=this}}class Kt extends d{constructor(t,{chunkSize:e,DecompressionStreamFallback:n,DecompressionStream:s}){super({});const{zipCrypto:c,encrypted:i,checkCrc32:a,crc32:f,compressed:w,useCompressionStream:h,deflate64:p,format:m,compressionMethod:S,rawBitFlag:g,outputSize:b}=t;let k,z,C=super.readable;if(i&&(c?C=Ht(C,new vt(t)):(z=new ut(t),C=Ht(C,z))),w){const t=m&&Ft(m);if(t)C=Nt(C,Ot(t.DecompressionStream,m,{chunkSize:e,compressionMethod:S,rawBitFlag:g,uncompressedSize:b}));else try{C=jt(C,h,{chunkSize:e,deflate64:p},s,n)}catch(t){if(p||b===v)throw t;let e;try{e=new s(Wt)}catch{throw t}C=((t,e,n)=>{const s=new R;let c,i,a,f=0,l=!1;const w=new u((t,e)=>{i=t,a=e});w.catch(()=>{}),n||i();const h=new d({start(t){const e=new o(10);e.set(_t),t.enqueue(e)},transform(t,e){e.enqueue(t)},async flush(t){l=!0,y();try{await w}finally{m()}const e=new o(8),r=_(e);r.setUint32(0,s.get(),!0),r.setUint32(4,n,!0),t.enqueue(e)},cancel(t){a(t)}}),p=new d({transform(t,e){s.append(t),f+=t.length,n>f?l&&y():i(),e.enqueue(t)},cancel(t){a(t)}});return t=Ht(t,h),Ht(t=Nt(t,e),p);function y(){m(),c=setTimeout(()=>a(new r(Bt)),5e3)}function m(){clearTimeout(c)}})(C,e,b)}C=(t=>{const e=t.getReader();return new y({async pull(t){let n;try{n=await e.read()}catch(t){if(t&&t.message)throw t;const e=new r("Invalid compressed data");throw e.cause=t,e}const{value:s,done:o}=n;o?t.close():t.enqueue(s)},cancel:t=>e.cancel(t)})})(C)}a&&(k=new U,C=Ht(C,k)),Lt(this,C,()=>{if(a){const t=new l(k.value.buffer);if(f!=t.getUint32(0,!1))throw new r(Rt)}})}}const Et=new f;function Lt(t,n,s){n=Ht(n,new d({flush:s})),e.defineProperty(t,"readable",{get:()=>n})}function Ot(t,e,n){if(!t)throw new r("Compression method not supported");return new t(e,n)}function jt(t,e,n,s,r){const o=e&&s?s:r||s,c=n.deflate64?"deflate64-raw":Ut;let i;try{i=new o(c,n)}catch(t){if(!e||!r||o==r)throw t;i=new r(c,n)}return Nt(t,i)}function Ht(t,e){return Pt(t).pipeThrough(e)}function Nt(t,e){const n=e.writable.getWriter(),s=t.getReader();return(async()=>{try{for(;;){await n.ready;const t=await s.read();if(t.done){await n.close();break}await n.write(t.value)}}catch(t){await(async(t,e)=>{try{await t.abort(e)}catch{}})(n,t),await(async(t,e)=>{try{await t.cancel(e)}catch{}})(s,t)}})(),e.readable}const qt="data",Gt="close",Jt="deflate";class Qt extends d{constructor(t,n){super({});const s=this,{codecType:o}=t;let c;o.startsWith(Jt)?c=Tt:o.startsWith("inflate")&&(c=Kt),s.outputSize=0;let i=0;const a=new c(t,n),f=super.readable,l=new d({transform(t,e){t&&t.length&&(i+=t.length,e.enqueue(t))},flush(){e.assign(s,{inputSize:i})}}),u=new d({transform(e,n){if(e&&e.length&&(n.enqueue(e),s.outputSize+=e.length,t.outputSize!==v&&s.outputSize>t.outputSize))throw new r(Bt)},flush(){const{crc32:t}=a;e.assign(s,{crc32:t,inputSize:i})}});e.defineProperty(s,"readable",{get:()=>f.pipeThrough(l).pipeThrough(a).pipeThrough(u)})}}class Xt extends d{constructor(t){const e=[];let s=0;function r(){const n=new o(t);let r=0;for(;t>r;){const s=e[0],o=t-r;s.length>o?(n.set(s.subarray(0,o),r),e[0]=s.subarray(o),r+=o):(n.set(s,r),r+=s.length,e.shift())}return s-=t,n}n.isFinite(t)&&t>=1||(t=65536),super({transform(n,o){for(e.push(n),s+=n.length;s>t;)o.enqueue(r())},flush(t){s&&t.enqueue(((t,e)=>{const n=new o(e);let s=0;for(const e of t)n.set(e,s),s+=e.length;return n})(e,s))}})}}let Yt=2;try{typeof navigator!=b&&navigator.hardwareConcurrency&&(Yt=navigator.hardwareConcurrency)}catch{}const Zt=new f,$t=new f;let te,ee,ne,se,re,oe,ce=0;async function ie(t){let e,o;try{const{options:c,config:i}=t;if(c.format)try{await(async(t,e)=>{!Dt.has(t)&&e&&((t,e)=>{const{CompressionStream:n,DecompressionStream:s}=e;if(typeof n!=k&&typeof s!=k)throw new r("Invalid codec module");Dt.set(t,{CompressionStream:n,DecompressionStream:s})})(t,await(import(e)))})(c.format,c.codecURI)}catch(t){throw t.codecImportFailed=!0,t}if(i.CompressionStream=self.CompressionStream,i.DecompressionStream=self.DecompressionStream,c.compressed&&!c.format)if(c.useCompressionStream){if(!((t,e)=>{if(!t)return!1;let n=Et.get(t);n||(n=new f,Et.set(t,n));let s=n.get(e);if(s===v){try{new t(e),s=!0}catch{s=!1}n.set(e,s)}return s})(c.codecType.startsWith(Jt)?i.CompressionStream:i.DecompressionStream,Ut))try{await self.initModule(t.config)}catch{}}else try{await self.initModule(t.config)}catch{c.useCompressionStream=!0}!i.CompressionStreamFallback&&i.CompressionStreamZlib&&(i.CompressionStreamFallback=i.CompressionStreamZlib),!i.DecompressionStreamFallback&&i.DecompressionStreamZlib&&(i.DecompressionStreamFallback=i.DecompressionStreamZlib);const a={highWaterMark:1},l=t.readable?Pt(t.readable):new y({async pull(t){const e=new u(t=>Zt.set(ce,t));ae({type:"pull",messageId:ce}),ce=(ce+1)%n.MAX_SAFE_INTEGER;const{value:s,done:r}=await e;t.enqueue(s),r&&t.close()}},a);o=t.writable?(t=>{if(t instanceof m)return t;const e=t.getWriter();return new m({write:t=>e.write(t),close:()=>e.close(),abort:t=>e.abort(t)})})(t.writable):new m({async write(t){let e;const s=new u(t=>e=t);$t.set(ce,e),ae({type:qt,value:t,messageId:ce}),ce=(ce+1)%n.MAX_SAFE_INTEGER,await s}},a),e=new Qt(c,i),te=new AbortController;const{signal:w}=te;await l.pipeThrough(e).pipeThrough(new Xt((t=>{return r="string"==typeof(e=r=t.chunkSize)&&e.trim()?n(e):e,n.isInteger(r)&&r>=1?s.max(r,64):65536;var e,r})(i))).pipeTo(o,{signal:w,preventClose:!0,preventAbort:!0}),await o.getWriter().close();const{crc32:h,inputSize:p,outputSize:d}=e;ae({type:Gt,result:{crc32:h,inputSize:p,outputSize:d}})}catch(t){if(t.outputSize=e?e.outputSize:0,o&&!o.locked)try{await o.getWriter().close()}catch{}fe(t)}}function ae(t){const{value:e}=t;if(e)if(e.length)try{t.value=(n=e,n.byteOffset||n.byteLength!=n.buffer.byteLength?new o(n):n).buffer,p(t,[t.value])}catch{p(t)}else p(t);else p(t);var n}function fe(t=new r("Unknown error")){const{message:e,stack:n,code:s,name:o,outputSize:c,cause:i,codecImportFailed:a}=t,f={message:e,stack:n,code:s,name:o,outputSize:c};i&&(f.cause={name:i.name,message:i.message}),a&&(f.codecImportFailed=!0),p({error:f})}function le(t,e,n={}){if(!ee){const t=new r("WASM module not loaded");throw t.cause=oe,t}const c="number"==typeof n.level?n.level:-1,i="number"==typeof n.outBuffer?n.outBuffer:65536,a="number"==typeof n.inBufferSize?n.inBufferSize:65536;return new d({start(){try{let n;if(this.lt=ne(i),this.in=ne(a),this.inBufferSize=a,!this.lt||!this.in)throw new r("allocation failed");if(this.ut=new o(i),t?(this.wt=ee.deflate_process,this.ht=ee.deflate_last_consumed,this.yt=ee.deflate_end,this.St=ee.deflate_new(),n="gzip"===e?ee.deflate_init_gzip(this.St,c):"deflate-raw"===e?ee.deflate_init_raw(this.St,c):ee.deflate_init(this.St,c)):"deflate64-raw"===e?(this.wt=ee.inflate9_process,this.ht=ee.inflate9_last_consumed,this.yt=ee.inflate9_end,this.St=ee.inflate9_new(),n=ee.inflate9_init_raw(this.St)):(this.wt=ee.inflate_process,this.ht=ee.inflate_last_consumed,this.yt=ee.inflate_end,this.St=ee.inflate_new(),n="deflate-raw"===e?ee.inflate_init_raw(this.St):"gzip"===e?ee.inflate_init_gzip(this.St):ee.inflate_init(this.St)),0!==n)throw new r("init failed:"+n)}catch(t){throw f(this),t}},transform(e,n){try{const c=e,a=new o(re.buffer),f=this.wt,l=this.ht,u=this.lt,w=this.ut;let h=0;for(;h<c.length;){const e=s.min(c.length-h,32768);if((!this.in||this.inBufferSize<e)&&(this.in&&se&&(se(this.in),this.in=0),this.in=ne(e),this.inBufferSize=e,!this.in))throw new r("allocation failed");a.set(c.subarray(h,h+e),this.in);const o=f(this.St,this.in,e,u,i,0),p=16777215&o;if(p&&(w.set(a.subarray(u,u+p),0),n.enqueue(w.slice(0,p))),!t){const t=o>>24&255,e=128&t?t-256:t;if(0>e)throw new r("process error:"+e)}const d=l(this.St);if(0===d)break;h+=d}}catch(t){f(this),n.error(t)}},flush(e){try{const n=new o(re.buffer),s=this.wt,c=this.lt,a=this.ut;for(;;){const o=s(this.St,0,0,c,i,4),f=16777215&o,l=o>>24&255;if(!t){const t=128&l?l-256:l;if(0>t)throw new r("process error:"+t)}if(f&&(a.set(n.subarray(c,c+f),0),e.enqueue(a.slice(0,f))),1===l||0===f)break}}catch(t){e.error(t)}finally{const t=f(this);0!==t&&e.error(new r("end error:"+t))}},cancel(){f(this)}});function f(t){let e=0;return t.St&&t.yt&&(e=t.yt(t.St)),t.St=0,t.in&&se&&se(t.in),t.in=0,t.lt&&se&&se(t.lt),t.lt=0,e}}addEventListener("message",({data:t})=>{const{type:e,messageId:n,value:s,done:r}=t;try{if("start"==e&&ie(t),e==qt){const t=Zt.get(n);Zt.delete(n),t({value:s||new o,done:r})}if("ack"==e){const t=$t.get(n);$t.delete(n),t()}e==Gt&&te.abort()}catch(t){fe(t)}}),p({type:"ready"});class ue{constructor(t="deflate",e){return le(!0,t,e)}}class we{constructor(t="deflate",e){return le(!1,t,e)}}ue.gt=!0,we.gt=!0;let he=!1;((t={})=>{const{init:e}=t,n=t.CompressionStreamFallback||t.CompressionStreamZlib,s=t.DecompressionStreamFallback||t.DecompressionStreamZlib;self.initModule=async t=>{e&&await e(t),n&&(t.CompressionStreamFallback=n),s&&(t.DecompressionStreamFallback=s)}})({CompressionStreamFallback:ue,DecompressionStreamFallback:we,init:t=>(async(t,{baseURI:e})=>{if(!he)try{await(async(t,e)=>{let n,s;try{try{s=new URL(t,e)}catch{}const r=await fetch(s);n=await r.arrayBuffer()}catch(e){if(!t.startsWith("data:application/wasm;base64,"))throw e;n=(t=>{const e=t.split(",")[1],n=atob(e),s=n.length,r=new o(s);for(let t=0;s>t;++t)r[t]=n.charCodeAt(t);return r.buffer})(t)}(t=>{if(ee=t,({malloc:ne,free:se,memory:re}=ee),"function"!=typeof ne||"function"!=typeof se||!re)throw ee=ne=se=re=null,new r("Invalid WASM module")})((await WebAssembly.instantiate(n)).instance.exports)})(t,e),he=!0}catch(t){throw(t=>{oe=t})(t),t}})(t.wasmURI,t)})});\n';if("string"==typeof s&&(s=(new TextEncoder).encode(s)),t){const t=new Blob([s],{type:n});return URL.createObjectURL(t)}return "data:"+n+";base64,"+(t=>{let n="";const s=t.length;let r=0;for(;s>r+2;r+=3){const s=t[r]<<16|t[r+1]<<8|t[r+2];n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+e[63&s];}const o=s-r;if(1===o){const s=t[r]<<16;n+=e[s>>18&63]+e[s>>12&63]+"==";}else if(2===o){const s=t[r]<<16|t[r+1]<<8;n+=e[s>>18&63]+e[s>>12&63]+e[s>>6&63]+"=";}return n})(s)}});
247
396
 
248
397
  /*
249
398
  Copyright (c) 2026 Gildas Lormeau. All rights reserved.
@@ -1391,13 +1540,13 @@ class AESDecryptionStream extends TransformStream {
1391
1540
  const {
1392
1541
  ctr,
1393
1542
  hmac,
1394
- pending,
1543
+ pendingInput,
1395
1544
  ready
1396
1545
  } = this;
1397
1546
  if (hmac && ctr) {
1398
1547
  await ready;
1399
- const chunkToDecrypt = subarray(pending, 0, pending.length - AUTHENTICATION_CODE_LENGTH);
1400
- const originalAuthenticationCode = subarray(pending, pending.length - AUTHENTICATION_CODE_LENGTH);
1548
+ const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
1549
+ const originalAuthenticationCode = subarray(pendingInput, pendingInput.length - AUTHENTICATION_CODE_LENGTH);
1401
1550
  let decryptedChunkArray = EMPTY_UINT8_ARRAY;
1402
1551
  if (chunkToDecrypt.length) {
1403
1552
  const encryptedChunk = toBits(codecBytes, chunkToDecrypt);
@@ -1406,7 +1555,7 @@ class AESDecryptionStream extends TransformStream {
1406
1555
  decryptedChunkArray = fromBits(codecBytes, decryptedChunk);
1407
1556
  }
1408
1557
  const authenticationCode = subarray(fromBits(codecBytes, hmac.digest()), 0, AUTHENTICATION_CODE_LENGTH);
1409
- let invalidAuthenticationCode = pending.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
1558
+ let invalidAuthenticationCode = pendingInput.length < AUTHENTICATION_CODE_LENGTH ? 1 : 0;
1410
1559
  for (let indexByte = 0; indexByte < AUTHENTICATION_CODE_LENGTH; indexByte++) {
1411
1560
  invalidAuthenticationCode |= authenticationCode[indexByte] ^ originalAuthenticationCode[indexByte];
1412
1561
  }
@@ -1450,14 +1599,14 @@ class AESEncryptionStream extends TransformStream {
1450
1599
  const {
1451
1600
  ctr,
1452
1601
  hmac,
1453
- pending,
1602
+ pendingInput,
1454
1603
  ready
1455
1604
  } = this;
1456
1605
  if (hmac && ctr) {
1457
1606
  await ready;
1458
1607
  let encryptedChunkArray = EMPTY_UINT8_ARRAY;
1459
- if (pending.length) {
1460
- const encryptedChunk = ctr.update(toBits(codecBytes, pending));
1608
+ if (pendingInput.length) {
1609
+ const encryptedChunk = ctr.update(toBits(codecBytes, pendingInput));
1461
1610
  hmac.update(encryptedChunk);
1462
1611
  encryptedChunkArray = fromBits(codecBytes, encryptedChunk);
1463
1612
  }
@@ -1474,7 +1623,7 @@ function initAesCrypto(aesCrypto, password, rawPassword, encryptionStrength) {
1474
1623
  ready: new Promise(resolve => aesCrypto.resolveReady = resolve),
1475
1624
  password: encodePassword(password, rawPassword),
1476
1625
  strength: encryptionStrength - 1,
1477
- pending: EMPTY_UINT8_ARRAY
1626
+ pendingInput: EMPTY_UINT8_ARRAY
1478
1627
  });
1479
1628
  }
1480
1629
 
@@ -1482,10 +1631,10 @@ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifyAuthen
1482
1631
  const {
1483
1632
  ctr,
1484
1633
  hmac,
1485
- pending
1634
+ pendingInput
1486
1635
  } = aesCrypto;
1487
- if (pending.length) {
1488
- input = concat(pending, input);
1636
+ if (pendingInput.length) {
1637
+ input = concat(pendingInput, input);
1489
1638
  }
1490
1639
  const inputLength = input.length - paddingEnd;
1491
1640
  output = expand(output, paddingStart + (inputLength - (inputLength % BLOCK_LENGTH)));
@@ -1501,7 +1650,7 @@ function append(aesCrypto, input, output, paddingStart, paddingEnd, verifyAuthen
1501
1650
  }
1502
1651
  output.set(fromBits(codecBytes, outputChunk), offset + paddingStart);
1503
1652
  }
1504
- aesCrypto.pending = subarray(input, offset);
1653
+ aesCrypto.pendingInput = subarray(input, offset);
1505
1654
  return output;
1506
1655
  }
1507
1656
 
@@ -2756,6 +2905,7 @@ function createWebWorkerInterface(workerData, config) {
2756
2905
  worker,
2757
2906
  workerAlive: false,
2758
2907
  terminated: false,
2908
+ startupError: null,
2759
2909
  interface: {
2760
2910
  run: async () => {
2761
2911
  try {
@@ -2783,6 +2933,13 @@ function createWebWorkerInterface(workerData, config) {
2783
2933
  }
2784
2934
 
2785
2935
  async function runWebWorker(workerData, config) {
2936
+ if (!workerData.worker) {
2937
+ const { startupError } = workerData;
2938
+ workerData.startupError = null;
2939
+ const error = startupError || new Error(ERR_WORKER_STARTUP_TIMEOUT);
2940
+ error.workerStartupFailed = true;
2941
+ throw error;
2942
+ }
2786
2943
  let resolveResult, rejectResult;
2787
2944
  const result = new Promise((resolve, reject) => {
2788
2945
  resolveResult = resolve;
@@ -2996,11 +3153,12 @@ function onWorkerError(event, workerData) {
2996
3153
  if (!workerAlive) {
2997
3154
  workerData.worker = null;
2998
3155
  }
3156
+ let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
3157
+ if (!workerAlive) {
3158
+ error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
3159
+ workerData.startupError = error;
3160
+ }
2999
3161
  if (rejectResult) {
3000
- let error = event.error || new Error(event.message || ERROR_EVENT_TYPE);
3001
- if (!workerAlive) {
3002
- error = Object.assign(new Error(error.message || ERROR_EVENT_TYPE), { workerStartupFailed: true });
3003
- }
3004
3162
  rejectResult(error);
3005
3163
  if (writer) {
3006
3164
  writer.releaseLock();
@@ -3269,6 +3427,96 @@ async function terminateWorkers() {
3269
3427
  resetWebWorkerSupport();
3270
3428
  }
3271
3429
 
3430
+ /*
3431
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3432
+
3433
+ Redistribution and use in source and binary forms, with or without
3434
+ modification, are permitted provided that the following conditions are met:
3435
+
3436
+ 1. Redistributions of source code must retain the above copyright notice,
3437
+ this list of conditions and the following disclaimer.
3438
+
3439
+ 2. Redistributions in binary form must reproduce the above copyright
3440
+ notice, this list of conditions and the following disclaimer in
3441
+ the documentation and/or other materials provided with the distribution.
3442
+
3443
+ 3. The names of the authors may not be used to endorse or promote products
3444
+ derived from this software without specific prior written permission.
3445
+
3446
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3447
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3448
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3449
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3450
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3451
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3452
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3453
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3454
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3455
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3456
+ */
3457
+
3458
+ /* global TextDecoder */
3459
+
3460
+ const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
3461
+ const VALID_CP437 = CP437.length == 256;
3462
+
3463
+ function decodeCP437(stringValue) {
3464
+ if (VALID_CP437) {
3465
+ let result = "";
3466
+ for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
3467
+ result += CP437[stringValue[indexCharacter]];
3468
+ }
3469
+ return result;
3470
+ } else {
3471
+ return new TextDecoder().decode(stringValue);
3472
+ }
3473
+ }
3474
+
3475
+ /*
3476
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3477
+
3478
+ Redistribution and use in source and binary forms, with or without
3479
+ modification, are permitted provided that the following conditions are met:
3480
+
3481
+ 1. Redistributions of source code must retain the above copyright notice,
3482
+ this list of conditions and the following disclaimer.
3483
+
3484
+ 2. Redistributions in binary form must reproduce the above copyright
3485
+ notice, this list of conditions and the following disclaimer in
3486
+ the documentation and/or other materials provided with the distribution.
3487
+
3488
+ 3. The names of the authors may not be used to endorse or promote products
3489
+ derived from this software without specific prior written permission.
3490
+
3491
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
3492
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
3493
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
3494
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
3495
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3496
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
3497
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3498
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3499
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
3500
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3501
+ */
3502
+
3503
+
3504
+ function decodeText(value, encoding) {
3505
+ return decode(value, encoding, true);
3506
+ }
3507
+
3508
+ function decodeTextRemovingBOM(value, encoding) {
3509
+ return decode(value, encoding, false);
3510
+ }
3511
+
3512
+ function decode(value, encoding, ignoreBOM) {
3513
+ if (encoding && encoding.trim().toLowerCase() == "cp437") {
3514
+ return decodeCP437(value);
3515
+ } else {
3516
+ return new TextDecoder(encoding, { ignoreBOM }).decode(value);
3517
+ }
3518
+ }
3519
+
3272
3520
  /*
3273
3521
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
3274
3522
 
@@ -3341,6 +3589,7 @@ class Reader extends Stream {
3341
3589
  createReadable({ offset = 0, size, chunkSize = getChunkSize(getConfiguration()) } = {}) {
3342
3590
  const reader = this;
3343
3591
  let chunkOffset = 0;
3592
+ chunkSize = normalizeChunkSize(chunkSize);
3344
3593
  return new ReadableStream({
3345
3594
  async pull(controller) {
3346
3595
  const dataSize = size === UNDEFINED_VALUE ? chunkSize : Math.min(chunkSize, size - chunkOffset);
@@ -3348,7 +3597,7 @@ class Reader extends Stream {
3348
3597
  if (data.length) {
3349
3598
  controller.enqueue(data);
3350
3599
  }
3351
- if ((chunkOffset + chunkSize >= size) || (size === UNDEFINED_VALUE && !data.length && dataSize)) {
3600
+ if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3352
3601
  controller.close();
3353
3602
  } else {
3354
3603
  chunkOffset += chunkSize;
@@ -3428,31 +3677,31 @@ class Data64URIWriter extends Writer {
3428
3677
  Object.assign(this, {
3429
3678
  contentType,
3430
3679
  data: "data:" + (contentType || "") + ";base64,",
3431
- pending: []
3680
+ pendingCharacters: ""
3432
3681
  });
3433
3682
  }
3434
3683
 
3435
3684
  writeUint8Array(array) {
3436
3685
  const writer = this;
3437
3686
  let indexArray;
3438
- let dataString = writer.pending;
3439
- const delta = writer.pending.length;
3440
- writer.pending = "";
3687
+ let dataString = writer.pendingCharacters;
3688
+ const delta = writer.pendingCharacters.length;
3689
+ writer.pendingCharacters = "";
3441
3690
  for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
3442
3691
  dataString += String.fromCharCode(array[indexArray]);
3443
3692
  }
3444
3693
  for (; indexArray < array.length; indexArray++) {
3445
- writer.pending += String.fromCharCode(array[indexArray]);
3694
+ writer.pendingCharacters += String.fromCharCode(array[indexArray]);
3446
3695
  }
3447
3696
  if (dataString.length > 2) {
3448
3697
  writer.data += btoa(dataString);
3449
3698
  } else {
3450
- writer.pending = dataString + writer.pending;
3699
+ writer.pendingCharacters = dataString + writer.pendingCharacters;
3451
3700
  }
3452
3701
  }
3453
3702
 
3454
3703
  getData() {
3455
- return this.data + btoa(this.pending);
3704
+ return this.data + btoa(this.pendingCharacters);
3456
3705
  }
3457
3706
  }
3458
3707
 
@@ -3482,7 +3731,7 @@ class BlobReader extends Reader {
3482
3731
  constructor(blob) {
3483
3732
  super();
3484
3733
  Object.assign(this, {
3485
- blob,
3734
+ sourceBlob: blob,
3486
3735
  size: blob.size
3487
3736
  });
3488
3737
  if (!blobSliceProbe) {
@@ -3492,13 +3741,13 @@ class BlobReader extends Reader {
3492
3741
 
3493
3742
  createReadable(options) {
3494
3743
  const reader = this;
3495
- const { blob, size } = reader;
3744
+ const { sourceBlob, size } = reader;
3496
3745
  const { offset = 0, size: readSize = size - offset } = options || {};
3497
3746
  if (!offset && readSize >= size) {
3498
- return toCompatibleReadable(blob.stream());
3747
+ return toCompatibleReadable(sourceBlob.stream());
3499
3748
  }
3500
3749
  if (blobSliceReliable) {
3501
- return toCompatibleReadable(blob.slice(offset, offset + readSize).stream());
3750
+ return toCompatibleReadable(sourceBlob.slice(offset, offset + readSize).stream());
3502
3751
  }
3503
3752
  return super.createReadable(options);
3504
3753
  }
@@ -3507,7 +3756,7 @@ class BlobReader extends Reader {
3507
3756
  const reader = this;
3508
3757
  const offsetEnd = offset + length;
3509
3758
  const readsWholeBlob = !offset && offsetEnd >= reader.size;
3510
- const blob = readsWholeBlob ? reader.blob : reader.blob.slice(offset, offsetEnd);
3759
+ const blob = readsWholeBlob ? reader.sourceBlob : reader.sourceBlob.slice(offset, offsetEnd);
3511
3760
  let arrayBuffer = await blob.arrayBuffer();
3512
3761
  const sliceIgnoredByBuggyImplementation = arrayBuffer.byteLength > length;
3513
3762
  if (sliceIgnoredByBuggyImplementation) {
@@ -3529,12 +3778,12 @@ class BlobWriter extends Stream {
3529
3778
  }
3530
3779
  });
3531
3780
  writer.contentType = contentType;
3532
- writer.blob = streamToBlob(transformStream.readable, contentType);
3533
- writer.blob.catch(() => { });
3781
+ writer.blobPromise = streamToBlob(transformStream.readable, contentType);
3782
+ writer.blobPromise.catch(() => { });
3534
3783
  }
3535
3784
 
3536
3785
  getData() {
3537
- return this.blob;
3786
+ return this.blobPromise;
3538
3787
  }
3539
3788
  }
3540
3789
 
@@ -3568,7 +3817,7 @@ function getTextSize(text) {
3568
3817
  class TextWriter extends BlobWriter {
3569
3818
 
3570
3819
  constructor(encoding) {
3571
- super(encoding);
3820
+ super();
3572
3821
  Object.assign(this, {
3573
3822
  encoding,
3574
3823
  utf8: !encoding || encoding.toLowerCase() == "utf-8"
@@ -3584,14 +3833,7 @@ class TextWriter extends BlobWriter {
3584
3833
  if (blob.text && utf8) {
3585
3834
  return blob.text();
3586
3835
  } else {
3587
- const reader = new FileReader();
3588
- return new Promise((resolve, reject) => {
3589
- Object.assign(reader, {
3590
- onload: ({ target }) => resolve(target.result),
3591
- onerror: () => reject(reader.error)
3592
- });
3593
- reader.readAsText(blob, encoding);
3594
- });
3836
+ return decodeTextRemovingBOM(new Uint8Array(await blob.arrayBuffer()), encoding);
3595
3837
  }
3596
3838
  }
3597
3839
  }
@@ -4049,9 +4291,8 @@ class SplitDataReader extends Reader {
4049
4291
 
4050
4292
  async init() {
4051
4293
  const reader = this;
4052
- const { readers } = reader;
4053
4294
  reader.lastDiskNumber = 0;
4054
- await Promise.all(readers.map(diskReader => initStream(diskReader)));
4295
+ const readers = reader.readers = await Promise.all(reader.readers.map(initDiskReader));
4055
4296
  reader.diskOffsets = readers.map(diskReader => {
4056
4297
  const diskOffset = reader.size;
4057
4298
  reader.size += diskReader.size;
@@ -4246,89 +4487,27 @@ async function initStream(stream, initSize) {
4246
4487
  }
4247
4488
  }
4248
4489
 
4249
- function readUint8Array(reader, offset, size) {
4250
- return reader.readUint8Array(offset, size);
4251
- }
4252
-
4253
- /*
4254
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4255
-
4256
- Redistribution and use in source and binary forms, with or without
4257
- modification, are permitted provided that the following conditions are met:
4258
-
4259
- 1. Redistributions of source code must retain the above copyright notice,
4260
- this list of conditions and the following disclaimer.
4261
-
4262
- 2. Redistributions in binary form must reproduce the above copyright
4263
- notice, this list of conditions and the following disclaimer in
4264
- the documentation and/or other materials provided with the distribution.
4265
-
4266
- 3. The names of the authors may not be used to endorse or promote products
4267
- derived from this software without specific prior written permission.
4268
-
4269
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4270
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4271
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4272
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4273
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4274
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4275
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4276
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4277
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4278
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4279
- */
4280
-
4281
- /* global TextDecoder */
4282
-
4283
- const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
4284
- const VALID_CP437 = CP437.length == 256;
4285
-
4286
- function decodeCP437(stringValue) {
4287
- if (VALID_CP437) {
4288
- let result = "";
4289
- for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
4290
- result += CP437[stringValue[indexCharacter]];
4291
- }
4292
- return result;
4293
- } else {
4294
- return new TextDecoder().decode(stringValue);
4490
+ async function initDiskReader(diskReader) {
4491
+ diskReader = new GenericReader(diskReader);
4492
+ await initStream(diskReader);
4493
+ if (diskReader.size === UNDEFINED_VALUE || !diskReader.readUint8Array) {
4494
+ diskReader = new BlobReader(await streamToBlob(diskReader.readable));
4495
+ await initStream(diskReader);
4295
4496
  }
4497
+ return diskReader;
4296
4498
  }
4297
4499
 
4298
- /*
4299
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4300
-
4301
- Redistribution and use in source and binary forms, with or without
4302
- modification, are permitted provided that the following conditions are met:
4303
-
4304
- 1. Redistributions of source code must retain the above copyright notice,
4305
- this list of conditions and the following disclaimer.
4306
-
4307
- 2. Redistributions in binary form must reproduce the above copyright
4308
- notice, this list of conditions and the following disclaimer in
4309
- the documentation and/or other materials provided with the distribution.
4310
-
4311
- 3. The names of the authors may not be used to endorse or promote products
4312
- derived from this software without specific prior written permission.
4313
-
4314
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4315
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4316
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4317
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4318
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4319
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4320
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4321
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4322
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4323
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4324
- */
4325
-
4500
+ function readUint8Array(reader, offset, size) {
4501
+ return reader.readUint8Array(offset, size);
4502
+ }
4326
4503
 
4327
- function decodeText(value, encoding) {
4328
- if (encoding && encoding.trim().toLowerCase() == "cp437") {
4329
- return decodeCP437(value);
4504
+ function createReadable(reader, options) {
4505
+ if (reader.createReadable) {
4506
+ return reader.createReadable(options);
4507
+ } else if (reader.readUint8Array) {
4508
+ return Reader.prototype.createReadable.call(reader, options);
4330
4509
  } else {
4331
- return new TextDecoder(encoding, { ignoreBOM: true }).decode(value);
4510
+ return reader.readable;
4332
4511
  }
4333
4512
  }
4334
4513
 
@@ -4404,6 +4583,10 @@ const PROPERTY_NAME_SETUID = "setuid";
4404
4583
  const PROPERTY_NAME_SETGID = "setgid";
4405
4584
  const PROPERTY_NAME_STICKY = "sticky";
4406
4585
  const PROPERTY_NAME_BITFLAG = "bitFlag";
4586
+ const PROPERTY_NAME_RAW_BITFLAG = "rawBitFlag";
4587
+ const PROPERTY_NAME_FILENAME_LENGTH = "filenameLength";
4588
+ const PROPERTY_NAME_EXTRA_FIELD_LENGTH = "extraFieldLength";
4589
+ const PROPERTY_NAME_UNIX_EXTERNAL_UPPER = "unixExternalUpper";
4407
4590
  const PROPERTY_NAME_FILENAME_UTF8 = "filenameUTF8";
4408
4591
  const PROPERTY_NAME_COMMENT_UTF8 = "commentUTF8";
4409
4592
  const PROPERTY_NAME_RAW_EXTRA_FIELD = "rawExtraField";
@@ -4456,10 +4639,14 @@ const PROPERTY_NAMES = [
4456
4639
  PROPERTY_NAME_UID,
4457
4640
  PROPERTY_NAME_GID,
4458
4641
  PROPERTY_NAME_UNIX_MODE,
4642
+ PROPERTY_NAME_UNIX_EXTERNAL_UPPER,
4459
4643
  PROPERTY_NAME_SETUID,
4460
4644
  PROPERTY_NAME_SETGID,
4461
4645
  PROPERTY_NAME_STICKY,
4462
4646
  PROPERTY_NAME_BITFLAG,
4647
+ PROPERTY_NAME_RAW_BITFLAG,
4648
+ PROPERTY_NAME_FILENAME_LENGTH,
4649
+ PROPERTY_NAME_EXTRA_FIELD_LENGTH,
4463
4650
  PROPERTY_NAME_FILENAME_UTF8,
4464
4651
  PROPERTY_NAME_COMMENT_UTF8,
4465
4652
  PROPERTY_NAME_RAW_EXTRA_FIELD,
@@ -4480,82 +4667,6 @@ class Entry {
4480
4667
 
4481
4668
  }
4482
4669
 
4483
- /*
4484
- Copyright (c) 2022 Gildas Lormeau. All rights reserved.
4485
-
4486
- Redistribution and use in source and binary forms, with or without
4487
- modification, are permitted provided that the following conditions are met:
4488
-
4489
- 1. Redistributions of source code must retain the above copyright notice,
4490
- this list of conditions and the following disclaimer.
4491
-
4492
- 2. Redistributions in binary form must reproduce the above copyright
4493
- notice, this list of conditions and the following disclaimer in
4494
- the documentation and/or other materials provided with the distribution.
4495
-
4496
- 3. The names of the authors may not be used to endorse or promote products
4497
- derived from this software without specific prior written permission.
4498
-
4499
- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
4500
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
4501
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
4502
- INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
4503
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4504
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
4505
- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4506
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4507
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
4508
- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4509
- */
4510
-
4511
- const OPTION_FILENAME_ENCODING = "filenameEncoding";
4512
- const OPTION_COMMENT_ENCODING = "commentEncoding";
4513
- const OPTION_DECODE_TEXT = "decodeText";
4514
- const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
4515
- const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
4516
- const OPTION_PASSWORD = "password";
4517
- const OPTION_RAW_PASSWORD = "rawPassword";
4518
- const OPTION_PASS_THROUGH = "passThrough";
4519
- const OPTION_SIGNAL = "signal";
4520
- const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
4521
- const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
4522
- const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
4523
- const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
4524
- const OPTION_CHECK_SIGNATURE = "checkSignature";
4525
- const OPTION_CHECK_CRC32 = "checkCrc32";
4526
- const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
4527
- const OPTION_USE_WEB_WORKERS = "useWebWorkers";
4528
- const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
4529
- const OPTION_TRANSFER_STREAMS = "transferStreams";
4530
- const OPTION_PREVENT_CLOSE = "preventClose";
4531
- const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
4532
- const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
4533
- const OPTION_NTFS_TIMESTAMP = "ntfsTimestamp";
4534
- const OPTION_KEEP_ORDER = "keepOrder";
4535
- const OPTION_LEVEL = "level";
4536
- const OPTION_BUFFERED_WRITE = "bufferedWrite";
4537
- const OPTION_CREATE_TEMP_STREAM = "createTempStream";
4538
- const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
4539
- const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
4540
- const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
4541
- const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
4542
- const OPTION_ENCODE_TEXT = "encodeText";
4543
- const OPTION_OFFSET = "offset";
4544
- const OPTION_USDZ = "usdz";
4545
- const OPTION_UNIX_EXTRA_FIELD_TYPE = "unixExtraFieldType";
4546
- const OPTION_LOCAL_EXTRA_FIELD = "localExtraField";
4547
- const OPTION_STRICTNESS = "strictness";
4548
- const OPTION_FILENAME_VALIDATION = "filenameValidation";
4549
- const OPTION_NORMALIZE_FILENAME = "normalizeFilename";
4550
- const OPTION_MAX_APPENDED_DATA_SIZE = "maxAppendedDataSize";
4551
- const OPTION_DECRYPT_CENTRAL_DIRECTORY = "decryptCentralDirectory";
4552
- const OPTION_SIGN_CENTRAL_DIRECTORY = "signCentralDirectory";
4553
- const TEXT_TYPE_FILENAME = "filename";
4554
- const TEXT_TYPE_COMMENT = "comment";
4555
- const STRICTNESS_STRICT = "strict";
4556
- const STRICTNESS_BALANCED = "balanced";
4557
- const STRICTNESS_TOLERANT = "tolerant";
4558
-
4559
4670
  /*
4560
4671
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
4561
4672
 
@@ -4596,6 +4707,7 @@ const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
4596
4707
  const ERR_UNSUPPORTED_COMPRESSION$1 = "Compression method not supported";
4597
4708
  const ERR_SPLIT_ZIP_FILE = "Split zip file";
4598
4709
  const ERR_OVERLAPPING_ENTRY = "Overlapping entry found";
4710
+ const ERR_ENTRY_DATA_OUT_OF_BOUNDS = "Entry data out of bounds";
4599
4711
  const ERR_AMBIGUOUS_ARCHIVE = "Ambiguous archive";
4600
4712
  const ERR_ENCRYPTED_CENTRAL_DIRECTORY = "Encrypted central directory is not supported";
4601
4713
  const ERR_UNSAFE_FILENAME = "Unsafe filename";
@@ -4616,7 +4728,7 @@ const ZIP64_PROPERTIES = [
4616
4728
  ];
4617
4729
  const ZIP64_EXTRACTION = {
4618
4730
  [MAX_16_BITS]: {
4619
- getValue: getUint32,
4731
+ getValue: getUint32$1,
4620
4732
  bytes: 4
4621
4733
  },
4622
4734
  [MAX_32_BITS]: {
@@ -4625,6 +4737,7 @@ const ZIP64_EXTRACTION = {
4625
4737
  }
4626
4738
  };
4627
4739
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4740
+ const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4628
4741
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
4629
4742
  const CENTRAL_DIRECTORY_PLAUSIBLE = 1;
4630
4743
  const CENTRAL_DIRECTORY_REACHABLE = 2;
@@ -4635,7 +4748,6 @@ class ZipReader {
4635
4748
  Object.assign(this, {
4636
4749
  reader: new GenericReader(reader),
4637
4750
  options,
4638
- config: getConfiguration(),
4639
4751
  readRanges: new Map()
4640
4752
  });
4641
4753
  }
@@ -4643,7 +4755,6 @@ class ZipReader {
4643
4755
  async* getEntriesGenerator(options = {}) {
4644
4756
  const zipReader = this;
4645
4757
  let { reader } = zipReader;
4646
- const { config } = zipReader;
4647
4758
  await initStream(reader);
4648
4759
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
4649
4760
  reader = new BlobReader(await streamToBlob(reader.readable));
@@ -4652,7 +4763,7 @@ class ZipReader {
4652
4763
  if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
4653
4764
  throw new Error(ERR_BAD_FORMAT);
4654
4765
  }
4655
- const strictness = getStrictness(getOptionValue$1(zipReader, options, OPTION_STRICTNESS), getOptionValue$1(zipReader, options, OPTION_CHECK_AMBIGUITY));
4766
+ const strictness = getStrictness(options, zipReader.options);
4656
4767
  const checkAmbiguity = strictness == STRICTNESS_STRICT;
4657
4768
  const rejectAmbiguousEndOfDirectory = strictness != STRICTNESS_TOLERANT;
4658
4769
  const maxAppendedDataSize = getMaxAppendedDataSize(getOptionValue$1(zipReader, options, OPTION_MAX_APPENDED_DATA_SIZE), strictness);
@@ -4660,9 +4771,7 @@ class ZipReader {
4660
4771
  const normalizeFilename = getOptionValue$1(zipReader, options, OPTION_NORMALIZE_FILENAME);
4661
4772
  const { endOfDirectoryInfo, endOfDirectoryReachingEndCount } = await findEndOfCentralDirectory(reader, rejectAmbiguousEndOfDirectory, maxAppendedDataSize);
4662
4773
  if (!endOfDirectoryInfo) {
4663
- const signatureArray = await readUint8Array(reader, 0, 4);
4664
- const signatureView = getDataView(signatureArray);
4665
- if (getUint32(signatureView) == SPLIT_ZIP_FILE_SIGNATURE) {
4774
+ if (await startsWithSplitZipSignature$1(reader)) {
4666
4775
  throw new Error(ERR_SPLIT_ZIP_FILE);
4667
4776
  } else {
4668
4777
  throw new Error(ERR_EOCDR_NOT_FOUND);
@@ -4672,18 +4781,18 @@ class ZipReader {
4672
4781
  throwAmbiguousArchive("multiple end of central directory records");
4673
4782
  }
4674
4783
  const endOfDirectoryView = getDataView(endOfDirectoryInfo);
4675
- let directoryDataLength = getUint32(endOfDirectoryView, 12);
4676
- let directoryDataOffset = getUint32(endOfDirectoryView, 16);
4784
+ let directoryDataLength = getUint32$1(endOfDirectoryView, 12);
4785
+ let directoryDataOffset = getUint32$1(endOfDirectoryView, 16);
4677
4786
  const commentOffset = endOfDirectoryInfo.offset;
4678
- const commentLength = getUint16(endOfDirectoryView, 20);
4787
+ const commentLength = getUint16$1(endOfDirectoryView, 20);
4679
4788
  const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
4680
4789
  if (reader.size - appendedDataOffset > maxAppendedDataSize) {
4681
4790
  throwAmbiguousArchive("appended data");
4682
4791
  }
4683
- let lastDiskNumber = getUint16(endOfDirectoryView, 4);
4792
+ let lastDiskNumber = getUint16$1(endOfDirectoryView, 4);
4684
4793
  const expectedLastDiskNumber = reader.lastDiskNumber || 0;
4685
- let diskNumber = getUint16(endOfDirectoryView, 6);
4686
- let filesLength = getUint16(endOfDirectoryView, 10);
4794
+ let diskNumber = getUint16$1(endOfDirectoryView, 6);
4795
+ let filesLength = getUint16$1(endOfDirectoryView, 10);
4687
4796
  let prependedDataLength = 0;
4688
4797
  let startOffset;
4689
4798
  let zip64EndOfDirectory;
@@ -4699,12 +4808,12 @@ class ZipReader {
4699
4808
  EMPTY_UINT8_ARRAY;
4700
4809
  const endOfDirectoryLocatorView = getDataView(endOfDirectoryLocatorArray);
4701
4810
  if (endOfDirectoryLocatorArray.length == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH &&
4702
- getUint32(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4703
- directoryDataOffset = getDiskOffset$1(reader, getUint32(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
4811
+ getUint32$1(endOfDirectoryLocatorView, 0) == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
4812
+ directoryDataOffset = getDiskOffset$1(reader, getUint32$1(endOfDirectoryLocatorView, 4)) + getBigUint64(endOfDirectoryLocatorView, 8);
4704
4813
  let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4705
4814
  let endOfDirectoryView = getDataView(endOfDirectoryArray);
4706
4815
  const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4707
- if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
4816
+ if ((endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) &&
4708
4817
  directoryDataOffset != expectedDirectoryDataOffset && expectedDirectoryDataOffset >= 0) {
4709
4818
  const originalDirectoryDataOffset = directoryDataOffset;
4710
4819
  directoryDataOffset = expectedDirectoryDataOffset;
@@ -4714,7 +4823,7 @@ class ZipReader {
4714
4823
  endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4715
4824
  endOfDirectoryView = getDataView(endOfDirectoryArray);
4716
4825
  }
4717
- if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
4826
+ if (endOfDirectoryArray.length < ZIP64_END_OF_CENTRAL_DIR_LENGTH || getUint32$1(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
4718
4827
  throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
4719
4828
  }
4720
4829
  zip64EndOfDirectory = true;
@@ -4729,13 +4838,13 @@ class ZipReader {
4729
4838
  }
4730
4839
  }
4731
4840
  if (lastDiskNumber == MAX_16_BITS) {
4732
- lastDiskNumber = getUint32(endOfDirectoryView, 16);
4733
- } else if (checkAmbiguity && lastDiskNumber != getUint32(endOfDirectoryView, 16)) {
4841
+ lastDiskNumber = getUint32$1(endOfDirectoryView, 16);
4842
+ } else if (checkAmbiguity && lastDiskNumber != getUint32$1(endOfDirectoryView, 16)) {
4734
4843
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4735
4844
  }
4736
4845
  if (diskNumber == MAX_16_BITS) {
4737
- diskNumber = getUint32(endOfDirectoryView, 20);
4738
- } else if (checkAmbiguity && diskNumber != getUint32(endOfDirectoryView, 20)) {
4846
+ diskNumber = getUint32$1(endOfDirectoryView, 20);
4847
+ } else if (checkAmbiguity && diskNumber != getUint32$1(endOfDirectoryView, 20)) {
4739
4848
  throwAmbiguousArchive("mismatched zip64 end of central directory record");
4740
4849
  }
4741
4850
  if (filesLength == MAX_16_BITS) {
@@ -4773,11 +4882,11 @@ class ZipReader {
4773
4882
  }
4774
4883
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4775
4884
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4776
- const storedPointsAtDirectory = getUint32(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4885
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4777
4886
  let reconcile = !storedPointsAtDirectory;
4778
4887
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4779
4888
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
4780
- reconcile = getUint32(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4889
+ reconcile = getUint32$1(getDataView(expectedSignatureArray), 0) == CENTRAL_FILE_HEADER_SIGNATURE;
4781
4890
  }
4782
4891
  if (reconcile) {
4783
4892
  const originalDirectoryDataOffset = directoryDataOffset;
@@ -4801,10 +4910,10 @@ class ZipReader {
4801
4910
  }
4802
4911
  zipReader.directoryOffset = directoryDataOffset;
4803
4912
  zipReader.directoryLength = declaredDirectoryDataLength;
4804
- const decryptCentralDirectory = getOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4913
+ const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4805
4914
  let decryptedDirectory;
4806
4915
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4807
- getUint32(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4916
+ getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4808
4917
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4809
4918
  directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4810
4919
  directoryView = getDataView(directoryArray);
@@ -4817,8 +4926,8 @@ class ZipReader {
4817
4926
  const filenames = checkAmbiguity ? new Set() : UNDEFINED_VALUE;
4818
4927
  let duplicateFilename;
4819
4928
  for (let indexFile = 0; indexFile < filesLength; indexFile++) {
4820
- const fileEntry = new ZipEntry$1(reader, config, zipReader.options);
4821
- if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4929
+ const fileEntry = new ZipEntry$1(reader, zipReader.options);
4930
+ if (offset + CENTRAL_FILE_HEADER_LENGTH > directoryArray.length || getUint32$1(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
4822
4931
  if (indexFile == 0 && !decryptedDirectory && (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4823
4932
  throw new Error(ERR_ENCRYPTED_CENTRAL_DIRECTORY);
4824
4933
  }
@@ -4829,16 +4938,16 @@ class ZipReader {
4829
4938
  const filenameOffset = offset + CENTRAL_FILE_HEADER_LENGTH;
4830
4939
  const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
4831
4940
  const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
4832
- const versionMadeBy = getUint16(directoryView, offset + 4);
4941
+ const versionMadeBy = getUint16$1(directoryView, offset + 4);
4833
4942
  const msDosCompatible = versionMadeBy >> 8 == 0;
4834
4943
  const unixCompatible = versionMadeBy >> 8 == 3;
4835
4944
  const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
4836
- const commentLength = getUint16(directoryView, offset + 32);
4945
+ const commentLength = getUint16$1(directoryView, offset + 32);
4837
4946
  const endOffset = commentOffset + commentLength;
4838
4947
  const rawComment = directoryArray.subarray(commentOffset, endOffset);
4839
4948
  const filenameUTF8 = languageEncodingFlag;
4840
4949
  const commentUTF8 = languageEncodingFlag;
4841
- const externalFileAttributes = getUint32(directoryView, offset + 38);
4950
+ const externalFileAttributes = getUint32$1(directoryView, offset + 38);
4842
4951
  const msdosAttributesRaw = externalFileAttributes & MAX_8_BITS;
4843
4952
  const msdosAttributes = {
4844
4953
  readOnly: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_READONLY_MASK),
@@ -4847,8 +4956,8 @@ class ZipReader {
4847
4956
  directory: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_DIR_MASK),
4848
4957
  archive: Boolean(msdosAttributesRaw & FILE_ATTR_MSDOS_ARCHIVE_MASK)
4849
4958
  };
4850
- const offsetFileEntry = getUint32(directoryView, offset + 42);
4851
- const decode = getOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
4959
+ const offsetFileEntry = getUint32$1(directoryView, offset + 42);
4960
+ const decode = getFunctionOptionValue$1(zipReader, options, OPTION_DECODE_TEXT) || decodeText;
4852
4961
  const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
4853
4962
  const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
4854
4963
  let filename = decode(rawFilename, rawFilenameEncoding, TEXT_TYPE_FILENAME);
@@ -4874,12 +4983,13 @@ class ZipReader {
4874
4983
  index: indexFile,
4875
4984
  versionMadeBy,
4876
4985
  msDosCompatible,
4986
+ zip64: false,
4877
4987
  compressedSize: 0,
4878
4988
  uncompressedSize: 0,
4879
4989
  commentLength,
4880
4990
  offset: offsetFileEntry,
4881
- diskNumberStart: getUint16(directoryView, offset + 34),
4882
- internalFileAttributes: getUint16(directoryView, offset + 36),
4991
+ diskNumberStart: getUint16$1(directoryView, offset + 34),
4992
+ internalFileAttributes: getUint16$1(directoryView, offset + 36),
4883
4993
  externalFileAttributes,
4884
4994
  msdosAttributesRaw,
4885
4995
  msdosAttributes,
@@ -4947,8 +5057,8 @@ class ZipReader {
4947
5057
  yield entry;
4948
5058
  }
4949
5059
  let offsetAfterSignature = offset;
4950
- if (offset + 6 <= directoryArray.length && getUint32(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
4951
- const signatureDataLength = getUint16(directoryView, offset + 4);
5060
+ if (offset + 6 <= directoryArray.length && getUint32$1(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
5061
+ const signatureDataLength = getUint16$1(directoryView, offset + 4);
4952
5062
  if (offset + 6 + signatureDataLength <= directoryArray.length) {
4953
5063
  zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
4954
5064
  offsetAfterSignature = offset + 6 + signatureDataLength;
@@ -4960,13 +5070,17 @@ class ZipReader {
4960
5070
  if (duplicateFilename) {
4961
5071
  throwAmbiguousArchive("duplicate filename");
4962
5072
  }
4963
- if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > 0))) {
4964
- throwAmbiguousArchive("prepended data");
4965
- }
4966
5073
  const extractPrependedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_PREPENDED_DATA);
4967
5074
  const extractAppendedData = getOptionValue$1(zipReader, options, OPTION_EXTRACT_APPENDED_DATA);
5075
+ const splitZipSignatureLength = (checkAmbiguity || extractPrependedData) && filesLength &&
5076
+ startOffset == SPLIT_ZIP_FILE_SIGNATURE_LENGTH && await startsWithSplitZipMarker(reader) ? SPLIT_ZIP_FILE_SIGNATURE_LENGTH : 0;
5077
+ if (checkAmbiguity && (prependedDataLength || (filesLength && startOffset > splitZipSignatureLength))) {
5078
+ throwAmbiguousArchive("prepended data");
5079
+ }
4968
5080
  if (extractPrependedData) {
4969
- zipReader.prependedData = startOffset > 0 ? await readUint8Array(reader, 0, startOffset) : EMPTY_UINT8_ARRAY;
5081
+ zipReader.prependedData = startOffset > splitZipSignatureLength ?
5082
+ await readUint8Array(reader, splitZipSignatureLength, startOffset - splitZipSignatureLength) :
5083
+ EMPTY_UINT8_ARRAY;
4970
5084
  }
4971
5085
  zipReader.comment = commentLength ? await readUint8Array(reader, commentOffset + END_OF_CENTRAL_DIR_LENGTH, commentLength) : EMPTY_UINT8_ARRAY;
4972
5086
  if (extractAppendedData) {
@@ -5033,16 +5147,16 @@ class ZipReaderStream {
5033
5147
 
5034
5148
  let ZipEntry$1 = class ZipEntry {
5035
5149
 
5036
- constructor(reader, config, options) {
5150
+ constructor(reader, options) {
5037
5151
  Object.assign(this, {
5038
5152
  reader,
5039
- config,
5040
5153
  options
5041
5154
  });
5042
5155
  }
5043
5156
 
5044
5157
  async getData(writer, fileEntry, readRanges, options = {}) {
5045
5158
  const zipEntry = this;
5159
+ const config = getConfiguration();
5046
5160
  const {
5047
5161
  reader,
5048
5162
  index,
@@ -5051,7 +5165,6 @@ let ZipEntry$1 = class ZipEntry {
5051
5165
  extraFieldAES,
5052
5166
  extraFieldZip64,
5053
5167
  compressionMethod,
5054
- config,
5055
5168
  bitFlag,
5056
5169
  rawBitFlag,
5057
5170
  crc32,
@@ -5069,6 +5182,7 @@ let ZipEntry$1 = class ZipEntry {
5069
5182
  let password = getOptionValue$1(zipEntry, options, OPTION_PASSWORD);
5070
5183
  let rawPassword = getOptionValue$1(zipEntry, options, OPTION_RAW_PASSWORD);
5071
5184
  const passThrough = getOptionValue$1(zipEntry, options, OPTION_PASS_THROUGH);
5185
+ checkPasswordOption(password, rawPassword);
5072
5186
  password = password && password.length && password;
5073
5187
  rawPassword = rawPassword && rawPassword.length && rawPassword;
5074
5188
  if (extraFieldAES) {
@@ -5076,7 +5190,7 @@ let ZipEntry$1 = class ZipEntry {
5076
5190
  throw new Error(ERR_UNSUPPORTED_COMPRESSION$1);
5077
5191
  }
5078
5192
  }
5079
- if (dataArray.length < HEADER_SIZE || getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
5193
+ if (dataArray.length < HEADER_SIZE || getUint32$1(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
5080
5194
  throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
5081
5195
  }
5082
5196
  readCommonHeader(localDirectory, dataView, 4);
@@ -5084,9 +5198,12 @@ let ZipEntry$1 = class ZipEntry {
5084
5198
  extraFieldLength,
5085
5199
  filenameLength
5086
5200
  } = localDirectory;
5087
- const checkAmbiguity = getStrictness(getOptionValue$1(zipEntry, options, OPTION_STRICTNESS), getOptionValue$1(zipEntry, options, OPTION_CHECK_AMBIGUITY)) == STRICTNESS_STRICT;
5201
+ const checkLocalDirectoryOption = getOptionValue$1(zipEntry, options, OPTION_CHECK_LOCAL_DIRECTORY);
5202
+ const entryStrictness = getStrictness(options, zipEntry.options);
5203
+ const checkLocalDirectory = getCheckLocalDirectory(checkLocalDirectoryOption, entryStrictness);
5204
+ const checkLocalFilename = getCheckLocalFilename(checkLocalDirectoryOption, entryStrictness);
5088
5205
  let rawLocalFilename = EMPTY_UINT8_ARRAY;
5089
- if (checkAmbiguity && (filenameLength || extraFieldLength)) {
5206
+ if (checkLocalFilename && (filenameLength || extraFieldLength)) {
5090
5207
  const trailingDataArray = await readUint8Array(reader, localHeaderOffset + HEADER_SIZE, filenameLength + extraFieldLength);
5091
5208
  rawLocalFilename = trailingDataArray.subarray(0, filenameLength);
5092
5209
  localDirectory.rawExtraField = trailingDataArray.subarray(filenameLength);
@@ -5095,17 +5212,26 @@ let ZipEntry$1 = class ZipEntry {
5095
5212
  await readUint8Array(reader, localHeaderOffset + HEADER_SIZE + filenameLength, extraFieldLength) :
5096
5213
  EMPTY_UINT8_ARRAY;
5097
5214
  }
5215
+ if (checkLocalFilename) {
5216
+ localDirectory.rawFilename = rawLocalFilename;
5217
+ }
5098
5218
  readCommonFooter(zipEntry, localDirectory, dataView, 4, true);
5099
- if (checkAmbiguity) {
5100
- checkLocalDirectory(zipEntry, localDirectory, rawLocalFilename);
5219
+ if (checkLocalDirectory) {
5220
+ validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename);
5101
5221
  }
5102
- const { lastAccessDate, creationDate } = localDirectory;
5222
+ const { lastAccessDate, creationDate, uid, gid } = localDirectory;
5103
5223
  if (lastAccessDate) {
5104
5224
  fileEntry.lastAccessDate = lastAccessDate;
5105
5225
  }
5106
5226
  if (creationDate) {
5107
5227
  fileEntry.creationDate = creationDate;
5108
5228
  }
5229
+ if (uid !== UNDEFINED_VALUE && fileEntry.uid === UNDEFINED_VALUE) {
5230
+ fileEntry.uid = uid;
5231
+ }
5232
+ if (gid !== UNDEFINED_VALUE && fileEntry.gid === UNDEFINED_VALUE) {
5233
+ fileEntry.gid = gid;
5234
+ }
5109
5235
  const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
5110
5236
  const zipCrypto = encrypted && !extraFieldAES;
5111
5237
  if (!passThrough) {
@@ -5126,9 +5252,12 @@ let ZipEntry$1 = class ZipEntry {
5126
5252
  }
5127
5253
  }
5128
5254
  const dataOffset = localHeaderOffset + HEADER_SIZE + filenameLength + extraFieldLength;
5255
+ if (dataOffset + compressedSize > reader.size) {
5256
+ throw new Error(ERR_ENTRY_DATA_OUT_OF_BOUNDS);
5257
+ }
5129
5258
  const size = compressedSize;
5130
5259
  const readable = toCompatibleReadable(reader.createReadable({ offset: dataOffset, size }));
5131
- const signal = getOptionValue$1(zipEntry, options, OPTION_SIGNAL);
5260
+ const signal = checkSignalOption(getOptionValue$1(zipEntry, options, OPTION_SIGNAL));
5132
5261
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5133
5262
  let checkOverlappingEntry = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY);
5134
5263
  const checkOverlappingEntryOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_OVERLAPPING_ENTRY_ONLY);
@@ -5136,6 +5265,8 @@ let ZipEntry$1 = class ZipEntry {
5136
5265
  checkOverlappingEntry = true;
5137
5266
  }
5138
5267
  const { onstart, onprogress, onend } = options;
5268
+ const compressed = compressionMethod != COMPRESSION_METHOD_STORE && !passThrough;
5269
+ const outputSize = passThrough ? compressedSize : uncompressedSize;
5139
5270
  const deflate64 = compressionMethod == COMPRESSION_METHOD_DEFLATE_64;
5140
5271
  let useCompressionStream = getOptionValue$1(zipEntry, options, OPTION_USE_COMPRESSION_STREAM);
5141
5272
  if (deflate64) {
@@ -5156,9 +5287,9 @@ let ZipEntry$1 = class ZipEntry {
5156
5287
  checkCrc32,
5157
5288
  checkAuthenticationCode: getOptionValue$1(zipEntry, options, OPTION_CHECK_AUTHENTICATION_CODE),
5158
5289
  passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((crc32 >>> 24) & MAX_8_BITS)),
5159
- outputSize: passThrough ? compressedSize : uncompressedSize,
5290
+ outputSize,
5160
5291
  crc32,
5161
- compressed: compressionMethod != 0 && !passThrough,
5292
+ compressed,
5162
5293
  encrypted,
5163
5294
  useWebWorkers: getOptionValue$1(zipEntry, options, OPTION_USE_WEB_WORKERS),
5164
5295
  useCompressionStream,
@@ -5195,11 +5326,11 @@ let ZipEntry$1 = class ZipEntry {
5195
5326
  writer = new WritableStream();
5196
5327
  }
5197
5328
  writer = new GenericWriter(writer);
5198
- await initStream(writer, passThrough ? compressedSize : uncompressedSize);
5329
+ await initStream(writer, getDecodableOutputSize(outputSize, compressedSize, compressed));
5199
5330
  ({ writable } = writer);
5200
- const { outputSize } = await runWorker({ readable, writable }, workerOptions);
5201
- writer.size += outputSize;
5202
- if (outputSize != (passThrough ? compressedSize : uncompressedSize)) {
5331
+ const { outputSize: writtenSize } = await runWorker({ readable, writable }, workerOptions);
5332
+ writer.size += writtenSize;
5333
+ if (writtenSize != outputSize) {
5203
5334
  throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
5204
5335
  }
5205
5336
  }
@@ -5233,7 +5364,7 @@ let ZipEntry$1 = class ZipEntry {
5233
5364
  function detectEncryptedCentralDirectory(directoryView) {
5234
5365
  const maxOffset = Math.min(directoryView.byteLength, 1024) - 3;
5235
5366
  for (let offset = 0; offset < maxOffset; offset++) {
5236
- if (getUint32(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
5367
+ if (getUint32$1(directoryView, offset) == ARCHIVE_EXTRA_DATA_SIGNATURE) {
5237
5368
  return true;
5238
5369
  }
5239
5370
  }
@@ -5244,15 +5375,15 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5244
5375
  const directoryEncryptionInfo = { rawExtensibleData };
5245
5376
  if (rawExtensibleData.length >= 28) {
5246
5377
  const extensibleDataView = getDataView(rawExtensibleData);
5247
- const hashDataLength = getUint16(extensibleDataView, 26);
5378
+ const hashDataLength = getUint16$1(extensibleDataView, 26);
5248
5379
  Object.assign(directoryEncryptionInfo, {
5249
- compressionMethod: getUint16(extensibleDataView, 0),
5380
+ compressionMethod: getUint16$1(extensibleDataView, 0),
5250
5381
  compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5251
5382
  uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5252
- encryptionAlgorithm: getUint16(extensibleDataView, 18),
5253
- bitLength: getUint16(extensibleDataView, 20),
5254
- flags: getUint16(extensibleDataView, 22),
5255
- hashAlgorithm: getUint16(extensibleDataView, 24),
5383
+ encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
5384
+ bitLength: getUint16$1(extensibleDataView, 20),
5385
+ flags: getUint16$1(extensibleDataView, 22),
5386
+ hashAlgorithm: getUint16$1(extensibleDataView, 24),
5256
5387
  hashData: rawExtensibleData.subarray(28, 28 + hashDataLength)
5257
5388
  });
5258
5389
  }
@@ -5260,12 +5391,12 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5260
5391
  }
5261
5392
 
5262
5393
  function readCommonHeader(directory, dataView, offset) {
5263
- const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
5394
+ const rawBitFlag = directory.rawBitFlag = getUint16$1(dataView, offset + 2);
5264
5395
  const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
5265
- const rawLastModDate = getUint32(dataView, offset + 6);
5396
+ const rawLastModDate = getUint32$1(dataView, offset + 6);
5266
5397
  Object.assign(directory, {
5267
5398
  encrypted,
5268
- version: getUint16(dataView, offset),
5399
+ version: getUint16$1(dataView, offset),
5269
5400
  bitFlag: {
5270
5401
  level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
5271
5402
  dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
@@ -5273,8 +5404,8 @@ function readCommonHeader(directory, dataView, offset) {
5273
5404
  },
5274
5405
  rawLastModDate,
5275
5406
  lastModDate: getDate(rawLastModDate),
5276
- filenameLength: getUint16(dataView, offset + 22),
5277
- extraFieldLength: getUint16(dataView, offset + 24)
5407
+ filenameLength: getUint16$1(dataView, offset + 22),
5408
+ extraFieldLength: getUint16$1(dataView, offset + 24)
5278
5409
  });
5279
5410
  }
5280
5411
 
@@ -5285,8 +5416,8 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5285
5416
  let offsetExtraField = 0;
5286
5417
  try {
5287
5418
  while (offsetExtraField < rawExtraField.length) {
5288
- const type = getUint16(rawExtraFieldView, offsetExtraField);
5289
- const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
5419
+ const type = getUint16$1(rawExtraFieldView, offsetExtraField);
5420
+ const size = getUint16$1(rawExtraFieldView, offsetExtraField + 2);
5290
5421
  extraField.set(type, {
5291
5422
  type,
5292
5423
  data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
@@ -5296,12 +5427,12 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5296
5427
  } catch {
5297
5428
  // ignored
5298
5429
  }
5299
- const compressionMethod = getUint16(dataView, offset + 4);
5430
+ const compressionMethod = getUint16$1(dataView, offset + 4);
5300
5431
  Object.assign(directory, {
5301
- signature: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5302
- crc32: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5303
- compressedSize: getUint32(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
5304
- uncompressedSize: getUint32(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
5432
+ signature: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
5433
+ crc32: getUint32$1(dataView, offset + HEADER_OFFSET_SIGNATURE),
5434
+ compressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
5435
+ uncompressedSize: getUint32$1(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
5305
5436
  });
5306
5437
  const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
5307
5438
  if (extraFieldZip64) {
@@ -5341,10 +5472,12 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5341
5472
  directory.extraFieldNTFS = extraFieldNTFS;
5342
5473
  }
5343
5474
  const extraFieldUnix = extraField.get(EXTRAFIELD_TYPE_UNIX);
5475
+ let unixIdsRead;
5344
5476
  if (extraFieldUnix) {
5345
- readExtraFieldUnix(extraFieldUnix, directory, false);
5477
+ unixIdsRead = readExtraFieldUnix(extraFieldUnix, directory, false);
5346
5478
  directory.extraFieldUnix = extraFieldUnix;
5347
- } else {
5479
+ }
5480
+ if (!unixIdsRead) {
5348
5481
  const extraFieldInfoZip = extraField.get(EXTRAFIELD_TYPE_INFOZIP);
5349
5482
  if (extraFieldInfoZip) {
5350
5483
  readExtraFieldUnix(extraFieldInfoZip, directory, true);
@@ -5388,11 +5521,11 @@ function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName,
5388
5521
  computedCrc32.append(fileEntry[rawPropertyName]);
5389
5522
  const computedCrc32View = getDataView(new Uint8Array(4));
5390
5523
  computedCrc32View.setUint32(0, computedCrc32.get(), true);
5391
- const nameCrc32 = getUint32(extraFieldView, 1);
5524
+ const nameCrc32 = getUint32$1(extraFieldView, 1);
5392
5525
  Object.assign(extraFieldUnicode, {
5393
5526
  version: getUint8(extraFieldView, 0),
5394
5527
  [propertyName]: decodeText(extraFieldUnicode.data.subarray(5)),
5395
- valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32(computedCrc32View, 0)
5528
+ valid: !fileEntry.bitFlag.languageEncodingFlag && nameCrc32 == getUint32$1(computedCrc32View, 0)
5396
5529
  });
5397
5530
  if (extraFieldUnicode.valid) {
5398
5531
  directory[propertyName] = extraFieldUnicode[propertyName];
@@ -5408,7 +5541,7 @@ function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
5408
5541
  vendorId: getUint8(extraFieldView, 2),
5409
5542
  strength,
5410
5543
  originalCompressionMethod: compressionMethod,
5411
- compressionMethod: getUint16(extraFieldView, 5)
5544
+ compressionMethod: getUint16$1(extraFieldView, 5)
5412
5545
  });
5413
5546
  directory.compressionMethod = extraFieldAES.compressionMethod;
5414
5547
  if (extraFieldAES.vendorVersion != VENDOR_VERSION_AE_1$1) {
@@ -5422,8 +5555,8 @@ function readExtraFieldNTFS(extraFieldNTFS, directory) {
5422
5555
  let tag1Data;
5423
5556
  try {
5424
5557
  while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
5425
- const tagValue = getUint16(extraFieldView, offsetExtraField);
5426
- const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
5558
+ const tagValue = getUint16$1(extraFieldView, offsetExtraField);
5559
+ const attributeSize = getUint16$1(extraFieldView, offsetExtraField + 2);
5427
5560
  if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
5428
5561
  tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
5429
5562
  }
@@ -5447,7 +5580,7 @@ function readExtraFieldNTFS(extraFieldNTFS, directory) {
5447
5580
  const creationDate = getDateNTFS(rawCreationDate);
5448
5581
  const extraFieldData = { lastModDate, lastAccessDate, creationDate };
5449
5582
  Object.assign(extraFieldNTFS, extraFieldData);
5450
- Object.assign(directory, extraFieldData);
5583
+ Object.assign(directory, extraFieldData, { rawLastAccessDate, rawCreationDate });
5451
5584
  }
5452
5585
  }
5453
5586
 
@@ -5456,12 +5589,12 @@ function readExtraFieldUnixDates(extraField, directory) {
5456
5589
  return;
5457
5590
  }
5458
5591
  const extraFieldView = getDataView(extraField.data);
5459
- const lastAccessDate = new Date((getUint32(extraFieldView, 0) | 0) * 1000);
5460
- const lastModDate = new Date((getUint32(extraFieldView, 4) | 0) * 1000);
5592
+ const lastAccessDate = new Date((getUint32$1(extraFieldView, 0) | 0) * 1000);
5593
+ const lastModDate = new Date((getUint32$1(extraFieldView, 4) | 0) * 1000);
5461
5594
  const extraFieldData = { lastAccessDate, lastModDate };
5462
5595
  if (extraField.data.length >= 12) {
5463
- extraFieldData.uid = getUint16(extraFieldView, 8);
5464
- extraFieldData.gid = getUint16(extraFieldView, 10);
5596
+ extraFieldData.uid = getUint16$1(extraFieldView, 8);
5597
+ extraFieldData.gid = getUint16$1(extraFieldView, 10);
5465
5598
  }
5466
5599
  Object.assign(extraField, extraFieldData);
5467
5600
  Object.assign(directory, extraFieldData);
@@ -5481,8 +5614,8 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
5481
5614
  gid = unpackUnixId(extraField.data.subarray(offset, offset + gidSize));
5482
5615
  Object.assign(extraField, { version, uid, gid });
5483
5616
  } else if (extraField.data.length >= 4) {
5484
- uid = getUint16(view, 0);
5485
- gid = getUint16(view, 2);
5617
+ uid = getUint16$1(view, 0);
5618
+ gid = getUint16$1(view, 2);
5486
5619
  Object.assign(extraField, { uid, gid });
5487
5620
  }
5488
5621
  if (uid !== UNDEFINED_VALUE) {
@@ -5491,6 +5624,7 @@ function readExtraFieldUnix(extraField, directory, isInfoZip) {
5491
5624
  if (gid !== UNDEFINED_VALUE) {
5492
5625
  directory.gid = gid;
5493
5626
  }
5627
+ return uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE;
5494
5628
  } catch {
5495
5629
  // ignored
5496
5630
  }
@@ -5531,7 +5665,7 @@ function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory,
5531
5665
  let offset = 1;
5532
5666
  timeProperties.forEach((propertyName, indexProperty) => {
5533
5667
  if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
5534
- const time = getUint32(extraFieldView, offset);
5668
+ const time = getUint32$1(extraFieldView, offset);
5535
5669
  directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date((time | 0) * 1000);
5536
5670
  const rawPropertyName = timeRawProperties[indexProperty];
5537
5671
  extraFieldExtendedTimestamp[rawPropertyName] = time;
@@ -5563,26 +5697,25 @@ async function detectOverlappingEntry({
5563
5697
  }
5564
5698
  if (dataDescriptorLength) {
5565
5699
  const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
5566
- const dataDescriptorSignature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
5567
- getUint32(getDataView(dataDescriptorArray), 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5568
- if (dataDescriptorSignature) {
5569
- const readCrc32 = getUint32(getDataView(dataDescriptorArray), 4);
5570
- let readCompressedSize;
5571
- let readUncompressedSize;
5572
- if (extraFieldZip64) {
5573
- readCompressedSize = getBigUint64(getDataView(dataDescriptorArray), 8);
5574
- readUncompressedSize = getBigUint64(getDataView(dataDescriptorArray), 16);
5575
- } else {
5576
- readCompressedSize = getUint32(getDataView(dataDescriptorArray), 8);
5577
- readUncompressedSize = getUint32(getDataView(dataDescriptorArray), 12);
5578
- }
5579
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || readCrc32 == crc32;
5700
+ const dataDescriptorView = getDataView(dataDescriptorArray);
5701
+ let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
5702
+ getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
5703
+ if (signature) {
5704
+ const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
5705
+ const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
5580
5706
  if (matchCrc32 &&
5581
- readCompressedSize == compressedSize &&
5582
- readUncompressedSize == uncompressedSize) {
5707
+ signedDataDescriptor.compressedSize == compressedSize &&
5708
+ signedDataDescriptor.uncompressedSize == uncompressedSize) {
5583
5709
  dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
5710
+ } else {
5711
+ signature = false;
5584
5712
  }
5585
5713
  }
5714
+ if (dataDescriptorArray.length >= dataDescriptorLength) {
5715
+ const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
5716
+ localDataDescriptor.signature = signature;
5717
+ fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
5718
+ }
5586
5719
  }
5587
5720
  const range = {
5588
5721
  start: offset,
@@ -5599,22 +5732,80 @@ async function detectOverlappingEntry({
5599
5732
  readRanges.set(index, range);
5600
5733
  }
5601
5734
 
5735
+ function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
5736
+ const crc32 = getUint32$1(dataDescriptorView, offset);
5737
+ let compressedSize;
5738
+ let uncompressedSize;
5739
+ if (extraFieldZip64) {
5740
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
5741
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
5742
+ } else {
5743
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
5744
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
5745
+ }
5746
+ return { crc32, compressedSize, uncompressedSize };
5747
+ }
5748
+
5602
5749
  function getDiskOffset$1(reader, diskNumber) {
5603
5750
  return reader.getDiskOffset ? reader.getDiskOffset(diskNumber) : 0;
5604
5751
  }
5605
5752
 
5753
+ async function startsWithSplitZipSignature$1(reader) {
5754
+ return await getFirstSignature(reader) == SPLIT_ZIP_FILE_SIGNATURE;
5755
+ }
5756
+
5757
+ async function startsWithSplitZipMarker(reader) {
5758
+ const signature = await getFirstSignature(reader);
5759
+ return signature == SPLIT_ZIP_FILE_SIGNATURE || signature == TEMPORARY_SPLIT_ZIP_FILE_SIGNATURE;
5760
+ }
5761
+
5762
+ async function getFirstSignature(reader) {
5763
+ const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
5764
+ return getUint32$1(getDataView(signatureArray));
5765
+ }
5766
+
5606
5767
  function isStrictnessValue(value) {
5607
5768
  return value === STRICTNESS_STRICT || value === STRICTNESS_BALANCED || value === STRICTNESS_TOLERANT;
5608
5769
  }
5609
5770
 
5610
- function getStrictness(strictness, checkAmbiguity) {
5611
- if (strictness === UNDEFINED_VALUE) {
5612
- return checkAmbiguity ? STRICTNESS_STRICT : STRICTNESS_BALANCED;
5771
+ function getDecodableOutputSize(outputSize, compressedSize, compressed) {
5772
+ return Math.min(outputSize, compressed ? compressedSize * MAX_DEFLATE_EXPANSION_RATIO : compressedSize);
5773
+ }
5774
+
5775
+ function getStrictness(options, inheritedOptions) {
5776
+ return resolveStrictness(options, resolveStrictness(inheritedOptions, STRICTNESS_BALANCED));
5777
+ }
5778
+
5779
+ function resolveStrictness(options, inheritedStrictness) {
5780
+ const strictness = options[OPTION_STRICTNESS];
5781
+ if (strictness !== UNDEFINED_VALUE) {
5782
+ if (!isStrictnessValue(strictness)) {
5783
+ throw new Error(ERR_INVALID_STRICTNESS);
5784
+ }
5785
+ return strictness;
5786
+ }
5787
+ const checkAmbiguity = options[OPTION_CHECK_AMBIGUITY];
5788
+ if (checkAmbiguity === UNDEFINED_VALUE) {
5789
+ return inheritedStrictness;
5613
5790
  }
5614
- if (!isStrictnessValue(strictness)) {
5615
- throw new Error(ERR_INVALID_STRICTNESS);
5791
+ if (checkAmbiguity) {
5792
+ return STRICTNESS_STRICT;
5616
5793
  }
5617
- return strictness;
5794
+ return inheritedStrictness == STRICTNESS_TOLERANT ? STRICTNESS_TOLERANT : STRICTNESS_BALANCED;
5795
+ }
5796
+
5797
+ function getCheckLocalDirectory(checkLocalDirectory, strictness) {
5798
+ if (checkLocalDirectory === UNDEFINED_VALUE) {
5799
+ return strictness != STRICTNESS_TOLERANT;
5800
+ }
5801
+ return Boolean(checkLocalDirectory);
5802
+ }
5803
+
5804
+ function getCheckLocalFilename(checkLocalFilename, strictness) {
5805
+ if (checkLocalFilename === UNDEFINED_VALUE) {
5806
+ return strictness == STRICTNESS_STRICT;
5807
+ }
5808
+ return Boolean(checkLocalFilename);
5618
5809
  }
5619
5810
 
5620
5811
  function getFilenameValidation(filenameValidation, strictness) {
@@ -5643,7 +5834,7 @@ function isUnsafeFilename(filename, filenameValidation) {
5643
5834
 
5644
5835
  function getMaxAppendedDataSize(maxAppendedDataSize, strictness) {
5645
5836
  if (maxAppendedDataSize !== UNDEFINED_VALUE) {
5646
- const size = toNumber$1(maxAppendedDataSize);
5837
+ const size = toNumber(maxAppendedDataSize);
5647
5838
  if (typeof size != NUMBER_TYPE || Number.isNaN(size) || size < 0) {
5648
5839
  throw new Error(ERR_INVALID_MAX_APPENDED_DATA_SIZE);
5649
5840
  }
@@ -5666,7 +5857,7 @@ async function findEndOfCentralDirectory(reader, rejectAmbiguous, maxAppendedDat
5666
5857
  let plausibleEndOfDirectoryInfo;
5667
5858
  let endOfDirectoryReachingEndCount = 0;
5668
5859
  for await (const [anchoredView, anchoredOffset, anchoredArray, indexByte, offset] of scanEndOfCentralDirectory(reader, anchoredLength)) {
5669
- const commentLength = getUint16(anchoredView, indexByte + 20);
5860
+ const commentLength = getUint16$1(anchoredView, indexByte + 20);
5670
5861
  if (offset + END_OF_CENTRAL_DIR_LENGTH + commentLength == size) {
5671
5862
  const reachability = await getCentralDirectoryReachability(reader, anchoredView, anchoredOffset, indexByte, offset, size, remoteProbeBudget);
5672
5863
  if (reachability == CENTRAL_DIRECTORY_REACHABLE) {
@@ -5717,7 +5908,7 @@ async function* scanEndOfCentralDirectory(reader, scanLength) {
5717
5908
  const scanArray = await readUint8Array(reader, scanOffset, scanLength);
5718
5909
  const scanView = getDataView(scanArray);
5719
5910
  for (let indexByte = scanArray.length - END_OF_CENTRAL_DIR_LENGTH; indexByte >= 0; indexByte--) {
5720
- if (getUint32(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5911
+ if (getUint32$1(scanView, indexByte) == END_OF_CENTRAL_DIR_SIGNATURE) {
5721
5912
  yield [scanView, scanOffset, scanArray, indexByte, scanOffset + indexByte];
5722
5913
  }
5723
5914
  }
@@ -5728,9 +5919,9 @@ function getEndOfCentralDirectoryInfo(scanArray, indexByte, offset) {
5728
5919
  }
5729
5920
 
5730
5921
  async function getCentralDirectoryReachability(reader, view, anchoredOffset, indexByte, offset, size, remoteProbeBudget) {
5731
- const filesLength = getUint16(view, indexByte + 10);
5732
- const directoryDataLength = getUint32(view, indexByte + 12);
5733
- const directoryDataOffset = getUint32(view, indexByte + 16);
5922
+ const filesLength = getUint16$1(view, indexByte + 10);
5923
+ const directoryDataLength = getUint32$1(view, indexByte + 12);
5924
+ const directoryDataOffset = getUint32$1(view, indexByte + 16);
5734
5925
  if (filesLength == MAX_16_BITS || directoryDataLength == MAX_32_BITS || directoryDataOffset == MAX_32_BITS) {
5735
5926
  const locatorSignature = await readSignature(reader, view, anchoredOffset, offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, size, remoteProbeBudget);
5736
5927
  return locatorSignature == ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE ? CENTRAL_DIRECTORY_REACHABLE : CENTRAL_DIRECTORY_UNREACHABLE;
@@ -5738,7 +5929,7 @@ async function getCentralDirectoryReachability(reader, view, anchoredOffset, ind
5738
5929
  if (!filesLength && !directoryDataLength) {
5739
5930
  return CENTRAL_DIRECTORY_PLAUSIBLE;
5740
5931
  }
5741
- const directoryDiskNumber = getUint16(view, indexByte + 6);
5932
+ const directoryDiskNumber = getUint16$1(view, indexByte + 6);
5742
5933
  for (const centralDirectoryOffset of [offset - directoryDataLength, getDiskOffset$1(reader, directoryDiskNumber) + directoryDataOffset]) {
5743
5934
  if (await readSignature(reader, view, anchoredOffset, centralDirectoryOffset, size, remoteProbeBudget) == CENTRAL_FILE_HEADER_SIGNATURE) {
5744
5935
  return CENTRAL_DIRECTORY_REACHABLE;
@@ -5752,20 +5943,21 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
5752
5943
  return UNDEFINED_VALUE;
5753
5944
  }
5754
5945
  if (signatureOffset >= anchoredOffset) {
5755
- return getUint32(view, signatureOffset - anchoredOffset);
5946
+ return getUint32$1(view, signatureOffset - anchoredOffset);
5756
5947
  }
5757
5948
  if (remoteProbeBudget.count > 0) {
5758
5949
  remoteProbeBudget.count--;
5759
5950
  const signatureArray = await readUint8Array(reader, signatureOffset, 4);
5760
- return getUint32(getDataView(signatureArray), 0);
5951
+ return getUint32$1(getDataView(signatureArray), 0);
5761
5952
  }
5762
5953
  return UNDEFINED_VALUE;
5763
5954
  }
5764
5955
 
5765
- function checkLocalDirectory(zipEntry, localDirectory, rawLocalFilename) {
5956
+ function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
5766
5957
  const { rawFilename } = zipEntry;
5767
- if (rawLocalFilename.length != rawFilename.length ||
5768
- rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte])) {
5958
+ if (checkLocalFilename &&
5959
+ (rawLocalFilename.length != rawFilename.length ||
5960
+ rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
5769
5961
  throwAmbiguousArchive("mismatched local file header (filename)");
5770
5962
  }
5771
5963
  if ((localDirectory.rawBitFlag & BITFLAG_AMBIGUITY_MASK) != (zipEntry.rawBitFlag & BITFLAG_AMBIGUITY_MASK)) {
@@ -5793,10 +5985,11 @@ function getOptionValue$1(zipReader, options, name) {
5793
5985
  return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
5794
5986
  }
5795
5987
 
5796
- function toNumber$1(value) {
5797
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
5988
+ function getFunctionOptionValue$1(zipReader, options, name) {
5989
+ return checkFunctionOption(getOptionValue$1(zipReader, options, name));
5798
5990
  }
5799
5991
 
5992
+
5800
5993
  function getDate(timeRaw) {
5801
5994
  const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
5802
5995
  return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
@@ -5810,11 +6003,11 @@ function getUint8(view, offset) {
5810
6003
  return view.getUint8(offset);
5811
6004
  }
5812
6005
 
5813
- function getUint16(view, offset) {
6006
+ function getUint16$1(view, offset) {
5814
6007
  return view.getUint16(offset, true);
5815
6008
  }
5816
6009
 
5817
- function getUint32(view, offset) {
6010
+ function getUint32$1(view, offset) {
5818
6011
  return view.getUint32(offset, true);
5819
6012
  }
5820
6013
 
@@ -5829,6 +6022,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
5829
6022
  ERR_CENTRAL_DIRECTORY_NOT_FOUND: ERR_CENTRAL_DIRECTORY_NOT_FOUND,
5830
6023
  ERR_ENCRYPTED: ERR_ENCRYPTED,
5831
6024
  ERR_ENCRYPTED_CENTRAL_DIRECTORY: ERR_ENCRYPTED_CENTRAL_DIRECTORY,
6025
+ ERR_ENTRY_DATA_OUT_OF_BOUNDS: ERR_ENTRY_DATA_OUT_OF_BOUNDS,
5832
6026
  ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
5833
6027
  ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
5834
6028
  ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
@@ -5883,13 +6077,18 @@ var zipReader = /*#__PURE__*/Object.freeze({
5883
6077
 
5884
6078
  const ERR_DUPLICATED_NAME = "File already exists";
5885
6079
  const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
6080
+ const ERR_INVALID_COMMENT_TYPE = "Invalid zip file comment (must be a Uint8Array)";
5886
6081
  const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
6082
+ const ERR_INVALID_ENTRY_COMMENT_TYPE = "Invalid file entry comment (must be a string)";
6083
+ const ERR_INVALID_DATE = "Invalid date (must be a valid Date instance)";
5887
6084
  const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
5888
6085
  const ERR_INVALID_VERSION = "Version exceeds 65535";
5889
6086
  const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
5890
6087
  const ERR_UNSUPPORTED_ENCRYPTION_USDZ = "Encryption is not supported in USDZ files";
5891
6088
  const ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = "Encryption is not supported when the 'passThrough' option is set";
5892
- const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
6089
+ const ERR_INVALID_EXTRAFIELD = "Invalid extra field (must be a Map)";
6090
+ const ERR_INVALID_EXTRAFIELD_TYPE = "Invalid extra field type (must be integer 0..65535)";
6091
+ const ERR_INVALID_EXTRAFIELD_DATA_TYPE = "Invalid extra field data (must be a Uint8Array)";
5893
6092
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
5894
6093
  const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
5895
6094
  const MIN_UNIX_TIME = -2147483648;
@@ -5909,7 +6108,6 @@ const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldTyp
5909
6108
  const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
5910
6109
  const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
5911
6110
  const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
5912
- const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
5913
6111
  const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
5914
6112
 
5915
6113
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
@@ -5934,8 +6132,7 @@ class ZipWriter {
5934
6132
  writer,
5935
6133
  addSplitZipSignature,
5936
6134
  options,
5937
- config: getConfiguration(),
5938
- files: new Map(),
6135
+ fileEntries: new Map(),
5939
6136
  filenames: new Set(),
5940
6137
  offset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? writer.size || writer.writable.size || 0 : options[OPTION_OFFSET],
5941
6138
  initialOffset: options[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : options[OPTION_OFFSET] - (writer.size || writer.writable.size || 0),
@@ -5951,15 +6148,28 @@ class ZipWriter {
5951
6148
  }
5952
6149
  reader = new GenericReader(reader);
5953
6150
  await initStream(reader);
6151
+ if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
6152
+ reader = new BlobReader(await streamToBlob(reader.readable));
6153
+ await initStream(reader);
6154
+ }
5954
6155
  const { ZipReader } = await Promise.resolve().then(function () { return zipReader; });
5955
- const zipReader$1 = new ZipReader(reader.readable);
6156
+ const zipReader$1 = new ZipReader(reader);
5956
6157
  const entries = await zipReader$1.getEntries();
5957
6158
  await zipReader$1.close();
5958
6159
  await initStream(this.writer);
5959
- await reader.readable.pipeTo(this.writer.writable, { preventClose: true, preventAbort: true });
5960
- this.writer.size = this.offset = reader.size;
6160
+ const { directoryOffset } = zipReader$1;
6161
+ let splitZipSignatureLength = 0;
6162
+ if (this.addSplitZipSignature) {
6163
+ delete this.addSplitZipSignature;
6164
+ if (!await startsWithSplitZipSignature(reader)) {
6165
+ await writeData(this.writer, getSplitZipSignatureArray());
6166
+ splitZipSignatureLength = SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
6167
+ this.offset += splitZipSignatureLength;
6168
+ }
6169
+ }
6170
+ const entryPositions = await copyZipData(this, reader, entries, directoryOffset, splitZipSignatureLength);
5961
6171
  this.filenames = new Set(entries.map(entry => entry.filename));
5962
- this.files = new Map(entries.map(entry => {
6172
+ this.fileEntries = new Map(entries.map(entry => {
5963
6173
  const {
5964
6174
  version,
5965
6175
  rawLastModDate,
@@ -6014,11 +6224,12 @@ class ZipWriter {
6014
6224
  if (crc32 !== UNDEFINED_VALUE) {
6015
6225
  setUint32(headerView, HEADER_OFFSET_SIGNATURE, crc32);
6016
6226
  }
6227
+ const { offset, diskNumberStart } = entryPositions.get(entry);
6017
6228
  Object.assign(entry, {
6018
6229
  zip64UncompressedSize,
6019
6230
  zip64CompressedSize,
6020
- zip64Offset: zip64 && entry.offset >= MAX_32_BITS,
6021
- diskNumberStart: 0,
6231
+ offset,
6232
+ diskNumberStart,
6022
6233
  zip64DiskNumberStart: false,
6023
6234
  rawExtraFieldZip64,
6024
6235
  rawExtraFieldAES,
@@ -6038,11 +6249,8 @@ class ZipWriter {
6038
6249
  async add(name = "", reader, options = {}) {
6039
6250
  const zipWriter = this;
6040
6251
  options = Object.assign({}, options);
6041
- const {
6042
- pendingAddFileCalls,
6043
- config
6044
- } = zipWriter;
6045
- if (workers < config.maxWorkers) {
6252
+ const { pendingAddFileCalls } = zipWriter;
6253
+ if (workers < getConfiguration().maxWorkers) {
6046
6254
  workers++;
6047
6255
  } else {
6048
6256
  await new Promise(resolve => pendingEntries.push(resolve));
@@ -6079,16 +6287,16 @@ class ZipWriter {
6079
6287
  }
6080
6288
 
6081
6289
  remove(entry) {
6082
- const { filenames, files } = this;
6290
+ const { filenames, fileEntries } = this;
6083
6291
  // deno-lint-ignore valid-typeof
6084
6292
  if (typeof entry == STRING_TYPE) {
6085
- entry = files.get(entry);
6293
+ entry = fileEntries.get(entry);
6086
6294
  }
6087
6295
  if (entry && entry.filename !== UNDEFINED_VALUE) {
6088
6296
  const { filename } = entry;
6089
- if (filenames.has(filename) && files.has(filename)) {
6297
+ if (filenames.has(filename) && fileEntries.has(filename)) {
6090
6298
  filenames.delete(filename);
6091
- files.delete(filename);
6299
+ fileEntries.delete(filename);
6092
6300
  return true;
6093
6301
  }
6094
6302
  }
@@ -6099,6 +6307,9 @@ class ZipWriter {
6099
6307
  const zipWriter = this;
6100
6308
  const { pendingAddFileCalls, writer } = this;
6101
6309
  const { writable } = writer;
6310
+ if (!(comment instanceof Uint8Array)) {
6311
+ throw new Error(ERR_INVALID_COMMENT_TYPE);
6312
+ }
6102
6313
  if (getLength(comment) > MAX_16_BITS) {
6103
6314
  throw new Error(ERR_INVALID_COMMENT);
6104
6315
  }
@@ -6182,12 +6393,12 @@ async function addFile(zipWriter, name, reader, options) {
6182
6393
  const metadataInfo = resolveMetadata(zipWriter, name, options);
6183
6394
  const { comment } = metadataInfo;
6184
6395
  const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
6185
- zipWriter.files.set(name, UNDEFINED_VALUE);
6396
+ zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
6186
6397
  let fileEntry;
6187
6398
  try {
6188
6399
  const { resolvedOptions } = metadataInfo;
6189
6400
  if (resolvedOptions.level != 0 && resolvedOptions.compressionMethod === UNDEFINED_VALUE &&
6190
- !resolvedOptions.passThrough && !(await supportsDeflate(zipWriter.config))) {
6401
+ !resolvedOptions.passThrough && !(await supportsDeflate(getConfiguration()))) {
6191
6402
  resolvedOptions.level = 0;
6192
6403
  }
6193
6404
  const sizesInfo = await resolveSizes(zipWriter, reader, metadataInfo, options);
@@ -6195,8 +6406,6 @@ async function addFile(zipWriter, name, reader, options) {
6195
6406
  const diskOffset = getDiskOffset(zipWriter.writer);
6196
6407
  const diskNumber = getDiskNumber(zipWriter.writer);
6197
6408
  options = Object.assign({}, options, attributesInfo.resolvedOptions, metadataInfo.resolvedOptions, sizesInfo.resolvedOptions, {
6198
- internalFileAttribute: metadataInfo.resolvedOptions.internalFileAttributes,
6199
- externalFileAttribute: attributesInfo.resolvedOptions.externalFileAttributes,
6200
6409
  signature: options[PROPERTY_NAME_SIGNATURE],
6201
6410
  crc32: options.crc32 === UNDEFINED_VALUE ? options[PROPERTY_NAME_SIGNATURE] : options.crc32,
6202
6411
  offset: zipWriter.offset - diskOffset,
@@ -6207,17 +6416,23 @@ async function addFile(zipWriter, name, reader, options) {
6207
6416
  const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
6208
6417
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
6209
6418
  } catch (error) {
6210
- zipWriter.files.delete(name);
6419
+ zipWriter.fileEntries.delete(name);
6211
6420
  throw error;
6212
6421
  }
6213
- Object.assign(fileEntry, { name, comment, extraField });
6422
+ Object.assign(fileEntry, {
6423
+ name,
6424
+ comment,
6425
+ extraField,
6426
+ [PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES]: fileEntry.internalFileAttributes,
6427
+ [PROPERTY_NAME_DEPRECATED_EXTERNAL_FILE_ATTRIBUTES]: fileEntry.externalFileAttributes
6428
+ });
6214
6429
  return new Entry(fileEntry);
6215
6430
  }
6216
6431
 
6217
6432
  function resolveAttributes(zipWriter, name, options) {
6218
6433
  name = name.trim();
6219
6434
  let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
6220
- let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
6435
+ let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? VERSION_MADE_BY_MSDOS : VERSION_MADE_BY_UNIX);
6221
6436
  const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
6222
6437
  const uid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UID);
6223
6438
  const gid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_GID);
@@ -6245,21 +6460,21 @@ function resolveAttributes(zipWriter, name, options) {
6245
6460
  if (unixExtraFieldType === UNDEFINED_VALUE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
6246
6461
  unixExtraFieldType = INFOZIP_EXTRA_FIELD_TYPE$1;
6247
6462
  }
6248
- let msdosAttributesRaw = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
6463
+ let msdosAttributesRaw = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES_RAW);
6249
6464
  let msdosAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_MSDOS_ATTRIBUTES);
6250
- const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType;
6465
+ const hasUnixMetadata = uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE || unixMode !== UNDEFINED_VALUE || unixExtraFieldType || executable;
6251
6466
  const hasMsDosProvided = msdosAttributesRaw !== UNDEFINED_VALUE || msdosAttributes !== UNDEFINED_VALUE;
6252
6467
  if (hasUnixMetadata) {
6253
6468
  msDosCompatible = false;
6254
- versionMadeBy = (versionMadeBy & MAX_16_BITS) | (3 << 8);
6469
+ versionMadeBy = (versionMadeBy & MAX_8_BITS) | VERSION_MADE_BY_UNIX;
6255
6470
  } else if (hasMsDosProvided) {
6256
6471
  msDosCompatible = true;
6257
6472
  versionMadeBy = (versionMadeBy & MAX_8_BITS);
6258
6473
  }
6259
- if (msdosAttributesRaw !== UNDEFINED_VALUE && (msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
6474
+ if (msdosAttributesRaw !== UNDEFINED_VALUE && (!Number.isInteger(msdosAttributesRaw) || msdosAttributesRaw < 0 || msdosAttributesRaw > MAX_8_BITS)) {
6260
6475
  throw new Error(ERR_INVALID_MSDOS_ATTRIBUTES);
6261
6476
  }
6262
- if (msdosAttributes && typeof msdosAttributes !== OBJECT_TYPE) {
6477
+ if (msdosAttributes && (typeof msdosAttributes !== OBJECT_TYPE || Array.isArray(msdosAttributes))) {
6263
6478
  throw new Error(ERR_INVALID_MSDOS_DATA);
6264
6479
  }
6265
6480
  if (versionMadeBy > MAX_16_BITS) {
@@ -6291,11 +6506,10 @@ function resolveAttributes(zipWriter, name, options) {
6291
6506
  externalFileAttributes = FILE_ATTR_UNIX_DEFAULT_MASK << 16;
6292
6507
  }
6293
6508
  }
6294
- let unixExternalUpper;
6295
6509
  if (!msDosCompatible) {
6296
6510
  const unixModeProvided = unixMode !== UNDEFINED_VALUE || Boolean(setuid || setgid || sticky);
6297
- unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
6298
- unixMode = unixMode === UNDEFINED_VALUE ? unixExternalUpper : (unixMode & MAX_16_BITS);
6511
+ const defaultUnixMode = (externalFileAttributes >> 16) & MAX_16_BITS;
6512
+ unixMode = unixMode === UNDEFINED_VALUE ? defaultUnixMode : (unixMode & MAX_16_BITS);
6299
6513
  if (setuid) {
6300
6514
  unixMode |= FILE_ATTR_UNIX_SETUID_MASK;
6301
6515
  } else {
@@ -6324,17 +6538,20 @@ function resolveAttributes(zipWriter, name, options) {
6324
6538
  if (hasMsDosProvided) {
6325
6539
  externalFileAttributes = (externalFileAttributes & MAX_32_BITS) | (msdosAttributesRaw & MAX_8_BITS);
6326
6540
  }
6541
+ const unixExternalUpper = (externalFileAttributes >> 16) & MAX_16_BITS;
6542
+ const symlink = unixMode !== UNDEFINED_VALUE && ((unixMode & FILE_ATTR_UNIX_TYPE_MASK) == FILE_ATTR_UNIX_TYPE_SYMLINK);
6327
6543
  return {
6328
6544
  name,
6329
6545
  resolvedOptions: {
6330
6546
  versionMadeBy,
6331
- msDosCompatible,
6547
+ msDosCompatible: Boolean(msDosCompatible),
6332
6548
  externalFileAttributes,
6333
6549
  unixExternalUpper,
6334
6550
  uid,
6335
6551
  gid,
6336
6552
  unixMode,
6337
6553
  unixExtraFieldType,
6554
+ symlink,
6338
6555
  setuid,
6339
6556
  setgid,
6340
6557
  sticky,
@@ -6345,7 +6562,7 @@ function resolveAttributes(zipWriter, name, options) {
6345
6562
  }
6346
6563
 
6347
6564
  function resolveMetadata(zipWriter, name, options) {
6348
- const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
6565
+ const encode = getFunctionOptionValue(zipWriter, options, OPTION_ENCODE_TEXT) || encodeText;
6349
6566
  let rawFilename = encode(name, TEXT_TYPE_FILENAME);
6350
6567
  if (rawFilename === UNDEFINED_VALUE) {
6351
6568
  rawFilename = encodeText(name);
@@ -6354,6 +6571,10 @@ function resolveMetadata(zipWriter, name, options) {
6354
6571
  throw new Error(ERR_INVALID_ENTRY_NAME);
6355
6572
  }
6356
6573
  const comment = options[PROPERTY_NAME_COMMENT] || "";
6574
+ // deno-lint-ignore valid-typeof
6575
+ if (typeof comment != STRING_TYPE) {
6576
+ throw new Error(ERR_INVALID_ENTRY_COMMENT_TYPE);
6577
+ }
6357
6578
  let rawComment = encode(comment, TEXT_TYPE_COMMENT);
6358
6579
  if (rawComment === UNDEFINED_VALUE) {
6359
6580
  rawComment = encodeText(comment);
@@ -6365,16 +6586,14 @@ function resolveMetadata(zipWriter, name, options) {
6365
6586
  if (version > MAX_16_BITS) {
6366
6587
  throw new Error(ERR_INVALID_VERSION);
6367
6588
  }
6368
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
6369
- const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
6370
- const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
6589
+ const lastModDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
6590
+ const lastAccessDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
6591
+ const creationDate = getDateOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
6371
6592
  const internalFileAttributes = getAliasedOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_DEPRECATED_INTERNAL_FILE_ATTRIBUTES, 0);
6372
6593
  const passThrough = getOptionValue(zipWriter, options, OPTION_PASS_THROUGH);
6373
6594
  const password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
6374
6595
  const rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
6375
- if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
6376
- throw new Error(ERR_INVALID_PASSWORD_TYPE);
6377
- }
6596
+ checkPasswordOption(password, rawPassword);
6378
6597
  const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
6379
6598
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
6380
6599
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
@@ -6383,9 +6602,9 @@ function resolveMetadata(zipWriter, name, options) {
6383
6602
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
6384
6603
  const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS);
6385
6604
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
6386
- const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6605
+ const createTempStream = getFunctionOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
6387
6606
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, true);
6388
- const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
6607
+ const signal = checkSignalOption(getOptionValue(zipWriter, options, OPTION_SIGNAL));
6389
6608
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
6390
6609
  const compressionMethod = getOptionValue(zipWriter, options, PROPERTY_NAME_COMPRESSION_METHOD);
6391
6610
  const registeredCodec = passThrough || compressionMethod === UNDEFINED_VALUE ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -6465,18 +6684,26 @@ function serializeExtraField(extraField) {
6465
6684
  if (!extraField) {
6466
6685
  return EMPTY_UINT8_ARRAY;
6467
6686
  }
6687
+ if (!(extraField instanceof Map)) {
6688
+ throw new Error(ERR_INVALID_EXTRAFIELD);
6689
+ }
6468
6690
  let extraFieldSize = 0;
6469
6691
  let offset = 0;
6470
- extraField.forEach(data => extraFieldSize += 4 + getLength(data));
6471
- const rawExtraField = new Uint8Array(extraFieldSize);
6472
- const rawExtraFieldView = getDataView(rawExtraField);
6473
6692
  extraField.forEach((data, type) => {
6474
- if (type > MAX_16_BITS) {
6693
+ if (!Number.isInteger(type) || type < 0 || type > MAX_16_BITS) {
6475
6694
  throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
6476
6695
  }
6696
+ if (!(data instanceof Uint8Array)) {
6697
+ throw new Error(ERR_INVALID_EXTRAFIELD_DATA_TYPE);
6698
+ }
6477
6699
  if (getLength(data) > MAX_16_BITS) {
6478
6700
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
6479
6701
  }
6702
+ extraFieldSize += 4 + getLength(data);
6703
+ });
6704
+ const rawExtraField = new Uint8Array(extraFieldSize);
6705
+ const rawExtraFieldView = getDataView(rawExtraField);
6706
+ extraField.forEach((data, type) => {
6480
6707
  setUint16(rawExtraFieldView, offset, type);
6481
6708
  setUint16(rawExtraFieldView, offset + 2, getLength(data));
6482
6709
  arraySet(rawExtraField, data, offset + 4);
@@ -6563,10 +6790,13 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6563
6790
  }
6564
6791
 
6565
6792
  async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comment) {
6566
- const zipWriter = { options: writerOptions, config: getConfiguration() };
6567
- if (writerOptions[OPTION_SIGN_CENTRAL_DIRECTORY]) {
6793
+ const zipWriter = { options: writerOptions };
6794
+ if (checkFunctionOption(writerOptions[OPTION_SIGN_CENTRAL_DIRECTORY])) {
6568
6795
  throw new Error(ERR_UNDETERMINED_SIZE);
6569
6796
  }
6797
+ if (comment !== UNDEFINED_VALUE && !(comment instanceof Uint8Array)) {
6798
+ throw new Error(ERR_INVALID_COMMENT_TYPE);
6799
+ }
6570
6800
  const commentLength = getLength(comment);
6571
6801
  if (commentLength > MAX_16_BITS) {
6572
6802
  throw new Error(ERR_INVALID_COMMENT);
@@ -6587,7 +6817,7 @@ async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comm
6587
6817
  ({ name } = attributesInfo);
6588
6818
  const { resolvedOptions: metadata } = resolveMetadata(zipWriter, name, options);
6589
6819
  if (metadata.level != 0 && metadata.compressionMethod === UNDEFINED_VALUE &&
6590
- !metadata.passThrough && !(await supportsDeflate(zipWriter.config))) {
6820
+ !metadata.passThrough && !(await supportsDeflate(getConfiguration()))) {
6591
6821
  metadata.level = 0;
6592
6822
  }
6593
6823
  const hasContent = !getOptionValue(zipWriter, options, PROPERTY_NAME_DIRECTORY);
@@ -6636,7 +6866,7 @@ async function getEntriesSize(writerOptions, entries, writeOrderGuaranteed, comm
6636
6866
 
6637
6867
  async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6638
6868
  const {
6639
- files,
6869
+ fileEntries,
6640
6870
  writer
6641
6871
  } = zipWriter;
6642
6872
  const {
@@ -6658,12 +6888,12 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6658
6888
  let writerSizeBeforeEntry;
6659
6889
  let flushedBufferedSize = 0;
6660
6890
  let fileWriter;
6661
- files.set(name, fileEntry);
6891
+ fileEntries.set(name, fileEntry);
6662
6892
  zipWriter.lastFileEntry = fileEntry;
6663
6893
  try {
6664
6894
  let lockPreviousFileEntry;
6665
6895
  if (keepOrder) {
6666
- lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
6896
+ lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6667
6897
  requestLockCurrentFileEntry();
6668
6898
  }
6669
6899
  if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
@@ -6684,11 +6914,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6684
6914
  const diskOffset = getDiskOffset(writer);
6685
6915
  if (zipWriter.addSplitZipSignature) {
6686
6916
  delete zipWriter.addSplitZipSignature;
6687
- const signatureArray = new Uint8Array(4);
6688
- const signatureArrayView = getDataView(signatureArray);
6689
- setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
6690
- await writeData(writer, signatureArray);
6691
- zipWriter.offset += 4;
6917
+ await writeData(writer, getSplitZipSignatureArray());
6918
+ zipWriter.offset += SPLIT_ZIP_FILE_SIGNATURE_LENGTH;
6692
6919
  }
6693
6920
  if (usdz && !bufferedWrite) {
6694
6921
  appendExtraFieldUSDZ(entryInfo, zipWriter.offset - diskOffset);
@@ -6706,11 +6933,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6706
6933
  writerSizeBeforeEntry = writer.size;
6707
6934
  await writeData(fileWriter, localHeaderArray);
6708
6935
  }
6709
- fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, zipWriter.config, options);
6936
+ fileEntry = await createFileEntry(reader, fileWriter, fileEntry, entryInfo, getConfiguration(), options);
6710
6937
  if (!bufferedWrite) {
6711
6938
  writingEntryData = false;
6712
6939
  }
6713
- files.set(name, fileEntry);
6940
+ fileEntries.set(name, fileEntry);
6714
6941
  fileEntry.filename = name;
6715
6942
  if (bufferedWrite) {
6716
6943
  await Promise.all([fileWriter.writable.getWriter().close(), lockPreviousFileEntry]);
@@ -6751,7 +6978,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6751
6978
  zipWriter.offset += flushedBufferedSize;
6752
6979
  }
6753
6980
  }
6754
- files.delete(name);
6981
+ fileEntries.delete(name);
6755
6982
  throw error;
6756
6983
  } finally {
6757
6984
  if (bufferedWrite) {
@@ -6773,7 +7000,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6773
7000
  }
6774
7001
 
6775
7002
  function requestLockCurrentFileEntry() {
6776
- fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
7003
+ fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
6777
7004
  }
6778
7005
 
6779
7006
  async function requestLockWriter() {
@@ -6793,7 +7020,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6793
7020
  }
6794
7021
  }
6795
7022
 
6796
- async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryInfo, config, options) {
7023
+ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry }, entryInfo, config, options) {
6797
7024
  const {
6798
7025
  headerInfo,
6799
7026
  dataDescriptorInfo,
@@ -6848,6 +7075,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6848
7075
  uid,
6849
7076
  gid,
6850
7077
  unixMode,
7078
+ symlink,
6851
7079
  setuid,
6852
7080
  setgid,
6853
7081
  sticky,
@@ -6860,7 +7088,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6860
7088
  codecURI
6861
7089
  } = options;
6862
7090
  const fileEntry = {
6863
- lock,
7091
+ lockFileEntry,
6864
7092
  versionMadeBy,
6865
7093
  zip64,
6866
7094
  directory: Boolean(directory),
@@ -6884,6 +7112,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6884
7112
  uid,
6885
7113
  gid,
6886
7114
  unixMode,
7115
+ symlink: Boolean(symlink),
6887
7116
  setuid,
6888
7117
  setgid,
6889
7118
  sticky,
@@ -6901,7 +7130,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6901
7130
  }
6902
7131
  const { writable } = writer;
6903
7132
  if (reader) {
6904
- const readable = toCompatibleReadable(reader.createReadable ? reader.createReadable() : reader.readable);
7133
+ const readable = toCompatibleReadable(createReadable(reader));
6905
7134
  const size = reader.size;
6906
7135
  const workerOptions = {
6907
7136
  options: {
@@ -6964,8 +7193,8 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6964
7193
  rawLastModDate,
6965
7194
  creationDate,
6966
7195
  lastAccessDate,
6967
- encrypted,
6968
- zipCrypto,
7196
+ encrypted: Boolean(encrypted),
7197
+ zipCrypto: Boolean(zipCrypto),
6969
7198
  size: metadataSize + compressedSize,
6970
7199
  compressionMethod,
6971
7200
  version,
@@ -7013,14 +7242,14 @@ function getHeaderInfo(options) {
7013
7242
  if (zip64 && (zip64UncompressedSize || zip64CompressedSize)) {
7014
7243
  const length = 4 + 16;
7015
7244
  const extraFieldZip64 = createRecordWriter(length);
7016
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
7017
- extraFieldZip64.uint16(length - 4);
7245
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
7246
+ extraFieldZip64.writeUint16(length - 4);
7018
7247
  rawLocalExtraFieldZip64 = extraFieldZip64.array;
7019
7248
  if (zip64ExtraFieldComplete) {
7020
- extraFieldZip64.uint64(uncompressedSize);
7249
+ extraFieldZip64.writeUint64(uncompressedSize);
7021
7250
  if (uncompressedFile) {
7022
7251
  const encryptionOverhead = encrypted ? (zipCrypto ? 12 : 16 + encryptionStrength * 4) : 0;
7023
- extraFieldZip64.uint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
7252
+ extraFieldZip64.writeUint64(passThrough ? 0 : uncompressedSize + encryptionOverhead);
7024
7253
  }
7025
7254
  }
7026
7255
  } else {
@@ -7029,8 +7258,8 @@ function getHeaderInfo(options) {
7029
7258
  let rawExtraFieldAES;
7030
7259
  if (encrypted && !zipCrypto) {
7031
7260
  const extraFieldAES = createRecordWriter(getLength(EXTRAFIELD_DATA_AES) + 2);
7032
- extraFieldAES.uint16(EXTRAFIELD_TYPE_AES);
7033
- extraFieldAES.bytes(EXTRAFIELD_DATA_AES);
7261
+ extraFieldAES.writeUint16(EXTRAFIELD_TYPE_AES);
7262
+ extraFieldAES.writeBytes(EXTRAFIELD_DATA_AES);
7034
7263
  rawExtraFieldAES = extraFieldAES.array;
7035
7264
  rawExtraFieldAES[8] = encryptionStrength;
7036
7265
  } else {
@@ -7046,15 +7275,15 @@ function getHeaderInfo(options) {
7046
7275
  const extraFieldTimestampLength = 9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0);
7047
7276
  const extraFieldTimestamp = createRecordWriter(extraFieldTimestampLength);
7048
7277
  extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
7049
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7050
- extraFieldTimestamp.uint16(extraFieldTimestampLength - 4);
7051
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
7052
- extraFieldTimestamp.uint32(lastModTimeUnix);
7278
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7279
+ extraFieldTimestamp.writeUint16(extraFieldTimestampLength - 4);
7280
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
7281
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
7053
7282
  if (lastAccessDate) {
7054
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(lastAccessDate)));
7283
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(lastAccessDate)));
7055
7284
  }
7056
7285
  if (creationDate) {
7057
- extraFieldTimestamp.uint32(clampUnixTime(getTimeUnix(creationDate)));
7286
+ extraFieldTimestamp.writeUint32(clampUnixTime(getTimeUnix(creationDate)));
7058
7287
  }
7059
7288
  rawExtraFieldExtendedTimestamp = extraFieldTimestamp.array;
7060
7289
  } else {
@@ -7067,14 +7296,14 @@ function getHeaderInfo(options) {
7067
7296
  try {
7068
7297
  const lastModTimeNTFS = getTimeNTFS(lastModDate);
7069
7298
  const extraFieldNTFS = createRecordWriter(36);
7070
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS);
7071
- extraFieldNTFS.uint16(32);
7299
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS);
7300
+ extraFieldNTFS.writeUint16(32);
7072
7301
  extraFieldNTFS.skip(4);
7073
- extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
7074
- extraFieldNTFS.uint16(24);
7075
- extraFieldNTFS.uint64(lastModTimeNTFS);
7076
- extraFieldNTFS.uint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
7077
- extraFieldNTFS.uint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
7302
+ extraFieldNTFS.writeUint16(EXTRAFIELD_TYPE_NTFS_TAG1);
7303
+ extraFieldNTFS.writeUint16(24);
7304
+ extraFieldNTFS.writeUint64(lastModTimeNTFS);
7305
+ extraFieldNTFS.writeUint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
7306
+ extraFieldNTFS.writeUint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
7078
7307
  rawExtraFieldNTFS = extraFieldNTFS.array;
7079
7308
  } catch {
7080
7309
  rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
@@ -7093,20 +7322,20 @@ function getHeaderInfo(options) {
7093
7322
  const gidBytes = packUnixId(gid);
7094
7323
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7095
7324
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7096
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_INFOZIP);
7097
- extraFieldUnix.uint16(payloadLength);
7098
- extraFieldUnix.uint8(1);
7099
- extraFieldUnix.uint8(uidBytes.length);
7100
- extraFieldUnix.bytes(uidBytes);
7101
- extraFieldUnix.uint8(gidBytes.length);
7102
- extraFieldUnix.bytes(gidBytes);
7325
+ extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
7326
+ extraFieldUnix.writeUint16(payloadLength);
7327
+ extraFieldUnix.writeUint8(1);
7328
+ extraFieldUnix.writeUint8(uidBytes.length);
7329
+ extraFieldUnix.writeBytes(uidBytes);
7330
+ extraFieldUnix.writeUint8(gidBytes.length);
7331
+ extraFieldUnix.writeBytes(gidBytes);
7103
7332
  rawExtraFieldUnix = extraFieldUnix.array;
7104
7333
  } else if (unixExtraFieldType == UNIX_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7105
7334
  const extraFieldUnix = createRecordWriter(8);
7106
- extraFieldUnix.uint16(EXTRAFIELD_TYPE_UNIX);
7107
- extraFieldUnix.uint16(4);
7108
- extraFieldUnix.uint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
7109
- extraFieldUnix.uint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
7335
+ extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_UNIX);
7336
+ extraFieldUnix.writeUint16(4);
7337
+ extraFieldUnix.writeUint16((uid === UNDEFINED_VALUE ? 0 : uid) & MAX_16_BITS);
7338
+ extraFieldUnix.writeUint16((gid === UNDEFINED_VALUE ? 0 : gid) & MAX_16_BITS);
7110
7339
  rawExtraFieldUnix = extraFieldUnix.array;
7111
7340
  } else {
7112
7341
  rawExtraFieldUnix = EMPTY_UINT8_ARRAY;
@@ -7156,18 +7385,18 @@ function getHeaderInfo(options) {
7156
7385
  const localHeader = createRecordWriter(HEADER_SIZE + getLength(rawFilename) + extraFieldLength);
7157
7386
  const localHeaderArray = localHeader.array;
7158
7387
  const localHeaderView = getDataView(localHeaderArray);
7159
- localHeader.uint32(LOCAL_FILE_HEADER_SIGNATURE);
7160
- localHeader.bytes(headerArray);
7161
- localHeader.bytes(rawFilename);
7388
+ localHeader.writeUint32(LOCAL_FILE_HEADER_SIGNATURE);
7389
+ localHeader.writeBytes(headerArray);
7390
+ localHeader.writeBytes(rawFilename);
7162
7391
  if (writeLocalExtraFieldZip64) {
7163
- localHeader.bytes(rawLocalExtraFieldZip64);
7164
- }
7165
- localHeader.bytes(rawExtraFieldAES);
7166
- localHeader.bytes(rawExtraFieldExtendedTimestamp);
7167
- localHeader.bytes(rawExtraFieldNTFS);
7168
- localHeader.bytes(rawExtraFieldUnix);
7169
- localHeader.bytes(rawExtraField);
7170
- localHeader.bytes(rawLocalExtraField);
7392
+ localHeader.writeBytes(rawLocalExtraFieldZip64);
7393
+ }
7394
+ localHeader.writeBytes(rawExtraFieldAES);
7395
+ localHeader.writeBytes(rawExtraFieldExtendedTimestamp);
7396
+ localHeader.writeBytes(rawExtraFieldNTFS);
7397
+ localHeader.writeBytes(rawExtraFieldUnix);
7398
+ localHeader.writeBytes(rawExtraField);
7399
+ localHeader.writeBytes(rawLocalExtraField);
7171
7400
  if (dataDescriptor) {
7172
7401
  if (!zip64CompressedSize) {
7173
7402
  setUint32(localHeaderView, HEADER_OFFSET_COMPRESSED_SIZE + LOCAL_HEADER_COMMON_OFFSET, 0);
@@ -7357,7 +7586,7 @@ function updateLocalHeader({
7357
7586
 
7358
7587
 
7359
7588
  async function closeFile(zipWriter, comment, options) {
7360
- const directoryDataLength = createDirectoryRecords(zipWriter.files);
7589
+ const directoryDataLength = createDirectoryRecords(zipWriter.fileEntries);
7361
7590
  const { directoryStart, directoryArray } = await writeDirectoryRecords(zipWriter, directoryDataLength, options);
7362
7591
  const signatureLength = await writeDigitalSignatureRecord(zipWriter, directoryArray, options);
7363
7592
  await writeEndOfDirectoryRecord(zipWriter, comment, options, { directoryStart, directoryDataLength, signatureLength });
@@ -7387,19 +7616,19 @@ function createDirectoryRecords(files) {
7387
7616
  if (zip64Offset || zip64DiskNumberStart || zip64UncompressedSize || zip64CompressedSize) {
7388
7617
  const length = 4 + (zip64UncompressedSize ? 8 : 0) + (zip64CompressedSize ? 8 : 0) + (zip64Offset ? 8 : 0) + (zip64DiskNumberStart ? 4 : 0);
7389
7618
  const extraFieldZip64 = createRecordWriter(length);
7390
- extraFieldZip64.uint16(EXTRAFIELD_TYPE_ZIP64);
7391
- extraFieldZip64.uint16(length - 4);
7619
+ extraFieldZip64.writeUint16(EXTRAFIELD_TYPE_ZIP64);
7620
+ extraFieldZip64.writeUint16(length - 4);
7392
7621
  if (zip64UncompressedSize) {
7393
- extraFieldZip64.uint64(uncompressedSize);
7622
+ extraFieldZip64.writeUint64(uncompressedSize);
7394
7623
  }
7395
7624
  if (zip64CompressedSize) {
7396
- extraFieldZip64.uint64(compressedSize);
7625
+ extraFieldZip64.writeUint64(compressedSize);
7397
7626
  }
7398
7627
  if (zip64Offset) {
7399
- extraFieldZip64.uint64(fileEntry.offset);
7628
+ extraFieldZip64.writeUint64(fileEntry.offset);
7400
7629
  }
7401
7630
  if (zip64DiskNumberStart) {
7402
- extraFieldZip64.uint32(fileEntry.diskNumberStart);
7631
+ extraFieldZip64.writeUint32(fileEntry.diskNumberStart);
7403
7632
  }
7404
7633
  rawExtraFieldZip64 = extraFieldZip64.array;
7405
7634
  } else {
@@ -7412,10 +7641,10 @@ function createDirectoryRecords(files) {
7412
7641
  const lastModTimeUnix = getTimeUnix(lastModDate);
7413
7642
  if (extendedTimestamp && inUnixTimeRange(lastModTimeUnix)) {
7414
7643
  const extraFieldTimestamp = createRecordWriter(9);
7415
- extraFieldTimestamp.uint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7416
- extraFieldTimestamp.uint16(5);
7417
- extraFieldTimestamp.uint8(extraFieldExtendedTimestampFlag);
7418
- extraFieldTimestamp.uint32(lastModTimeUnix);
7644
+ extraFieldTimestamp.writeUint16(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
7645
+ extraFieldTimestamp.writeUint16(5);
7646
+ extraFieldTimestamp.writeUint8(extraFieldExtendedTimestampFlag);
7647
+ extraFieldTimestamp.writeUint32(lastModTimeUnix);
7419
7648
  rawExtraFieldTimestamp = extraFieldTimestamp.array;
7420
7649
  } else {
7421
7650
  rawExtraFieldTimestamp = EMPTY_UINT8_ARRAY;
@@ -7437,14 +7666,14 @@ function createDirectoryRecords(files) {
7437
7666
  }
7438
7667
 
7439
7668
  async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7440
- const { files, writer } = zipWriter;
7669
+ const { fileEntries, writer } = zipWriter;
7441
7670
  const directoryArray = new Uint8Array(directoryDataLength);
7442
7671
  await initStream(writer);
7443
7672
  let offset = 0;
7444
7673
  let directoryDiskOffset = 0;
7445
7674
  let directoryStartDiskNumber = getDiskNumber(writer);
7446
7675
  let directoryStartDiskOffset = getDiskOffset(writer);
7447
- for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
7676
+ for (const [indexFileEntry, fileEntry] of Array.from(fileEntries.values()).entries()) {
7448
7677
  const {
7449
7678
  offset: fileEntryOffset,
7450
7679
  rawFilename,
@@ -7489,28 +7718,28 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7489
7718
  setUint16(headerView, HEADER_OFFSET_VERSION, VERSION_ZIP64);
7490
7719
  }
7491
7720
  const directoryRecord = createRecordWriter(directoryRecordLength);
7492
- directoryRecord.uint32(CENTRAL_FILE_HEADER_SIGNATURE);
7493
- directoryRecord.uint16(versionMadeBy);
7494
- directoryRecord.bytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
7495
- directoryRecord.uint16(extraFieldLength);
7496
- directoryRecord.uint16(getLength(rawComment));
7497
- directoryRecord.uint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
7498
- directoryRecord.uint16(internalFileAttributes);
7499
- directoryRecord.uint32(externalFileAttributes);
7500
- directoryRecord.uint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
7501
- directoryRecord.bytes(rawFilename);
7502
- directoryRecord.bytes(rawExtraFieldZip64);
7503
- directoryRecord.bytes(rawExtraFieldAES);
7504
- directoryRecord.bytes(rawExtraFieldExtendedTimestamp);
7505
- directoryRecord.bytes(rawExtraFieldNTFS);
7506
- directoryRecord.bytes(rawExtraFieldUnix);
7507
- directoryRecord.bytes(rawExtraField);
7508
- directoryRecord.bytes(rawComment);
7721
+ directoryRecord.writeUint32(CENTRAL_FILE_HEADER_SIGNATURE);
7722
+ directoryRecord.writeUint16(versionMadeBy);
7723
+ directoryRecord.writeBytes(headerArray.subarray(0, HEADER_SIZE - 4 - 2));
7724
+ directoryRecord.writeUint16(extraFieldLength);
7725
+ directoryRecord.writeUint16(getLength(rawComment));
7726
+ directoryRecord.writeUint16(zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
7727
+ directoryRecord.writeUint16(internalFileAttributes);
7728
+ directoryRecord.writeUint32(externalFileAttributes);
7729
+ directoryRecord.writeUint32(zip64Offset ? MAX_32_BITS : fileEntryOffset);
7730
+ directoryRecord.writeBytes(rawFilename);
7731
+ directoryRecord.writeBytes(rawExtraFieldZip64);
7732
+ directoryRecord.writeBytes(rawExtraFieldAES);
7733
+ directoryRecord.writeBytes(rawExtraFieldExtendedTimestamp);
7734
+ directoryRecord.writeBytes(rawExtraFieldNTFS);
7735
+ directoryRecord.writeBytes(rawExtraFieldUnix);
7736
+ directoryRecord.writeBytes(rawExtraField);
7737
+ directoryRecord.writeBytes(rawComment);
7509
7738
  arraySet(directoryArray, directoryRecord.array, offset);
7510
7739
  offset += directoryRecordLength;
7511
7740
  if (options.onprogress) {
7512
7741
  try {
7513
- await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
7742
+ await options.onprogress(indexFileEntry + 1, fileEntries.size, new Entry(fileEntry));
7514
7743
  } catch {
7515
7744
  // ignored
7516
7745
  }
@@ -7524,7 +7753,7 @@ async function writeDirectoryRecords(zipWriter, directoryDataLength, options) {
7524
7753
  }
7525
7754
 
7526
7755
  async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7527
- const signCentralDirectory = getOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7756
+ const signCentralDirectory = getFunctionOptionValue(zipWriter, options, OPTION_SIGN_CENTRAL_DIRECTORY);
7528
7757
  if (signCentralDirectory) {
7529
7758
  const signatureData = await signCentralDirectory(directoryArray);
7530
7759
  const signatureDataLength = getLength(signatureData);
@@ -7532,9 +7761,9 @@ async function writeDigitalSignatureRecord(zipWriter, directoryArray, options) {
7532
7761
  throw new Error(ERR_INVALID_SIGNATURE_DATA);
7533
7762
  }
7534
7763
  const signatureRecord = createRecordWriter(6 + signatureDataLength);
7535
- signatureRecord.uint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7536
- signatureRecord.uint16(signatureDataLength);
7537
- signatureRecord.bytes(signatureData);
7764
+ signatureRecord.writeUint32(DIGITAL_SIGNATURE_RECORD_SIGNATURE);
7765
+ signatureRecord.writeUint16(signatureDataLength);
7766
+ signatureRecord.writeBytes(signatureData);
7538
7767
  await writeData(zipWriter.writer, signatureRecord.array);
7539
7768
  return 6 + signatureDataLength;
7540
7769
  }
@@ -7545,7 +7774,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7545
7774
  const { writer } = zipWriter;
7546
7775
  const { directoryStart, signatureLength } = cdInfo;
7547
7776
  let { directoryDataLength } = cdInfo;
7548
- let filesLength = zipWriter.files.size;
7777
+ let fileEntriesLength = zipWriter.fileEntries.size;
7549
7778
  let diskNumber = directoryStart.diskNumber;
7550
7779
  let directoryOffset = getSegmentOffset(zipWriter, directoryStart);
7551
7780
  let lastDiskNumber = getDiskNumber(writer);
@@ -7553,7 +7782,7 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7553
7782
  lastDiskNumber++;
7554
7783
  }
7555
7784
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
7556
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
7785
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || fileEntriesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
7557
7786
  if (zip64 === false) {
7558
7787
  throw new Error(ERR_UNSUPPORTED_FORMAT);
7559
7788
  } else {
@@ -7570,37 +7799,37 @@ async function writeEndOfDirectoryRecord(zipWriter, comment, options, cdInfo) {
7570
7799
  }
7571
7800
  lastDiskNumber = getDiskNumber(writer);
7572
7801
  if (zip64) {
7573
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
7574
- endOfdirectoryRecord.uint64(44);
7575
- endOfdirectoryRecord.uint16(45);
7576
- endOfdirectoryRecord.uint16(45);
7577
- endOfdirectoryRecord.uint32(lastDiskNumber);
7578
- endOfdirectoryRecord.uint32(diskNumber);
7579
- endOfdirectoryRecord.uint64(filesLength);
7580
- endOfdirectoryRecord.uint64(filesLength);
7581
- endOfdirectoryRecord.uint64(directoryDataLength);
7582
- endOfdirectoryRecord.uint64(directoryOffset);
7583
- endOfdirectoryRecord.uint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7584
- endOfdirectoryRecord.uint32(lastDiskNumber);
7585
- endOfdirectoryRecord.uint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7586
- endOfdirectoryRecord.uint32(lastDiskNumber + 1);
7802
+ endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
7803
+ endOfdirectoryRecord.writeUint64(44);
7804
+ endOfdirectoryRecord.writeUint16(45);
7805
+ endOfdirectoryRecord.writeUint16(45);
7806
+ endOfdirectoryRecord.writeUint32(lastDiskNumber);
7807
+ endOfdirectoryRecord.writeUint32(diskNumber);
7808
+ endOfdirectoryRecord.writeUint64(fileEntriesLength);
7809
+ endOfdirectoryRecord.writeUint64(fileEntriesLength);
7810
+ endOfdirectoryRecord.writeUint64(directoryDataLength);
7811
+ endOfdirectoryRecord.writeUint64(directoryOffset);
7812
+ endOfdirectoryRecord.writeUint32(ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
7813
+ endOfdirectoryRecord.writeUint32(lastDiskNumber);
7814
+ endOfdirectoryRecord.writeUint64(BigInt(getSegmentOffset(zipWriter, writer)) + BigInt(directoryDataLength) + BigInt(signatureLength));
7815
+ endOfdirectoryRecord.writeUint32(lastDiskNumber + 1);
7587
7816
  const supportZip64SplitFile = getOptionValue(zipWriter, options, OPTION_SUPPORT_ZIP64_SPLIT_FILE, true);
7588
7817
  if (supportZip64SplitFile) {
7589
7818
  lastDiskNumber = MAX_16_BITS;
7590
7819
  diskNumber = MAX_16_BITS;
7591
7820
  }
7592
- filesLength = MAX_16_BITS;
7821
+ fileEntriesLength = MAX_16_BITS;
7593
7822
  directoryOffset = MAX_32_BITS;
7594
7823
  directoryDataLength = MAX_32_BITS;
7595
7824
  }
7596
- endOfdirectoryRecord.uint32(END_OF_CENTRAL_DIR_SIGNATURE);
7597
- endOfdirectoryRecord.uint16(lastDiskNumber);
7598
- endOfdirectoryRecord.uint16(diskNumber);
7599
- endOfdirectoryRecord.uint16(filesLength);
7600
- endOfdirectoryRecord.uint16(filesLength);
7601
- endOfdirectoryRecord.uint32(directoryDataLength);
7602
- endOfdirectoryRecord.uint32(directoryOffset);
7603
- endOfdirectoryRecord.uint16(commentLength);
7825
+ endOfdirectoryRecord.writeUint32(END_OF_CENTRAL_DIR_SIGNATURE);
7826
+ endOfdirectoryRecord.writeUint16(lastDiskNumber);
7827
+ endOfdirectoryRecord.writeUint16(diskNumber);
7828
+ endOfdirectoryRecord.writeUint16(fileEntriesLength);
7829
+ endOfdirectoryRecord.writeUint16(fileEntriesLength);
7830
+ endOfdirectoryRecord.writeUint32(directoryDataLength);
7831
+ endOfdirectoryRecord.writeUint32(directoryOffset);
7832
+ endOfdirectoryRecord.writeUint16(commentLength);
7604
7833
  await writeData(writer, endOfdirectoryRecord.array);
7605
7834
  if (commentLength) {
7606
7835
  await writeData(writer, comment);
@@ -7613,11 +7842,11 @@ function createRecordWriter(length) {
7613
7842
  let offset = 0;
7614
7843
  return {
7615
7844
  array,
7616
- uint8: value => { setUint8(view, offset, value); offset += 1; },
7617
- uint16: value => { setUint16(view, offset, value); offset += 2; },
7618
- uint32: value => { setUint32(view, offset, value); offset += 4; },
7619
- uint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7620
- bytes: value => { arraySet(array, value, offset); offset += getLength(value); },
7845
+ writeUint8: value => { setUint8(view, offset, value); offset += 1; },
7846
+ writeUint16: value => { setUint16(view, offset, value); offset += 2; },
7847
+ writeUint32: value => { setUint32(view, offset, value); offset += 4; },
7848
+ writeUint64: value => { setBigUint64(view, offset, BigInt(value)); offset += 8; },
7849
+ writeBytes: value => { arraySet(array, value, offset); offset += getLength(value); },
7621
7850
  skip: count => offset += count
7622
7851
  };
7623
7852
  }
@@ -7641,6 +7870,71 @@ function getSegmentOffset(zipWriter, { diskNumber = 0, diskOffset = 0 }) {
7641
7870
  return zipWriter.offset - diskOffset - (diskNumber ? zipWriter.initialOffset : 0);
7642
7871
  }
7643
7872
 
7873
+ async function startsWithSplitZipSignature(reader) {
7874
+ const signatureArray = await readUint8Array(reader, 0, SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
7875
+ return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7876
+ }
7877
+
7878
+ async function copyZipData(zipWriter, reader, entries, directoryOffset, splitZipSignatureLength) {
7879
+ const { writer } = zipWriter;
7880
+ const entryPositions = new Map();
7881
+ if (writer.closeDisk) {
7882
+ const sortedEntries = Array.from(entries).sort((firstEntry, secondEntry) =>
7883
+ getSourceOffset(reader, firstEntry) - getSourceOffset(reader, secondEntry));
7884
+ let copiedLength = 0;
7885
+ for (const entry of sortedEntries) {
7886
+ const sourceOffset = getSourceOffset(reader, entry);
7887
+ await copyData(zipWriter, reader, copiedLength, sourceOffset - copiedLength);
7888
+ if (exceedsAvailableSize(writer, await getLocalHeaderLength(reader, sourceOffset))) {
7889
+ await writer.closeDisk();
7890
+ }
7891
+ entryPositions.set(entry, {
7892
+ offset: getSegmentOffset(zipWriter, writer),
7893
+ diskNumberStart: getDiskNumber(writer)
7894
+ });
7895
+ copiedLength = sourceOffset;
7896
+ }
7897
+ await copyData(zipWriter, reader, copiedLength, directoryOffset - copiedLength);
7898
+ } else {
7899
+ await copyData(zipWriter, reader, 0, directoryOffset);
7900
+ entries.forEach(entry => entryPositions.set(entry, {
7901
+ offset: splitZipSignatureLength + getSourceOffset(reader, entry),
7902
+ diskNumberStart: 0
7903
+ }));
7904
+ }
7905
+ return entryPositions;
7906
+ }
7907
+
7908
+ async function copyData(zipWriter, reader, offset, size) {
7909
+ if (size > 0) {
7910
+ const { writer } = zipWriter;
7911
+ await createReadable(reader, { offset, size }).pipeTo(writer.writable, { preventClose: true, preventAbort: true });
7912
+ writer.size += size;
7913
+ zipWriter.offset += size;
7914
+ }
7915
+ }
7916
+
7917
+ async function getLocalHeaderLength(reader, offset) {
7918
+ const headerArray = await readUint8Array(reader, offset, HEADER_SIZE);
7919
+ if (getLength(headerArray) < HEADER_SIZE) {
7920
+ return HEADER_SIZE;
7921
+ }
7922
+ const headerView = getDataView(headerArray);
7923
+ return HEADER_SIZE +
7924
+ getUint16(headerView, HEADER_OFFSET_FILENAME_LENGTH + LOCAL_HEADER_COMMON_OFFSET) +
7925
+ getUint16(headerView, HEADER_OFFSET_EXTRAFIELD_LENGTH + LOCAL_HEADER_COMMON_OFFSET);
7926
+ }
7927
+
7928
+ function getSourceOffset(reader, { offset, diskNumberStart }) {
7929
+ return offset + (reader.getDiskOffset ? reader.getDiskOffset(diskNumberStart) : 0);
7930
+ }
7931
+
7932
+ function getSplitZipSignatureArray() {
7933
+ const signatureArray = new Uint8Array(SPLIT_ZIP_FILE_SIGNATURE_LENGTH);
7934
+ setUint32(getDataView(signatureArray), 0, SPLIT_ZIP_FILE_SIGNATURE);
7935
+ return signatureArray;
7936
+ }
7937
+
7644
7938
  async function writeData(writer, array) {
7645
7939
  const { writable } = writer;
7646
7940
  const streamWriter = writable.getWriter();
@@ -7692,6 +7986,21 @@ function getOptionValue(zipWriter, options, name, defaultValue) {
7692
7986
  return result === UNDEFINED_VALUE ? defaultValue : result;
7693
7987
  }
7694
7988
 
7989
+ function getDateOptionValue(zipWriter, options, name, defaultValue) {
7990
+ const date = getOptionValue(zipWriter, options, name, defaultValue);
7991
+ if (date === null) {
7992
+ return defaultValue;
7993
+ }
7994
+ if (date !== UNDEFINED_VALUE && (typeof date.getTime != FUNCTION_TYPE || Number.isNaN(date.getTime()))) {
7995
+ throw new Error(ERR_INVALID_DATE);
7996
+ }
7997
+ return date;
7998
+ }
7999
+
8000
+ function getFunctionOptionValue(zipWriter, options, name) {
8001
+ return checkFunctionOption(getOptionValue(zipWriter, options, name));
8002
+ }
8003
+
7695
8004
  function getAliasedOptionValue(zipWriter, options, name, deprecatedName, defaultValue) {
7696
8005
  const value = getAliasedValue(options, name, deprecatedName);
7697
8006
  const result = value === UNDEFINED_VALUE ? getAliasedValue(zipWriter.options, name, deprecatedName) : value;
@@ -7706,9 +8015,6 @@ function getNumberOptionValue(zipWriter, options, name, defaultValue) {
7706
8015
  return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
7707
8016
  }
7708
8017
 
7709
- function toNumber(value) {
7710
- return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
7711
- }
7712
8018
 
7713
8019
  function getMaximumCompressedSize(uncompressedSize) {
7714
8020
  return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
@@ -7720,6 +8026,14 @@ function isCompressed(compressionMethod, level) {
7720
8026
  : compressionMethod !== COMPRESSION_METHOD_STORE;
7721
8027
  }
7722
8028
 
8029
+ function getUint16(view, offset) {
8030
+ return view.getUint16(offset, true);
8031
+ }
8032
+
8033
+ function getUint32(view, offset) {
8034
+ return view.getUint32(offset, true);
8035
+ }
8036
+
7723
8037
  function setUint8(view, offset, value) {
7724
8038
  view.setUint8(offset, value);
7725
8039
  }
@@ -7763,9 +8077,9 @@ function getHeaderArrayData({
7763
8077
  const headerRecord = createRecordWriter(HEADER_SIZE - 4);
7764
8078
  const headerArray = headerRecord.array;
7765
8079
  const headerView = getDataView(headerArray);
7766
- headerRecord.uint16(version);
7767
- headerRecord.uint16(bitFlag);
7768
- headerRecord.uint16(compressionMethod);
8080
+ headerRecord.writeUint16(version);
8081
+ headerRecord.writeUint16(bitFlag);
8082
+ headerRecord.writeUint16(compressionMethod);
7769
8083
  if (rawLastModDate === UNDEFINED_VALUE) {
7770
8084
  const dateArray = new Uint32Array(1);
7771
8085
  const dateView = getDataView(dateArray);
@@ -7773,20 +8087,20 @@ function getHeaderArrayData({
7773
8087
  setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
7774
8088
  rawLastModDate = dateArray[0];
7775
8089
  }
7776
- headerRecord.uint32(rawLastModDate);
8090
+ headerRecord.writeUint32(rawLastModDate);
7777
8091
  headerRecord.skip(4);
7778
8092
  if (zip64CompressedSize || compressedSize !== UNDEFINED_VALUE) {
7779
- headerRecord.uint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
8093
+ headerRecord.writeUint32(zip64CompressedSize ? MAX_32_BITS : compressedSize);
7780
8094
  } else {
7781
8095
  headerRecord.skip(4);
7782
8096
  }
7783
8097
  if (zip64UncompressedSize || uncompressedSize !== UNDEFINED_VALUE) {
7784
- headerRecord.uint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
8098
+ headerRecord.writeUint32(zip64UncompressedSize ? MAX_32_BITS : uncompressedSize);
7785
8099
  } else {
7786
8100
  headerRecord.skip(4);
7787
8101
  }
7788
- headerRecord.uint16(getLength(rawFilename));
7789
- headerRecord.uint16(extraFieldLength);
8102
+ headerRecord.writeUint16(getLength(rawFilename));
8103
+ headerRecord.writeUint16(extraFieldLength);
7790
8104
  return {
7791
8105
  headerArray,
7792
8106
  headerView,
@@ -8734,6 +9048,7 @@ U(setDefaultConfiguration);
8734
9048
  const ERR_ENTRY_EXISTS = "Entry filename already exists";
8735
9049
  const ERR_READABLE_CONSUMED = "Readable stream already consumed";
8736
9050
  const ERR_INVALID_PASS_THROUGH = "Invalid passThrough option (use readerOptions.passThrough or set uncompressedSize for each entry)";
9051
+ const ERR_INVALID_READER_OPTIONS = "Invalid readerOptions (must be an object)";
8737
9052
  const ERR_ABORT_EXPORT = "zipjs-abort-export";
8738
9053
  const ERR_ABORTED = "The operation was aborted";
8739
9054
  const ABORT_ERROR_NAME = "AbortError";
@@ -8766,13 +9081,14 @@ class ZipEntry {
8766
9081
  fs,
8767
9082
  name,
8768
9083
  data: params.data,
8769
- options: params.options,
9084
+ options: params.options && Object.assign({}, params.options),
8770
9085
  id: fs.entryIdCounter++,
8771
9086
  parent,
8772
9087
  children: [],
8773
9088
  uncompressedSize: params.uncompressedSize || 0,
8774
9089
  undeterminedSize: params.undeterminedSize || params.uncompressedSize === UNDEFINED_VALUE,
8775
- passThrough: params.passThrough
9090
+ passThrough: params.passThrough,
9091
+ defaultLastModDate: params.defaultLastModDate || new Date()
8776
9092
  });
8777
9093
  if (parent || !fs.root) {
8778
9094
  fs.entries[zipEntry.id] = zipEntry;
@@ -8782,12 +9098,6 @@ class ZipEntry {
8782
9098
  }
8783
9099
  }
8784
9100
 
8785
- moveTo(target) {
8786
- // deprecated
8787
- const zipEntry = this;
8788
- zipEntry.fs.move(zipEntry, target);
8789
- }
8790
-
8791
9101
  getFullname() {
8792
9102
  return this.getRelativeName();
8793
9103
  }
@@ -8819,6 +9129,11 @@ class ZipEntry {
8819
9129
  this.name = name;
8820
9130
  }
8821
9131
  }
9132
+
9133
+ setOptions(options) {
9134
+ const entryOptions = Object.assign({}, this.options, options);
9135
+ this.options = Object.fromEntries(Object.entries(entryOptions).filter(([, value]) => value !== UNDEFINED_VALUE));
9136
+ }
8822
9137
  }
8823
9138
 
8824
9139
  class ZipFileEntry extends ZipEntry {
@@ -8845,7 +9160,7 @@ class ZipFileEntry extends ZipEntry {
8845
9160
  const reader = zipEntry.reader = createReader(zipEntry.Reader, zipEntry.data, options);
8846
9161
  const dataSize = zipEntry.uncompressedSize || reader.size;
8847
9162
  await Promise.all([initStream(reader), initStream(writer, dataSize)]);
8848
- const { signal } = options;
9163
+ const signal = checkSignalOption(options.signal);
8849
9164
  const readable = createProgressReadable(zipEntry, reader, options, signal);
8850
9165
  const preventClose = !ownsWritable(writer) && Boolean(options.preventClose);
8851
9166
  zipEntry.uncompressedSize = reader.size;
@@ -9063,10 +9378,6 @@ class ZipDirectoryEntry extends ZipEntry {
9063
9378
  });
9064
9379
  }
9065
9380
 
9066
- addData(name, params) {
9067
- return addChild(this, name, params);
9068
- }
9069
-
9070
9381
  importBlob(blob, options) {
9071
9382
  return this.importZip(new BlobReader(blob), options);
9072
9383
  }
@@ -9180,7 +9491,7 @@ class ZipDirectoryEntry extends ZipEntry {
9180
9491
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9181
9492
  options.bufferedWrite = true;
9182
9493
  }
9183
- const [readers] = await Promise.all([initReaders(zipEntry, options.readerOptions), initStream(writer)]);
9494
+ const [readers] = await Promise.all([initReaders(zipEntry, checkReaderOptions(options.readerOptions)), initStream(writer)]);
9184
9495
  const zipWriter = new ZipWriter(writer, options);
9185
9496
  await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry], getUncompressedSize), options, readers);
9186
9497
  await zipWriter.close(options.globalComment);
@@ -9190,12 +9501,13 @@ class ZipDirectoryEntry extends ZipEntry {
9190
9501
  getExportedSize(options = {}) {
9191
9502
  const zipEntry = this;
9192
9503
  options = Object.assign({}, options);
9504
+ checkReaderOptions(options.readerOptions);
9193
9505
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9194
9506
  options.bufferedWrite = true;
9195
9507
  }
9196
9508
  const writeOrderGuaranteed = !options.bufferedWrite ||
9197
9509
  (options.keepOrder !== false && zipEntry.children.every(child => !child.children.length));
9198
- return getEntriesSize(options, Array.from(zipEntry.getChildren({ recursive: true }), child => {
9510
+ return getEntriesSize(options, zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9199
9511
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
9200
9512
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
9201
9513
  }), writeOrderGuaranteed, options.globalComment);
@@ -9234,7 +9546,7 @@ class ZipDirectoryEntry extends ZipEntry {
9234
9546
  }
9235
9547
 
9236
9548
 
9237
- class FS {
9549
+ class ZipFS {
9238
9550
 
9239
9551
  constructor() {
9240
9552
  resetFS(this);
@@ -9350,10 +9662,6 @@ class FS {
9350
9662
  return this.root.addFile(file, options);
9351
9663
  }
9352
9664
 
9353
- addData(name, params) {
9354
- return this.root.addData(name, params);
9355
- }
9356
-
9357
9665
  importBlob(blob, options) {
9358
9666
  resetFS(this);
9359
9667
  return this.root.importBlob(blob, options);
@@ -9421,7 +9729,7 @@ class FS {
9421
9729
  }
9422
9730
  }
9423
9731
 
9424
- const fs = { FS, ZipDirectoryEntry, ZipFileEntry };
9732
+ const fs = { FS: ZipFS, ZipDirectoryEntry, ZipFileEntry };
9425
9733
 
9426
9734
  function getTotalSize(entries, getEntrySize) {
9427
9735
  let size = 0;
@@ -9565,7 +9873,7 @@ function detach(entry) {
9565
9873
  }
9566
9874
 
9567
9875
  function forwardAbort(signal, abortController) {
9568
- if (!signal) {
9876
+ if (!checkSignalOption(signal)) {
9569
9877
  return () => { };
9570
9878
  }
9571
9879
  if (signal.aborted) {
@@ -9661,7 +9969,7 @@ function getChildEntryOptions(child, selectedEntry, options) {
9661
9969
  };
9662
9970
  }
9663
9971
  }
9664
- const entryOptions = Object.assign({}, zipEntryMetadata, options, passThroughOptions, childOptions, { directory: child.directory });
9972
+ const entryOptions = Object.assign({ lastModDate: child.defaultLastModDate }, zipEntryMetadata, options, childOptions, passThroughOptions, { directory: child.directory });
9665
9973
  if (!child.directory && entryOptions.passThrough && entryOptions.uncompressedSize === UNDEFINED_VALUE) {
9666
9974
  throw new Error(ERR_INVALID_PASS_THROUGH);
9667
9975
  }
@@ -9676,11 +9984,22 @@ function getDeterminedSize(child, passThrough) {
9676
9984
  return child.undeterminedSize ? UNDEFINED_VALUE : getExtractedSize(child, passThrough);
9677
9985
  }
9678
9986
 
9987
+ function checkReaderOptions(readerOptions) {
9988
+ if (readerOptions && (typeof readerOptions != OBJECT_TYPE || Array.isArray(readerOptions))) {
9989
+ throw new Error(ERR_INVALID_READER_OPTIONS);
9990
+ }
9991
+ return readerOptions;
9992
+ }
9993
+
9679
9994
  function isPassThrough(child, options) {
9680
9995
  const { readerOptions } = options;
9681
9996
  return Boolean(!child.directory && (child.passThrough || (readerOptions && readerOptions.passThrough)));
9682
9997
  }
9683
9998
 
9999
+ function isImplicitDirectory(child) {
10000
+ return child.directory && child.data === null;
10001
+ }
10002
+
9684
10003
  function getUserExtraField(extraField) {
9685
10004
  if (extraField) {
9686
10005
  const userExtraField = new Map();
@@ -9698,7 +10017,7 @@ function getUserExtraField(extraField) {
9698
10017
  async function exportZip(zipWriter, entry, totalSize, options, readers) {
9699
10018
  const { onstart, onprogress, onend, onentryprogress } = options;
9700
10019
  const selectedEntry = entry;
9701
- const totalEntries = getTotalSize(entry.children, () => 1);
10020
+ const totalEntries = getTotalSize(entry.children, child => isImplicitDirectory(child) ? 0 : 1);
9702
10021
  let writtenSize = 0;
9703
10022
  let writtenEntries = 0;
9704
10023
  if (onstart) {
@@ -9727,6 +10046,9 @@ async function exportZip(zipWriter, entry, totalSize, options, readers) {
9727
10046
  }
9728
10047
 
9729
10048
  async function addChild(child) {
10049
+ if (isImplicitDirectory(child)) {
10050
+ return;
10051
+ }
9730
10052
  const { name, entryOptions } = getChildEntryOptions(child, selectedEntry, options);
9731
10053
  let entryWrittenSize = 0;
9732
10054
  const entryMetadata = await zipWriter.add(name, readers.get(child), Object.assign(entryOptions, {
@@ -9760,7 +10082,7 @@ function addFileSystemHandle(zipEntry, handle, options) {
9760
10082
  if (handle.kind == "file") {
9761
10083
  const file = await handle.getFile();
9762
10084
  addedEntries.push(
9763
- parentEntry.addData(file.name, {
10085
+ addChild(parentEntry, file.name, {
9764
10086
  Reader: function () {
9765
10087
  const readable = file.stream();
9766
10088
  const size = file.size;
@@ -9794,10 +10116,11 @@ function addFileSystemHandle(zipEntry, handle, options) {
9794
10116
 
9795
10117
  async function exportFileSystemHandle(zipEntry, directoryHandle, options) {
9796
10118
  const { onstart, onprogress, onend } = options;
10119
+ const readerOptions = checkReaderOptions(options.readerOptions);
9797
10120
  const abortController = new AbortController();
9798
10121
  const { signal } = abortController;
9799
10122
  const releaseSignal = forwardAbort(options.signal, abortController);
9800
- const getDataOptions = Object.assign({}, options, options.readerOptions, {
10123
+ const getDataOptions = Object.assign({}, options, readerOptions, {
9801
10124
  signal,
9802
10125
  onstart: UNDEFINED_VALUE,
9803
10126
  onprogress: UNDEFINED_VALUE,
@@ -10097,6 +10420,7 @@ exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
10097
10420
  exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
10098
10421
  exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
10099
10422
  exports.ERR_ENCRYPTED_CENTRAL_DIRECTORY = ERR_ENCRYPTED_CENTRAL_DIRECTORY;
10423
+ exports.ERR_ENTRY_DATA_OUT_OF_BOUNDS = ERR_ENTRY_DATA_OUT_OF_BOUNDS;
10100
10424
  exports.ERR_ENTRY_EXISTS = ERR_ENTRY_EXISTS;
10101
10425
  exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
10102
10426
  exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
@@ -10107,22 +10431,31 @@ exports.ERR_INVALID_AUTHENTICATION_CODE = ERR_INVALID_AUTHENTICATION_CODE;
10107
10431
  exports.ERR_INVALID_CODEC_DEFINITION = ERR_INVALID_CODEC_DEFINITION;
10108
10432
  exports.ERR_INVALID_CODEC_MODULE = ERR_INVALID_CODEC_MODULE;
10109
10433
  exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
10434
+ exports.ERR_INVALID_COMMENT_TYPE = ERR_INVALID_COMMENT_TYPE;
10110
10435
  exports.ERR_INVALID_COMPRESSED_DATA = ERR_INVALID_COMPRESSED_DATA;
10111
10436
  exports.ERR_INVALID_CRC32 = ERR_INVALID_CRC32;
10437
+ exports.ERR_INVALID_DATE = ERR_INVALID_DATE;
10112
10438
  exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
10113
10439
  exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
10440
+ exports.ERR_INVALID_ENTRY_COMMENT_TYPE = ERR_INVALID_ENTRY_COMMENT_TYPE;
10114
10441
  exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
10442
+ exports.ERR_INVALID_EXTRAFIELD = ERR_INVALID_EXTRAFIELD;
10115
10443
  exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
10444
+ exports.ERR_INVALID_EXTRAFIELD_DATA_TYPE = ERR_INVALID_EXTRAFIELD_DATA_TYPE;
10116
10445
  exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
10117
10446
  exports.ERR_INVALID_FILENAME_VALIDATION = ERR_INVALID_FILENAME_VALIDATION;
10447
+ exports.ERR_INVALID_FUNCTION_OPTION = ERR_INVALID_FUNCTION_OPTION;
10118
10448
  exports.ERR_INVALID_GID = ERR_INVALID_GID;
10119
10449
  exports.ERR_INVALID_LEVEL = ERR_INVALID_LEVEL;
10120
10450
  exports.ERR_INVALID_MAX_APPENDED_DATA_SIZE = ERR_INVALID_MAX_APPENDED_DATA_SIZE;
10451
+ exports.ERR_INVALID_MAX_WORKERS = ERR_INVALID_MAX_WORKERS;
10121
10452
  exports.ERR_INVALID_MSDOS_ATTRIBUTES = ERR_INVALID_MSDOS_ATTRIBUTES;
10122
10453
  exports.ERR_INVALID_MSDOS_DATA = ERR_INVALID_MSDOS_DATA;
10123
10454
  exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
10124
10455
  exports.ERR_INVALID_PASSWORD_TYPE = ERR_INVALID_PASSWORD_TYPE;
10125
10456
  exports.ERR_INVALID_PASS_THROUGH = ERR_INVALID_PASS_THROUGH;
10457
+ exports.ERR_INVALID_READER_OPTIONS = ERR_INVALID_READER_OPTIONS;
10458
+ exports.ERR_INVALID_SIGNAL = ERR_INVALID_SIGNAL;
10126
10459
  exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
10127
10460
  exports.ERR_INVALID_SIGNATURE_DATA = ERR_INVALID_SIGNATURE_DATA;
10128
10461
  exports.ERR_INVALID_STRICTNESS = ERR_INVALID_STRICTNESS;
@@ -10162,6 +10495,10 @@ exports.TextWriter = TextWriter;
10162
10495
  exports.Uint8ArrayReader = Uint8ArrayReader;
10163
10496
  exports.Uint8ArrayWriter = Uint8ArrayWriter;
10164
10497
  exports.Writer = Writer;
10498
+ exports.ZipDirectoryEntry = ZipDirectoryEntry;
10499
+ exports.ZipEntry = ZipEntry;
10500
+ exports.ZipFS = ZipFS;
10501
+ exports.ZipFileEntry = ZipFileEntry;
10165
10502
  exports.ZipReader = ZipReader;
10166
10503
  exports.ZipReaderStream = ZipReaderStream;
10167
10504
  exports.ZipWriter = ZipWriter;