@zip.js/zip.js 2.7.50 → 2.7.52

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-full.js CHANGED
@@ -7570,16 +7570,19 @@
7570
7570
  const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
7571
7571
  const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
7572
7572
  const PROPERTY_NAME_ZIP64 = "zip64";
7573
+ const PROPERTY_NAME_ENCRYPTED = "encrypted";
7574
+ const PROPERTY_NAME_VERSION = "version";
7575
+ const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
7576
+ const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
7573
7577
 
7574
7578
  const PROPERTY_NAMES = [
7575
7579
  PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
7576
7580
  PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
7577
7581
  PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
7578
7582
  PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
7579
- PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
7580
- "directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
7581
- "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
7582
- "extraFieldExtendedTimestamp", "zipCrypto"];
7583
+ PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY,
7584
+ PROPERTY_NAME_ZIPCRYPTO, "directory", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField",
7585
+ "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
7583
7586
 
7584
7587
  class Entry {
7585
7588
 
@@ -7910,6 +7913,7 @@
7910
7913
  const dataView = getDataView$1(dataArray);
7911
7914
  let password = getOptionValue$1(zipEntry, options, "password");
7912
7915
  let rawPassword = getOptionValue$1(zipEntry, options, "rawPassword");
7916
+ const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
7913
7917
  password = password && password.length && password;
7914
7918
  rawPassword = rawPassword && rawPassword.length && rawPassword;
7915
7919
  if (extraFieldAES) {
@@ -7917,7 +7921,7 @@
7917
7921
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
7918
7922
  }
7919
7923
  }
7920
- if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
7924
+ if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) && !passThrough) {
7921
7925
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
7922
7926
  }
7923
7927
  if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
@@ -7932,7 +7936,6 @@
7932
7936
  lastAccessDate: localDirectory.lastAccessDate,
7933
7937
  creationDate: localDirectory.creationDate
7934
7938
  });
7935
- const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
7936
7939
  const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
7937
7940
  const zipCrypto = encrypted && !extraFieldAES;
7938
7941
  if (!passThrough) {
@@ -7959,7 +7962,7 @@
7959
7962
  writer = new WritableStream();
7960
7963
  }
7961
7964
  writer = initWriter(writer);
7962
- await initStream(writer, uncompressedSize);
7965
+ await initStream(writer, passThrough ? compressedSize : uncompressedSize);
7963
7966
  const { writable } = writer;
7964
7967
  const { onstart, onprogress, onend } = options;
7965
7968
  const workerOptions = {
@@ -8431,11 +8434,11 @@
8431
8434
  if (getLength(rawComment) > MAX_16_BITS) {
8432
8435
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
8433
8436
  }
8434
- const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
8437
+ const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION, VERSION_DEFLATE);
8435
8438
  if (version > MAX_16_BITS) {
8436
8439
  throw new Error(ERR_INVALID_VERSION);
8437
8440
  }
8438
- const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
8441
+ const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, 20);
8439
8442
  if (versionMadeBy > MAX_16_BITS) {
8440
8443
  throw new Error(ERR_INVALID_VERSION);
8441
8444
  }
@@ -8452,7 +8455,7 @@
8452
8455
  rawPassword = getOptionValue(zipWriter, options, "rawPassword");
8453
8456
  }
8454
8457
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
8455
- const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
8458
+ const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
8456
8459
  const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
8457
8460
  const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
8458
8461
  const level = getOptionValue(zipWriter, options, "level");
@@ -8462,9 +8465,10 @@
8462
8465
  const signal = getOptionValue(zipWriter, options, "signal");
8463
8466
  const useUnicodeFileNames = getOptionValue(zipWriter, options, "useUnicodeFileNames", true);
8464
8467
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
8468
+ const compressionMethod = getOptionValue(zipWriter, options, "compressionMethod");
8465
8469
  let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
8466
8470
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
8467
- if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
8471
+ if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
8468
8472
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
8469
8473
  }
8470
8474
  let rawExtraField = new Uint8Array();
@@ -8529,7 +8533,7 @@
8529
8533
  }
8530
8534
  }
8531
8535
  zip64 = zip64 || false;
8532
- const encrypted = getOptionValue(zipWriter, options, "encrypted");
8536
+ const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
8533
8537
  const { signature } = options;
8534
8538
  options = Object.assign({}, options, {
8535
8539
  rawFilename,
@@ -8564,7 +8568,8 @@
8564
8568
  useCompressionStream,
8565
8569
  passThrough,
8566
8570
  encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
8567
- signature
8571
+ signature,
8572
+ compressionMethod
8568
8573
  });
8569
8574
  const headerInfo = getHeaderInfo(options);
8570
8575
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -8912,7 +8917,7 @@
8912
8917
  encrypted
8913
8918
  } = options;
8914
8919
  const compressed = level !== 0 && !directory;
8915
- let version = options.version;
8920
+ let { version, compressionMethod } = options;
8916
8921
  let rawExtraFieldAES;
8917
8922
  if (encrypted && !zipCrypto) {
8918
8923
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -8967,9 +8972,10 @@
8967
8972
  if (dataDescriptor) {
8968
8973
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
8969
8974
  }
8970
- let compressionMethod = COMPRESSION_METHOD_STORE;
8975
+ if (compressionMethod === UNDEFINED_VALUE) {
8976
+ compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
8977
+ }
8971
8978
  if (compressed) {
8972
- compressionMethod = COMPRESSION_METHOD_DEFLATE;
8973
8979
  if (level >= 1 && level < 3) {
8974
8980
  bitFlag = bitFlag | 0b110;
8975
8981
  }
@@ -8987,10 +8993,8 @@
8987
8993
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
8988
8994
  if (!zipCrypto) {
8989
8995
  version = version > VERSION_AES ? version : VERSION_AES;
8996
+ rawExtraFieldAES[9] = compressionMethod;
8990
8997
  compressionMethod = COMPRESSION_METHOD_AES;
8991
- if (compressed) {
8992
- rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
8993
- }
8994
8998
  }
8995
8999
  }
8996
9000
  const headerArray = new Uint8Array(26);
@@ -9305,7 +9309,7 @@
9305
9309
  if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
9306
9310
  lastDiskNumber++;
9307
9311
  }
9308
- let zip64 = getOptionValue(zipWriter, options, "zip64");
9312
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9309
9313
  if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
9310
9314
  if (zip64 === false) {
9311
9315
  throw new Error(ERR_UNSUPPORTED_FORMAT);