@zip.js/zip.js 2.7.43 → 2.7.44

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.
package/dist/zip.js CHANGED
@@ -6,6 +6,7 @@
6
6
 
7
7
  const { Array, Object, String, Number, BigInt, Math, Date, Map, Set, Response, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, document, crypto, btoa, TransformStream, ReadableStream, WritableStream, CompressionStream, DecompressionStream, navigator, Worker } = typeof globalThis !== 'undefined' ? globalThis : this || self;
8
8
 
9
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
10
  /*
10
11
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
11
12
 
@@ -108,6 +109,7 @@
108
109
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109
110
  */
110
111
 
112
+
111
113
  class StreamAdapter {
112
114
 
113
115
  constructor(Codec) {
@@ -158,6 +160,7 @@
158
160
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
159
161
  */
160
162
 
163
+
161
164
  const MINIMUM_CHUNK_SIZE = 64;
162
165
  let maxWorkers = 2;
163
166
  try {
@@ -274,6 +277,7 @@
274
277
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275
278
  */
276
279
 
280
+
277
281
  function getMimeType() {
278
282
  return "application/octet-stream";
279
283
  }
@@ -421,6 +425,7 @@
421
425
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
422
426
  */
423
427
 
428
+
424
429
  class Crc32Stream extends TransformStream {
425
430
 
426
431
  constructor() {
@@ -470,6 +475,7 @@
470
475
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
471
476
  */
472
477
 
478
+
473
479
  function encodeText(value) {
474
480
  if (typeof TextEncoder == UNDEFINED_TYPE) {
475
481
  value = unescape(encodeURIComponent(value));
@@ -1331,6 +1337,7 @@
1331
1337
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1332
1338
  */
1333
1339
 
1340
+
1334
1341
  const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof crypto.getRandomValues == FUNCTION_TYPE;
1335
1342
 
1336
1343
  const ERR_INVALID_PASSWORD = "Invalid password";
@@ -1373,6 +1380,7 @@
1373
1380
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1374
1381
  */
1375
1382
 
1383
+
1376
1384
  const BLOCK_LENGTH = 16;
1377
1385
  const RAW_FORMAT = "raw";
1378
1386
  const PBKDF2_ALGORITHM = { name: "PBKDF2" };
@@ -1676,6 +1684,7 @@
1676
1684
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1677
1685
  */
1678
1686
 
1687
+
1679
1688
  const HEADER_LENGTH = 12;
1680
1689
 
1681
1690
  class ZipCryptoDecryptionStream extends TransformStream {
@@ -1823,6 +1832,7 @@
1823
1832
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1824
1833
  */
1825
1834
 
1835
+
1826
1836
  const COMPRESSION_FORMAT = "deflate-raw";
1827
1837
 
1828
1838
  class DeflateStream extends TransformStream {
@@ -1963,6 +1973,7 @@
1963
1973
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1964
1974
  */
1965
1975
 
1976
+
1966
1977
  const MESSAGE_EVENT_TYPE = "message";
1967
1978
  const MESSAGE_START = "start";
1968
1979
  const MESSAGE_PULL = "pull";
@@ -2084,6 +2095,7 @@
2084
2095
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2085
2096
  */
2086
2097
 
2098
+
2087
2099
  // deno-lint-ignore valid-typeof
2088
2100
  let WEB_WORKERS_SUPPORTED = typeof Worker != UNDEFINED_TYPE;
2089
2101
 
@@ -2412,6 +2424,7 @@
2412
2424
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2413
2425
  */
2414
2426
 
2427
+
2415
2428
  let pool = [];
2416
2429
  const pendingRequests = [];
2417
2430
 
@@ -2518,6 +2531,7 @@
2518
2531
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2519
2532
  */
2520
2533
 
2534
+
2521
2535
  const ERR_HTTP_STATUS = "HTTP error ";
2522
2536
  const ERR_HTTP_RANGE = "HTTP Range not supported";
2523
2537
  const ERR_ITERATOR_COMPLETED_TOO_SOON = "Writer iterator completed too soon";
@@ -3278,6 +3292,7 @@
3278
3292
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3279
3293
  */
3280
3294
 
3295
+
3281
3296
  function decodeText(value, encoding) {
3282
3297
  if (encoding && encoding.trim().toLowerCase() == "cp437") {
3283
3298
  return decodeCP437(value);
@@ -3379,6 +3394,7 @@
3379
3394
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3380
3395
  */
3381
3396
 
3397
+
3382
3398
  const ERR_BAD_FORMAT = "File format is not recognized";
3383
3399
  const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
3384
3400
  const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
@@ -3557,10 +3573,16 @@
3557
3573
  rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
3558
3574
  });
3559
3575
  const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
3560
- const [filename, comment] = await Promise.all([
3561
- decode(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
3562
- decode(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
3563
- ]);
3576
+ const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
3577
+ const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
3578
+ let filename = decode(rawFilename, rawFilenameEncoding);
3579
+ if (filename === UNDEFINED_VALUE) {
3580
+ filename = decodeText(rawFilename, rawFilenameEncoding);
3581
+ }
3582
+ let comment = decode(rawComment, rawCommentEncoding);
3583
+ if (comment === UNDEFINED_VALUE) {
3584
+ comment = decodeText(rawComment, rawCommentEncoding);
3585
+ }
3564
3586
  Object.assign(fileEntry, {
3565
3587
  rawComment,
3566
3588
  filename,
@@ -4042,6 +4064,7 @@
4042
4064
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4043
4065
  */
4044
4066
 
4067
+
4045
4068
  const ERR_DUPLICATED_NAME = "File already exists";
4046
4069
  const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
4047
4070
  const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
@@ -4164,12 +4187,18 @@
4164
4187
  options.directory = name.endsWith(DIRECTORY_SIGNATURE);
4165
4188
  }
4166
4189
  const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
4167
- const rawFilename = encode(name);
4190
+ let rawFilename = encode(name);
4191
+ if (rawFilename === UNDEFINED_VALUE) {
4192
+ rawFilename = encodeText(name);
4193
+ }
4168
4194
  if (getLength(rawFilename) > MAX_16_BITS) {
4169
4195
  throw new Error(ERR_INVALID_ENTRY_NAME);
4170
4196
  }
4171
4197
  const comment = options.comment || "";
4172
- const rawComment = encode(comment);
4198
+ let rawComment = encode(comment);
4199
+ if (rawComment === UNDEFINED_VALUE) {
4200
+ rawComment = encodeText(comment);
4201
+ }
4173
4202
  if (getLength(rawComment) > MAX_16_BITS) {
4174
4203
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
4175
4204
  }
@@ -4235,7 +4264,7 @@
4235
4264
  dataDescriptor = true;
4236
4265
  if (zip64 || zip64 === UNDEFINED_VALUE) {
4237
4266
  zip64 = true;
4238
- uncompressedSize = maximumCompressedSize = MAX_32_BITS;
4267
+ uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
4239
4268
  }
4240
4269
  } else {
4241
4270
  uncompressedSize = reader.size;
@@ -4243,11 +4272,11 @@
4243
4272
  }
4244
4273
  }
4245
4274
  const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
4246
- const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
4247
- const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
4248
- const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS;
4275
+ const zip64UncompressedSize = zip64Enabled || uncompressedSize > MAX_32_BITS;
4276
+ const zip64CompressedSize = zip64Enabled || maximumCompressedSize > MAX_32_BITS;
4277
+ const zip64Offset = zip64Enabled || zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset > MAX_32_BITS;
4249
4278
  const supportZip64SplitFile = getOptionValue(zipWriter, options, "supportZip64SplitFile", true);
4250
- const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS;
4279
+ const zip64DiskNumberStart = (supportZip64SplitFile && zip64Enabled) || diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) > MAX_16_BITS;
4251
4280
  if (zip64Offset || zip64UncompressedSize || zip64CompressedSize || zip64DiskNumberStart) {
4252
4281
  if (zip64 === false || !keepOrder) {
4253
4282
  throw new Error(ERR_UNSUPPORTED_FORMAT);
@@ -4390,7 +4419,7 @@
4390
4419
  fileEntry.offset = zipWriter.offset - diskOffset;
4391
4420
  if (fileEntry.zip64) {
4392
4421
  setZip64ExtraInfo(fileEntry, options);
4393
- } else if (fileEntry.offset >= MAX_32_BITS) {
4422
+ } else if (fileEntry.offset > MAX_32_BITS) {
4394
4423
  throw new Error(ERR_UNSUPPORTED_FORMAT);
4395
4424
  }
4396
4425
  zipWriter.offset += fileEntry.size;
@@ -5007,7 +5036,7 @@
5007
5036
  lastDiskNumber++;
5008
5037
  }
5009
5038
  let zip64 = getOptionValue(zipWriter, options, "zip64");
5010
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
5039
+ if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
5011
5040
  if (zip64 === false) {
5012
5041
  throw new Error(ERR_UNSUPPORTED_FORMAT);
5013
5042
  } else {
@@ -5146,9 +5175,10 @@
5146
5175
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5147
5176
  */
5148
5177
 
5178
+
5149
5179
  let baseURL;
5150
5180
  try {
5151
- baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('zip.js', document.baseURI).href));
5181
+ baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('zip.js', document.baseURI).href));
5152
5182
  } catch (_error) {
5153
5183
  // ignored
5154
5184
  }
@@ -5207,6 +5237,4 @@
5207
5237
  exports.readUint8Array = readUint8Array;
5208
5238
  exports.terminateWorkers = terminateWorkers;
5209
5239
 
5210
- Object.defineProperty(exports, '__esModule', { value: true });
5211
-
5212
5240
  }));