@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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zip-js/zip-js",
3
- "version": "2.7.46",
3
+ "version": "2.7.48",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./data-uri": "./lib/zip-data-uri.js"
@@ -9211,7 +9211,7 @@
9211
9211
  PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
9212
9212
  "directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
9213
9213
  "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
9214
- "extraFieldExtendedTimestamp"];
9214
+ "extraFieldExtendedTimestamp", "zipCrypto"];
9215
9215
 
9216
9216
  class Entry {
9217
9217
 
@@ -9446,6 +9446,7 @@
9446
9446
  });
9447
9447
  startOffset = Math.max(offsetFileEntry, startOffset);
9448
9448
  await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
9449
+ fileEntry.zipCrypto = fileEntry.encrypted && !fileEntry.extraFieldAES;
9449
9450
  const entry = new Entry(fileEntry);
9450
9451
  entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
9451
9452
  offset = endOffset;
@@ -9563,8 +9564,12 @@
9563
9564
  lastAccessDate: localDirectory.lastAccessDate,
9564
9565
  creationDate: localDirectory.creationDate
9565
9566
  });
9566
- const encrypted = zipEntry.encrypted && localDirectory.encrypted;
9567
+ const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
9568
+ const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
9567
9569
  const zipCrypto = encrypted && !extraFieldAES;
9570
+ if (!passThrough) {
9571
+ fileEntry.zipCrypto = zipCrypto;
9572
+ }
9568
9573
  if (encrypted) {
9569
9574
  if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
9570
9575
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
@@ -9596,11 +9601,11 @@
9596
9601
  rawPassword,
9597
9602
  zipCrypto,
9598
9603
  encryptionStrength: extraFieldAES && extraFieldAES.strength,
9599
- signed: getOptionValue$1(zipEntry, options, "checkSignature"),
9604
+ signed: getOptionValue$1(zipEntry, options, "checkSignature") && !passThrough,
9600
9605
  passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
9601
9606
  signature,
9602
- compressed: compressionMethod != 0,
9603
- encrypted,
9607
+ compressed: compressionMethod != 0 && !passThrough,
9608
+ encrypted: zipEntry.encrypted && !passThrough,
9604
9609
  useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers"),
9605
9610
  useCompressionStream: getOptionValue$1(zipEntry, options, "useCompressionStream"),
9606
9611
  transferStreams: getOptionValue$1(zipEntry, options, "transferStreams"),
@@ -9929,6 +9934,7 @@
9929
9934
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
9930
9935
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
9931
9936
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
9937
+ const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
9932
9938
 
9933
9939
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
9934
9940
 
@@ -10071,8 +10077,12 @@
10071
10077
  const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
10072
10078
  const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
10073
10079
  const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
10074
- const password = getOptionValue(zipWriter, options, "password");
10075
- const rawPassword = getOptionValue(zipWriter, options, "rawPassword");
10080
+ const passThrough = getOptionValue(zipWriter, options, "passThrough");
10081
+ let password, rawPassword;
10082
+ if (!passThrough) {
10083
+ password = getOptionValue(zipWriter, options, "password");
10084
+ rawPassword = getOptionValue(zipWriter, options, "rawPassword");
10085
+ }
10076
10086
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
10077
10087
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
10078
10088
  const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
@@ -10082,10 +10092,11 @@
10082
10092
  const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
10083
10093
  const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
10084
10094
  const signal = getOptionValue(zipWriter, options, "signal");
10095
+ const useUnicodeFileNames = getOptionValue(zipWriter, options, "useUnicodeFileNames", true);
10085
10096
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
10086
10097
  let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
10087
10098
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
10088
- if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
10099
+ if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
10089
10100
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
10090
10101
  }
10091
10102
  let rawExtraField = new Uint8Array();
@@ -10111,18 +10122,28 @@
10111
10122
  let maximumCompressedSize = 0;
10112
10123
  let maximumEntrySize = 0;
10113
10124
  let uncompressedSize = 0;
10125
+ if (passThrough) {
10126
+ ({ uncompressedSize } = options);
10127
+ if (uncompressedSize === UNDEFINED_VALUE) {
10128
+ throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
10129
+ }
10130
+ }
10114
10131
  const zip64Enabled = zip64 === true;
10115
10132
  if (reader) {
10116
10133
  reader = initReader(reader);
10117
10134
  await initStream(reader);
10118
- if (reader.size === UNDEFINED_VALUE) {
10119
- dataDescriptor = true;
10120
- if (zip64 || zip64 === UNDEFINED_VALUE) {
10121
- zip64 = true;
10122
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
10135
+ if (!passThrough) {
10136
+ if (reader.size === UNDEFINED_VALUE) {
10137
+ dataDescriptor = true;
10138
+ if (zip64 || zip64 === UNDEFINED_VALUE) {
10139
+ zip64 = true;
10140
+ uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
10141
+ }
10142
+ } else {
10143
+ uncompressedSize = reader.size;
10144
+ maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
10123
10145
  }
10124
10146
  } else {
10125
- uncompressedSize = reader.size;
10126
10147
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
10127
10148
  }
10128
10149
  }
@@ -10140,6 +10161,8 @@
10140
10161
  }
10141
10162
  }
10142
10163
  zip64 = zip64 || false;
10164
+ const encrypted = getOptionValue(zipWriter, options, "encrypted");
10165
+ const { signature } = options;
10143
10166
  options = Object.assign({}, options, {
10144
10167
  rawFilename,
10145
10168
  rawComment,
@@ -10163,13 +10186,17 @@
10163
10186
  zipCrypto,
10164
10187
  bufferedWrite,
10165
10188
  keepOrder,
10189
+ useUnicodeFileNames,
10166
10190
  dataDescriptor,
10167
10191
  dataDescriptorSignature,
10168
10192
  signal,
10169
10193
  msDosCompatible,
10170
10194
  internalFileAttribute,
10171
10195
  externalFileAttribute,
10172
- useCompressionStream
10196
+ useCompressionStream,
10197
+ passThrough,
10198
+ encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
10199
+ signature
10173
10200
  });
10174
10201
  const headerInfo = getHeaderInfo(options);
10175
10202
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -10380,7 +10407,8 @@
10380
10407
  msDosCompatible,
10381
10408
  internalFileAttribute,
10382
10409
  externalFileAttribute,
10383
- useCompressionStream
10410
+ useCompressionStream,
10411
+ passThrough
10384
10412
  } = options;
10385
10413
  const fileEntry = {
10386
10414
  lock,
@@ -10401,9 +10429,14 @@
10401
10429
  externalFileAttribute,
10402
10430
  diskNumberStart
10403
10431
  };
10432
+ let {
10433
+ signature,
10434
+ uncompressedSize
10435
+ } = options;
10404
10436
  let compressedSize = 0;
10405
- let uncompressedSize = 0;
10406
- let signature;
10437
+ if (!passThrough) {
10438
+ uncompressedSize = 0;
10439
+ }
10407
10440
  const { writable } = writer;
10408
10441
  if (reader) {
10409
10442
  reader.chunkSize = getChunkSize(config);
@@ -10419,9 +10452,9 @@
10419
10452
  encryptionStrength,
10420
10453
  zipCrypto: encrypted && zipCrypto,
10421
10454
  passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
10422
- signed: true,
10423
- compressed,
10424
- encrypted,
10455
+ signed: !passThrough,
10456
+ compressed: compressed && !passThrough,
10457
+ encrypted: encrypted && !passThrough,
10425
10458
  useWebWorkers,
10426
10459
  useCompressionStream,
10427
10460
  transferStreams: false
@@ -10430,9 +10463,11 @@
10430
10463
  streamOptions: { signal, size, onstart, onprogress, onend }
10431
10464
  };
10432
10465
  const result = await runWorker({ readable, writable }, workerOptions);
10433
- uncompressedSize = result.inputSize;
10434
10466
  compressedSize = result.outputSize;
10435
- signature = result.signature;
10467
+ if (!passThrough) {
10468
+ uncompressedSize = result.inputSize;
10469
+ signature = result.signature;
10470
+ }
10436
10471
  writable.size += uncompressedSize;
10437
10472
  } else {
10438
10473
  await writeData(writable, localHeaderArray);
@@ -10475,6 +10510,7 @@
10475
10510
  creationDate,
10476
10511
  lastAccessDate,
10477
10512
  encrypted,
10513
+ zipCrypto,
10478
10514
  size: metadataSize + compressedSize,
10479
10515
  compressionMethod,
10480
10516
  version,
@@ -10496,19 +10532,18 @@
10496
10532
  lastModDate,
10497
10533
  lastAccessDate,
10498
10534
  creationDate,
10499
- rawPassword,
10500
- password,
10501
10535
  level,
10502
10536
  zip64,
10503
10537
  zipCrypto,
10538
+ useUnicodeFileNames,
10504
10539
  dataDescriptor,
10505
10540
  directory,
10506
10541
  rawExtraField,
10507
10542
  encryptionStrength,
10508
- extendedTimestamp
10543
+ extendedTimestamp,
10544
+ encrypted
10509
10545
  } = options;
10510
10546
  const compressed = level !== 0 && !directory;
10511
- const encrypted = Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword)));
10512
10547
  let version = options.version;
10513
10548
  let rawExtraFieldAES;
10514
10549
  if (encrypted && !zipCrypto) {
@@ -10557,13 +10592,25 @@
10557
10592
  } else {
10558
10593
  rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array();
10559
10594
  }
10560
- let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
10595
+ let bitFlag = 0;
10596
+ if (useUnicodeFileNames) {
10597
+ bitFlag = bitFlag | BITFLAG_LANG_ENCODING_FLAG;
10598
+ }
10561
10599
  if (dataDescriptor) {
10562
10600
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
10563
10601
  }
10564
10602
  let compressionMethod = COMPRESSION_METHOD_STORE;
10565
10603
  if (compressed) {
10566
10604
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
10605
+ if (level >= 1 && level < 3) {
10606
+ bitFlag = bitFlag | 0b110;
10607
+ }
10608
+ if (level >= 3 && level < 5) {
10609
+ bitFlag = bitFlag | 0b01;
10610
+ }
10611
+ if (level === 9) {
10612
+ bitFlag = bitFlag | 0b10;
10613
+ }
10567
10614
  }
10568
10615
  if (zip64) {
10569
10616
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
@@ -11049,7 +11096,8 @@
11049
11096
  id: fs.entries.length,
11050
11097
  parent,
11051
11098
  children: [],
11052
- uncompressedSize: params.uncompressedSize || 0
11099
+ uncompressedSize: params.uncompressedSize || 0,
11100
+ passThrough: params.passThrough
11053
11101
  });
11054
11102
  fs.entries.push(zipEntry);
11055
11103
  if (parent) {
@@ -11392,7 +11440,8 @@
11392
11440
  importedEntries.push(addChild(parent, name, {
11393
11441
  data: entry,
11394
11442
  Reader: getZipBlobReader(Object.assign({}, options)),
11395
- uncompressedSize: entry.uncompressedSize
11443
+ uncompressedSize: entry.uncompressedSize,
11444
+ passThrough: options.passThrough
11396
11445
  }));
11397
11446
  }
11398
11447
  } catch (error) {
@@ -11708,8 +11757,17 @@
11708
11757
  comment,
11709
11758
  lastModDate,
11710
11759
  creationDate,
11711
- lastAccessDate
11760
+ lastAccessDate,
11761
+ uncompressedSize,
11762
+ encrypted,
11763
+ zipCrypto,
11764
+ signature,
11765
+ compressionMethod
11712
11766
  } = child.data;
11767
+ let level;
11768
+ if (compressionMethod === 0) {
11769
+ level = 0;
11770
+ }
11713
11771
  zipEntryOptions = {
11714
11772
  externalFileAttribute,
11715
11773
  versionMadeBy,
@@ -11718,6 +11776,16 @@
11718
11776
  creationDate,
11719
11777
  lastAccessDate
11720
11778
  };
11779
+ if (child.passThrough) {
11780
+ zipEntryOptions = Object.assign(zipEntryOptions, {
11781
+ passThrough: true,
11782
+ encrypted,
11783
+ zipCrypto,
11784
+ signature,
11785
+ uncompressedSize,
11786
+ level
11787
+ });
11788
+ }
11721
11789
  }
11722
11790
  await zipWriter.add(name, child.reader, Object.assign({
11723
11791
  directory: child.directory
@@ -11907,6 +11975,7 @@
11907
11975
  exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
11908
11976
  exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
11909
11977
  exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
11978
+ exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
11910
11979
  exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
11911
11980
  exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
11912
11981
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;