@zip.js/zip.js 2.7.47 → 2.7.49

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
@@ -3356,7 +3356,7 @@
3356
3356
  PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
3357
3357
  "directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
3358
3358
  "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
3359
- "extraFieldExtendedTimestamp"];
3359
+ "extraFieldExtendedTimestamp", "zipCrypto"];
3360
3360
 
3361
3361
  class Entry {
3362
3362
 
@@ -3591,6 +3591,7 @@
3591
3591
  });
3592
3592
  startOffset = Math.max(offsetFileEntry, startOffset);
3593
3593
  await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
3594
+ fileEntry.zipCrypto = fileEntry.encrypted && !fileEntry.extraFieldAES;
3594
3595
  const entry = new Entry(fileEntry);
3595
3596
  entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
3596
3597
  offset = endOffset;
@@ -3708,8 +3709,12 @@
3708
3709
  lastAccessDate: localDirectory.lastAccessDate,
3709
3710
  creationDate: localDirectory.creationDate
3710
3711
  });
3711
- const encrypted = zipEntry.encrypted && localDirectory.encrypted;
3712
+ const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
3713
+ const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
3712
3714
  const zipCrypto = encrypted && !extraFieldAES;
3715
+ if (!passThrough) {
3716
+ fileEntry.zipCrypto = zipCrypto;
3717
+ }
3713
3718
  if (encrypted) {
3714
3719
  if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
3715
3720
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
@@ -3741,11 +3746,11 @@
3741
3746
  rawPassword,
3742
3747
  zipCrypto,
3743
3748
  encryptionStrength: extraFieldAES && extraFieldAES.strength,
3744
- signed: getOptionValue$1(zipEntry, options, "checkSignature"),
3749
+ signed: getOptionValue$1(zipEntry, options, "checkSignature") && !passThrough,
3745
3750
  passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
3746
3751
  signature,
3747
- compressed: compressionMethod != 0,
3748
- encrypted,
3752
+ compressed: compressionMethod != 0 && !passThrough,
3753
+ encrypted: zipEntry.encrypted && !passThrough,
3749
3754
  useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers"),
3750
3755
  useCompressionStream: getOptionValue$1(zipEntry, options, "useCompressionStream"),
3751
3756
  transferStreams: getOptionValue$1(zipEntry, options, "transferStreams"),
@@ -4074,6 +4079,7 @@
4074
4079
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
4075
4080
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
4076
4081
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
4082
+ const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
4077
4083
 
4078
4084
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
4079
4085
 
@@ -4216,8 +4222,12 @@
4216
4222
  const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
4217
4223
  const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
4218
4224
  const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
4219
- const password = getOptionValue(zipWriter, options, "password");
4220
- const rawPassword = getOptionValue(zipWriter, options, "rawPassword");
4225
+ const passThrough = getOptionValue(zipWriter, options, "passThrough");
4226
+ let password, rawPassword;
4227
+ if (!passThrough) {
4228
+ password = getOptionValue(zipWriter, options, "password");
4229
+ rawPassword = getOptionValue(zipWriter, options, "rawPassword");
4230
+ }
4221
4231
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
4222
4232
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
4223
4233
  const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
@@ -4227,10 +4237,11 @@
4227
4237
  const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
4228
4238
  const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
4229
4239
  const signal = getOptionValue(zipWriter, options, "signal");
4240
+ const useUnicodeFileNames = getOptionValue(zipWriter, options, "useUnicodeFileNames", true);
4230
4241
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
4231
4242
  let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
4232
4243
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
4233
- if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
4244
+ if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
4234
4245
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
4235
4246
  }
4236
4247
  let rawExtraField = new Uint8Array();
@@ -4256,18 +4267,28 @@
4256
4267
  let maximumCompressedSize = 0;
4257
4268
  let maximumEntrySize = 0;
4258
4269
  let uncompressedSize = 0;
4270
+ if (passThrough) {
4271
+ ({ uncompressedSize } = options);
4272
+ if (uncompressedSize === UNDEFINED_VALUE) {
4273
+ throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
4274
+ }
4275
+ }
4259
4276
  const zip64Enabled = zip64 === true;
4260
4277
  if (reader) {
4261
4278
  reader = initReader(reader);
4262
4279
  await initStream(reader);
4263
- if (reader.size === UNDEFINED_VALUE) {
4264
- dataDescriptor = true;
4265
- if (zip64 || zip64 === UNDEFINED_VALUE) {
4266
- zip64 = true;
4267
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
4280
+ if (!passThrough) {
4281
+ if (reader.size === UNDEFINED_VALUE) {
4282
+ dataDescriptor = true;
4283
+ if (zip64 || zip64 === UNDEFINED_VALUE) {
4284
+ zip64 = true;
4285
+ uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
4286
+ }
4287
+ } else {
4288
+ uncompressedSize = reader.size;
4289
+ maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
4268
4290
  }
4269
4291
  } else {
4270
- uncompressedSize = reader.size;
4271
4292
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
4272
4293
  }
4273
4294
  }
@@ -4285,6 +4306,8 @@
4285
4306
  }
4286
4307
  }
4287
4308
  zip64 = zip64 || false;
4309
+ const encrypted = getOptionValue(zipWriter, options, "encrypted");
4310
+ const { signature } = options;
4288
4311
  options = Object.assign({}, options, {
4289
4312
  rawFilename,
4290
4313
  rawComment,
@@ -4308,13 +4331,17 @@
4308
4331
  zipCrypto,
4309
4332
  bufferedWrite,
4310
4333
  keepOrder,
4334
+ useUnicodeFileNames,
4311
4335
  dataDescriptor,
4312
4336
  dataDescriptorSignature,
4313
4337
  signal,
4314
4338
  msDosCompatible,
4315
4339
  internalFileAttribute,
4316
4340
  externalFileAttribute,
4317
- useCompressionStream
4341
+ useCompressionStream,
4342
+ passThrough,
4343
+ encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
4344
+ signature
4318
4345
  });
4319
4346
  const headerInfo = getHeaderInfo(options);
4320
4347
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -4525,7 +4552,8 @@
4525
4552
  msDosCompatible,
4526
4553
  internalFileAttribute,
4527
4554
  externalFileAttribute,
4528
- useCompressionStream
4555
+ useCompressionStream,
4556
+ passThrough
4529
4557
  } = options;
4530
4558
  const fileEntry = {
4531
4559
  lock,
@@ -4546,9 +4574,14 @@
4546
4574
  externalFileAttribute,
4547
4575
  diskNumberStart
4548
4576
  };
4577
+ let {
4578
+ signature,
4579
+ uncompressedSize
4580
+ } = options;
4549
4581
  let compressedSize = 0;
4550
- let uncompressedSize = 0;
4551
- let signature;
4582
+ if (!passThrough) {
4583
+ uncompressedSize = 0;
4584
+ }
4552
4585
  const { writable } = writer;
4553
4586
  if (reader) {
4554
4587
  reader.chunkSize = getChunkSize(config);
@@ -4564,9 +4597,9 @@
4564
4597
  encryptionStrength,
4565
4598
  zipCrypto: encrypted && zipCrypto,
4566
4599
  passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
4567
- signed: true,
4568
- compressed,
4569
- encrypted,
4600
+ signed: !passThrough,
4601
+ compressed: compressed && !passThrough,
4602
+ encrypted: encrypted && !passThrough,
4570
4603
  useWebWorkers,
4571
4604
  useCompressionStream,
4572
4605
  transferStreams: false
@@ -4575,9 +4608,11 @@
4575
4608
  streamOptions: { signal, size, onstart, onprogress, onend }
4576
4609
  };
4577
4610
  const result = await runWorker({ readable, writable }, workerOptions);
4578
- uncompressedSize = result.inputSize;
4579
4611
  compressedSize = result.outputSize;
4580
- signature = result.signature;
4612
+ if (!passThrough) {
4613
+ uncompressedSize = result.inputSize;
4614
+ signature = result.signature;
4615
+ }
4581
4616
  writable.size += uncompressedSize;
4582
4617
  } else {
4583
4618
  await writeData(writable, localHeaderArray);
@@ -4620,6 +4655,7 @@
4620
4655
  creationDate,
4621
4656
  lastAccessDate,
4622
4657
  encrypted,
4658
+ zipCrypto,
4623
4659
  size: metadataSize + compressedSize,
4624
4660
  compressionMethod,
4625
4661
  version,
@@ -4641,19 +4677,18 @@
4641
4677
  lastModDate,
4642
4678
  lastAccessDate,
4643
4679
  creationDate,
4644
- rawPassword,
4645
- password,
4646
4680
  level,
4647
4681
  zip64,
4648
4682
  zipCrypto,
4683
+ useUnicodeFileNames,
4649
4684
  dataDescriptor,
4650
4685
  directory,
4651
4686
  rawExtraField,
4652
4687
  encryptionStrength,
4653
- extendedTimestamp
4688
+ extendedTimestamp,
4689
+ encrypted
4654
4690
  } = options;
4655
4691
  const compressed = level !== 0 && !directory;
4656
- const encrypted = Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword)));
4657
4692
  let version = options.version;
4658
4693
  let rawExtraFieldAES;
4659
4694
  if (encrypted && !zipCrypto) {
@@ -4702,13 +4737,25 @@
4702
4737
  } else {
4703
4738
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
4704
4739
  }
4705
- let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
4740
+ let bitFlag = 0;
4741
+ if (useUnicodeFileNames) {
4742
+ bitFlag = bitFlag | BITFLAG_LANG_ENCODING_FLAG;
4743
+ }
4706
4744
  if (dataDescriptor) {
4707
4745
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
4708
4746
  }
4709
4747
  let compressionMethod = COMPRESSION_METHOD_STORE;
4710
4748
  if (compressed) {
4711
4749
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
4750
+ if (level >= 1 && level < 3) {
4751
+ bitFlag = bitFlag | 0b110;
4752
+ }
4753
+ if (level >= 3 && level < 5) {
4754
+ bitFlag = bitFlag | 0b01;
4755
+ }
4756
+ if (level === 9) {
4757
+ bitFlag = bitFlag | 0b10;
4758
+ }
4712
4759
  }
4713
4760
  if (zip64) {
4714
4761
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
@@ -5209,6 +5256,7 @@
5209
5256
  exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
5210
5257
  exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
5211
5258
  exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
5259
+ exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
5212
5260
  exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
5213
5261
  exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
5214
5262
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;