@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-fs.js CHANGED
@@ -3347,16 +3347,19 @@
3347
3347
  const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
3348
3348
  const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
3349
3349
  const PROPERTY_NAME_ZIP64 = "zip64";
3350
+ const PROPERTY_NAME_ENCRYPTED = "encrypted";
3351
+ const PROPERTY_NAME_VERSION = "version";
3352
+ const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
3353
+ const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
3350
3354
 
3351
3355
  const PROPERTY_NAMES = [
3352
3356
  PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
3353
3357
  PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
3354
3358
  PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
3355
3359
  PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
3356
- PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
3357
- "directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
3358
- "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
3359
- "extraFieldExtendedTimestamp", "zipCrypto"];
3360
+ PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY,
3361
+ PROPERTY_NAME_ZIPCRYPTO, "directory", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField",
3362
+ "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
3360
3363
 
3361
3364
  class Entry {
3362
3365
 
@@ -3687,6 +3690,7 @@
3687
3690
  const dataView = getDataView$1(dataArray);
3688
3691
  let password = getOptionValue$1(zipEntry, options, "password");
3689
3692
  let rawPassword = getOptionValue$1(zipEntry, options, "rawPassword");
3693
+ const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
3690
3694
  password = password && password.length && password;
3691
3695
  rawPassword = rawPassword && rawPassword.length && rawPassword;
3692
3696
  if (extraFieldAES) {
@@ -3694,7 +3698,7 @@
3694
3698
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
3695
3699
  }
3696
3700
  }
3697
- if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
3701
+ if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) && !passThrough) {
3698
3702
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
3699
3703
  }
3700
3704
  if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
@@ -3709,7 +3713,6 @@
3709
3713
  lastAccessDate: localDirectory.lastAccessDate,
3710
3714
  creationDate: localDirectory.creationDate
3711
3715
  });
3712
- const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
3713
3716
  const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
3714
3717
  const zipCrypto = encrypted && !extraFieldAES;
3715
3718
  if (!passThrough) {
@@ -3736,7 +3739,7 @@
3736
3739
  writer = new WritableStream();
3737
3740
  }
3738
3741
  writer = initWriter(writer);
3739
- await initStream(writer, uncompressedSize);
3742
+ await initStream(writer, passThrough ? compressedSize : uncompressedSize);
3740
3743
  const { writable } = writer;
3741
3744
  const { onstart, onprogress, onend } = options;
3742
3745
  const workerOptions = {
@@ -4208,11 +4211,11 @@
4208
4211
  if (getLength(rawComment) > MAX_16_BITS) {
4209
4212
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
4210
4213
  }
4211
- const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
4214
+ const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION, VERSION_DEFLATE);
4212
4215
  if (version > MAX_16_BITS) {
4213
4216
  throw new Error(ERR_INVALID_VERSION);
4214
4217
  }
4215
- const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
4218
+ const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, 20);
4216
4219
  if (versionMadeBy > MAX_16_BITS) {
4217
4220
  throw new Error(ERR_INVALID_VERSION);
4218
4221
  }
@@ -4229,7 +4232,7 @@
4229
4232
  rawPassword = getOptionValue(zipWriter, options, "rawPassword");
4230
4233
  }
4231
4234
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
4232
- const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
4235
+ const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
4233
4236
  const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
4234
4237
  const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
4235
4238
  const level = getOptionValue(zipWriter, options, "level");
@@ -4239,9 +4242,10 @@
4239
4242
  const signal = getOptionValue(zipWriter, options, "signal");
4240
4243
  const useUnicodeFileNames = getOptionValue(zipWriter, options, "useUnicodeFileNames", true);
4241
4244
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
4245
+ const compressionMethod = getOptionValue(zipWriter, options, "compressionMethod");
4242
4246
  let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
4243
4247
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
4244
- if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
4248
+ if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
4245
4249
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
4246
4250
  }
4247
4251
  let rawExtraField = new Uint8Array();
@@ -4306,7 +4310,7 @@
4306
4310
  }
4307
4311
  }
4308
4312
  zip64 = zip64 || false;
4309
- const encrypted = getOptionValue(zipWriter, options, "encrypted");
4313
+ const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
4310
4314
  const { signature } = options;
4311
4315
  options = Object.assign({}, options, {
4312
4316
  rawFilename,
@@ -4341,7 +4345,8 @@
4341
4345
  useCompressionStream,
4342
4346
  passThrough,
4343
4347
  encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
4344
- signature
4348
+ signature,
4349
+ compressionMethod
4345
4350
  });
4346
4351
  const headerInfo = getHeaderInfo(options);
4347
4352
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -4689,7 +4694,7 @@
4689
4694
  encrypted
4690
4695
  } = options;
4691
4696
  const compressed = level !== 0 && !directory;
4692
- let version = options.version;
4697
+ let { version, compressionMethod } = options;
4693
4698
  let rawExtraFieldAES;
4694
4699
  if (encrypted && !zipCrypto) {
4695
4700
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -4744,9 +4749,10 @@
4744
4749
  if (dataDescriptor) {
4745
4750
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
4746
4751
  }
4747
- let compressionMethod = COMPRESSION_METHOD_STORE;
4752
+ if (compressionMethod === UNDEFINED_VALUE) {
4753
+ compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
4754
+ }
4748
4755
  if (compressed) {
4749
- compressionMethod = COMPRESSION_METHOD_DEFLATE;
4750
4756
  if (level >= 1 && level < 3) {
4751
4757
  bitFlag = bitFlag | 0b110;
4752
4758
  }
@@ -4764,10 +4770,8 @@
4764
4770
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
4765
4771
  if (!zipCrypto) {
4766
4772
  version = version > VERSION_AES ? version : VERSION_AES;
4773
+ rawExtraFieldAES[9] = compressionMethod;
4767
4774
  compressionMethod = COMPRESSION_METHOD_AES;
4768
- if (compressed) {
4769
- rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
4770
- }
4771
4775
  }
4772
4776
  }
4773
4777
  const headerArray = new Uint8Array(26);
@@ -5082,7 +5086,7 @@
5082
5086
  if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
5083
5087
  lastDiskNumber++;
5084
5088
  }
5085
- let zip64 = getOptionValue(zipWriter, options, "zip64");
5089
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
5086
5090
  if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
5087
5091
  if (zip64 === false) {
5088
5092
  throw new Error(ERR_UNSUPPORTED_FORMAT);
@@ -5907,12 +5911,9 @@
5907
5911
  encrypted,
5908
5912
  zipCrypto,
5909
5913
  signature,
5910
- compressionMethod
5914
+ compressionMethod,
5915
+ extraFieldAES
5911
5916
  } = child.data;
5912
- let level;
5913
- if (compressionMethod === 0) {
5914
- level = 0;
5915
- }
5916
5917
  zipEntryOptions = {
5917
5918
  externalFileAttribute,
5918
5919
  versionMadeBy,
@@ -5922,13 +5923,22 @@
5922
5923
  lastAccessDate
5923
5924
  };
5924
5925
  if (child.passThrough) {
5926
+ let level, encryptionStrength;
5927
+ if (compressionMethod === 0) {
5928
+ level = 0;
5929
+ }
5930
+ if (extraFieldAES) {
5931
+ encryptionStrength = extraFieldAES.strength;
5932
+ }
5925
5933
  zipEntryOptions = Object.assign(zipEntryOptions, {
5926
5934
  passThrough: true,
5927
5935
  encrypted,
5928
5936
  zipCrypto,
5929
5937
  signature,
5930
5938
  uncompressedSize,
5931
- level
5939
+ level,
5940
+ encryptionStrength,
5941
+ compressionMethod
5932
5942
  });
5933
5943
  }
5934
5944
  }