@zip.js/zip.js 2.7.54 → 2.7.56

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
@@ -67,6 +67,8 @@
67
67
  const BITFLAG_DATA_DESCRIPTOR = 0x0008;
68
68
  const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
69
69
  const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
70
+ const FILE_ATTR_UNIX_DIR_MASK = 0x4000;
71
+ const FILE_ATTR_UNIX_EXECUTABLE_MASK = 0o111;
70
72
 
71
73
  const VERSION_DEFLATE = 0x14;
72
74
  const VERSION_ZIP64 = 0x2D;
@@ -167,7 +169,8 @@
167
169
  if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
168
170
  maxWorkers = navigator.hardwareConcurrency;
169
171
  }
170
- } catch (_error) {
172
+ // eslint-disable-next-line no-unused-vars
173
+ } catch (_) {
171
174
  // ignored
172
175
  }
173
176
  const DEFAULT_CONFIGURATION = {
@@ -1605,7 +1608,8 @@
1605
1608
  if (IMPORT_KEY_SUPPORTED) {
1606
1609
  try {
1607
1610
  return await subtle.importKey(format, password, algorithm, extractable, keyUsages);
1608
- } catch (_error) {
1611
+ // eslint-disable-next-line no-unused-vars
1612
+ } catch (_) {
1609
1613
  IMPORT_KEY_SUPPORTED = false;
1610
1614
  return misc.importKey(password);
1611
1615
  }
@@ -1618,7 +1622,8 @@
1618
1622
  if (DERIVE_BITS_SUPPORTED) {
1619
1623
  try {
1620
1624
  return await subtle.deriveBits(algorithm, baseKey, length);
1621
- } catch (_error) {
1625
+ // eslint-disable-next-line no-unused-vars
1626
+ } catch (_) {
1622
1627
  DERIVE_BITS_SUPPORTED = false;
1623
1628
  return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
1624
1629
  }
@@ -1936,11 +1941,13 @@
1936
1941
  try {
1937
1942
  const CompressionStream = useCompressionStream && CodecStreamNative ? CodecStreamNative : CodecStream;
1938
1943
  readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
1939
- } catch (_error) {
1944
+ // eslint-disable-next-line no-unused-vars
1945
+ } catch (_) {
1940
1946
  if (useCompressionStream) {
1941
1947
  try {
1942
1948
  readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
1943
- } catch (_error) {
1949
+ // eslint-disable-next-line no-unused-vars
1950
+ } catch (_) {
1944
1951
  return readable;
1945
1952
  }
1946
1953
  } else {
@@ -2183,7 +2190,8 @@
2183
2190
  async function callHandler(handler, ...parameters) {
2184
2191
  try {
2185
2192
  await handler(...parameters);
2186
- } catch (_error) {
2193
+ // eslint-disable-next-line no-unused-vars
2194
+ } catch (_) {
2187
2195
  // ignored
2188
2196
  }
2189
2197
  }
@@ -2200,7 +2208,8 @@
2200
2208
  let worker;
2201
2209
  try {
2202
2210
  worker = getWebWorker(workerData.scripts[0], baseURL, workerData);
2203
- } catch (_error) {
2211
+ // eslint-disable-next-line no-unused-vars
2212
+ } catch (_) {
2204
2213
  WEB_WORKERS_SUPPORTED = false;
2205
2214
  return createWorkerInterface(workerData, config);
2206
2215
  }
@@ -2303,13 +2312,15 @@
2303
2312
  }
2304
2313
  try {
2305
2314
  scriptUrl = new URL(url, baseURL);
2306
- } catch (_error) {
2315
+ // eslint-disable-next-line no-unused-vars
2316
+ } catch (_) {
2307
2317
  scriptUrl = url;
2308
2318
  }
2309
2319
  if (classicWorkersSupported) {
2310
2320
  try {
2311
2321
  worker = new Worker(scriptUrl);
2312
- } catch (_error) {
2322
+ // eslint-disable-next-line no-unused-vars
2323
+ } catch (_) {
2313
2324
  classicWorkersSupported = false;
2314
2325
  worker = new Worker(scriptUrl, workerOptions);
2315
2326
  }
@@ -2347,7 +2358,8 @@
2347
2358
  try {
2348
2359
  worker.postMessage(message, transferables);
2349
2360
  return true;
2350
- } catch (_error) {
2361
+ // eslint-disable-next-line no-unused-vars
2362
+ } catch (_) {
2351
2363
  transferStreamsSupported = false;
2352
2364
  message.readable = message.writable = null;
2353
2365
  worker.postMessage(message);
@@ -2490,7 +2502,8 @@
2490
2502
  pool = pool.filter(data => data != workerData);
2491
2503
  try {
2492
2504
  await workerData.terminate();
2493
- } catch (_error) {
2505
+ // eslint-disable-next-line no-unused-vars
2506
+ } catch (_) {
2494
2507
  // ignored
2495
2508
  }
2496
2509
  }, terminateWorkerTimeout);
@@ -2831,7 +2844,7 @@
2831
2844
  combineSizeEocd
2832
2845
  } = httpReader;
2833
2846
  if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
2834
- const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
2847
+ const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -22 : undefined));
2835
2848
  if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
2836
2849
  throw new Error(ERR_HTTP_RANGE);
2837
2850
  } else {
@@ -3354,7 +3367,9 @@
3354
3367
  const PROPERTY_NAME_CREATION_DATE = "creationDate";
3355
3368
  const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
3356
3369
  const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
3370
+ const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES = "internalFileAttributes";
3357
3371
  const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
3372
+ const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES = "externalFileAttributes";
3358
3373
  const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
3359
3374
  const PROPERTY_NAME_ZIP64 = "zip64";
3360
3375
  const PROPERTY_NAME_ENCRYPTED = "encrypted";
@@ -3366,10 +3381,7 @@
3366
3381
  PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
3367
3382
  PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
3368
3383
  PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
3369
- PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
3370
- PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY,
3371
- PROPERTY_NAME_ZIPCRYPTO, "directory", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField",
3372
- "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
3384
+ PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY, PROPERTY_NAME_ZIPCRYPTO, "directory", "executable", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
3373
3385
 
3374
3386
  class Entry {
3375
3387
 
@@ -3560,14 +3572,20 @@
3560
3572
  const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
3561
3573
  const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
3562
3574
  const versionMadeBy = getUint16(directoryView, offset + 4);
3563
- const msDosCompatible = (versionMadeBy & 0) == 0;
3575
+ const msDosCompatible = versionMadeBy >> 8 == 0;
3576
+ const unixCompatible = versionMadeBy >> 8 == 3;
3564
3577
  const rawFilename = directoryArray.subarray(filenameOffset, extraFieldOffset);
3565
3578
  const commentLength = getUint16(directoryView, offset + 32);
3566
3579
  const endOffset = commentOffset + commentLength;
3567
3580
  const rawComment = directoryArray.subarray(commentOffset, endOffset);
3568
3581
  const filenameUTF8 = languageEncodingFlag;
3569
3582
  const commentUTF8 = languageEncodingFlag;
3570
- const directory = msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK);
3583
+ const externalFileAttributes = getUint32(directoryView, offset + 38);
3584
+ const directory =
3585
+ (msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK)) ||
3586
+ (unixCompatible && (((externalFileAttributes >> 16) & FILE_ATTR_UNIX_DIR_MASK) == FILE_ATTR_UNIX_DIR_MASK)) ||
3587
+ (rawFilename.length && rawFilename[rawFilename.length - 1] == DIRECTORY_SIGNATURE.charCodeAt(0));
3588
+ const executable = (unixCompatible && (((externalFileAttributes >> 16) & FILE_ATTR_UNIX_EXECUTABLE_MASK) == FILE_ATTR_UNIX_EXECUTABLE_MASK));
3571
3589
  const offsetFileEntry = getUint32(directoryView, offset + 42) + prependedDataLength;
3572
3590
  Object.assign(fileEntry, {
3573
3591
  versionMadeBy,
@@ -3578,13 +3596,16 @@
3578
3596
  directory,
3579
3597
  offset: offsetFileEntry,
3580
3598
  diskNumberStart: getUint16(directoryView, offset + 34),
3581
- internalFileAttribute: getUint16(directoryView, offset + 36),
3582
- externalFileAttribute: getUint32(directoryView, offset + 38),
3599
+ internalFileAttributes: getUint16(directoryView, offset + 36),
3600
+ externalFileAttributes,
3583
3601
  rawFilename,
3584
3602
  filenameUTF8,
3585
3603
  commentUTF8,
3586
- rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
3604
+ rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset),
3605
+ executable
3587
3606
  });
3607
+ fileEntry.internalFileAttribute = fileEntry.internalFileAttributes;
3608
+ fileEntry.externalFileAttribute = fileEntry.externalFileAttributes;
3588
3609
  const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
3589
3610
  const rawFilenameEncoding = filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437;
3590
3611
  const rawCommentEncoding = commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437;
@@ -3612,7 +3633,8 @@
3612
3633
  if (onprogress) {
3613
3634
  try {
3614
3635
  await onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
3615
- } catch (_error) {
3636
+ // eslint-disable-next-line no-unused-vars
3637
+ } catch (_) {
3616
3638
  // ignored
3617
3639
  }
3618
3640
  }
@@ -3824,7 +3846,8 @@
3824
3846
  });
3825
3847
  offsetExtraField += 4 + size;
3826
3848
  }
3827
- } catch (_error) {
3849
+ // eslint-disable-next-line no-unused-vars
3850
+ } catch (_) {
3828
3851
  // ignored
3829
3852
  }
3830
3853
  const compressionMethod = getUint16(dataView, offset + 4);
@@ -3931,7 +3954,8 @@
3931
3954
  }
3932
3955
  offsetExtraField += 4 + attributeSize;
3933
3956
  }
3934
- } catch (_error) {
3957
+ // eslint-disable-next-line no-unused-vars
3958
+ } catch (_) {
3935
3959
  // ignored
3936
3960
  }
3937
3961
  try {
@@ -3952,7 +3976,8 @@
3952
3976
  Object.assign(extraFieldNTFS, extraFieldData);
3953
3977
  Object.assign(directory, extraFieldData);
3954
3978
  }
3955
- } catch (_error) {
3979
+ // eslint-disable-next-line no-unused-vars
3980
+ } catch (_) {
3956
3981
  // ignored
3957
3982
  }
3958
3983
  }
@@ -4021,7 +4046,8 @@
4021
4046
  const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
4022
4047
  try {
4023
4048
  return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
4024
- } catch (_error) {
4049
+ // eslint-disable-next-line no-unused-vars
4050
+ } catch (_) {
4025
4051
  // ignored
4026
4052
  }
4027
4053
  }
@@ -4233,8 +4259,14 @@
4233
4259
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
4234
4260
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
4235
4261
  const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
4236
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
4237
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
4262
+ let internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, 0);
4263
+ if (internalFileAttributes === 0) {
4264
+ internalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
4265
+ }
4266
+ let externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, 0);
4267
+ if (externalFileAttributes === 0) {
4268
+ externalFileAttributes = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
4269
+ }
4238
4270
  const passThrough = getOptionValue(zipWriter, options, "passThrough");
4239
4271
  let password, rawPassword;
4240
4272
  if (!passThrough) {
@@ -4350,8 +4382,10 @@
4350
4382
  dataDescriptorSignature,
4351
4383
  signal,
4352
4384
  msDosCompatible,
4353
- internalFileAttribute,
4354
- externalFileAttribute,
4385
+ internalFileAttribute: internalFileAttributes,
4386
+ internalFileAttributes,
4387
+ externalFileAttribute: externalFileAttributes,
4388
+ externalFileAttributes,
4355
4389
  useCompressionStream,
4356
4390
  passThrough,
4357
4391
  encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
@@ -4472,7 +4506,8 @@
4472
4506
  if (error) {
4473
4507
  try {
4474
4508
  error.corruptedEntry = true;
4475
- } catch (_error) {
4509
+ // eslint-disable-next-line no-unused-vars
4510
+ } catch (_) {
4476
4511
  // ignored
4477
4512
  }
4478
4513
  }
@@ -4565,8 +4600,8 @@
4565
4600
  encryptionStrength,
4566
4601
  extendedTimestamp,
4567
4602
  msDosCompatible,
4568
- internalFileAttribute,
4569
- externalFileAttribute,
4603
+ internalFileAttributes,
4604
+ externalFileAttributes,
4570
4605
  useCompressionStream,
4571
4606
  passThrough
4572
4607
  } = options;
@@ -4585,8 +4620,8 @@
4585
4620
  rawExtraField,
4586
4621
  extendedTimestamp,
4587
4622
  msDosCompatible,
4588
- internalFileAttribute,
4589
- externalFileAttribute,
4623
+ internalFileAttributes,
4624
+ externalFileAttributes,
4590
4625
  diskNumberStart
4591
4626
  };
4592
4627
  let {
@@ -4746,7 +4781,8 @@
4746
4781
  setBigUint64(extraFieldNTFSView, 12, lastModTimeNTFS);
4747
4782
  setBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
4748
4783
  setBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);
4749
- } catch (_error) {
4784
+ // eslint-disable-next-line no-unused-vars
4785
+ } catch (_) {
4750
4786
  rawExtraFieldNTFS = new Uint8Array();
4751
4787
  }
4752
4788
  } else {
@@ -5041,8 +5077,8 @@
5041
5077
  zip64DiskNumberStart,
5042
5078
  zip64Offset,
5043
5079
  msDosCompatible,
5044
- internalFileAttribute,
5045
- externalFileAttribute,
5080
+ internalFileAttributes,
5081
+ externalFileAttributes,
5046
5082
  diskNumberStart,
5047
5083
  uncompressedSize,
5048
5084
  compressedSize
@@ -5061,9 +5097,9 @@
5061
5097
  setUint16(directoryView, offset + 30, extraFieldLength);
5062
5098
  setUint16(directoryView, offset + 32, getLength(rawComment));
5063
5099
  setUint16(directoryView, offset + 34, zip64 && zip64DiskNumberStart ? MAX_16_BITS : diskNumberStart);
5064
- setUint16(directoryView, offset + 36, internalFileAttribute);
5065
- if (externalFileAttribute) {
5066
- setUint32(directoryView, offset + 38, externalFileAttribute);
5100
+ setUint16(directoryView, offset + 36, internalFileAttributes);
5101
+ if (externalFileAttributes) {
5102
+ setUint32(directoryView, offset + 38, externalFileAttributes);
5067
5103
  } else if (directory && msDosCompatible) {
5068
5104
  setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
5069
5105
  }
@@ -5085,7 +5121,8 @@
5085
5121
  if (options.onprogress) {
5086
5122
  try {
5087
5123
  await options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
5088
- } catch (_error) {
5124
+ // eslint-disable-next-line no-unused-vars
5125
+ } catch (_) {
5089
5126
  // ignored
5090
5127
  }
5091
5128
  }
@@ -5240,7 +5277,8 @@
5240
5277
  let baseURL;
5241
5278
  try {
5242
5279
  baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('zip.js', document.baseURI).href));
5243
- } catch (_error) {
5280
+ // eslint-disable-next-line no-unused-vars
5281
+ } catch (_) {
5244
5282
  // ignored
5245
5283
  }
5246
5284
  configure({ baseURL });