@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/index.cjs CHANGED
@@ -9196,16 +9196,19 @@ const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
9196
9196
  const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
9197
9197
  const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
9198
9198
  const PROPERTY_NAME_ZIP64 = "zip64";
9199
+ const PROPERTY_NAME_ENCRYPTED = "encrypted";
9200
+ const PROPERTY_NAME_VERSION = "version";
9201
+ const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
9202
+ const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
9199
9203
 
9200
9204
  const PROPERTY_NAMES = [
9201
9205
  PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
9202
9206
  PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
9203
9207
  PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
9204
9208
  PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
9205
- PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
9206
- "directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
9207
- "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
9208
- "extraFieldExtendedTimestamp", "zipCrypto"];
9209
+ PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY,
9210
+ PROPERTY_NAME_ZIPCRYPTO, "directory", "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField",
9211
+ "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
9209
9212
 
9210
9213
  class Entry {
9211
9214
 
@@ -9536,6 +9539,7 @@ let ZipEntry$1 = class ZipEntry {
9536
9539
  const dataView = getDataView$1(dataArray);
9537
9540
  let password = getOptionValue$1(zipEntry, options, "password");
9538
9541
  let rawPassword = getOptionValue$1(zipEntry, options, "rawPassword");
9542
+ const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
9539
9543
  password = password && password.length && password;
9540
9544
  rawPassword = rawPassword && rawPassword.length && rawPassword;
9541
9545
  if (extraFieldAES) {
@@ -9543,7 +9547,7 @@ let ZipEntry$1 = class ZipEntry {
9543
9547
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
9544
9548
  }
9545
9549
  }
9546
- if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
9550
+ if ((compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) && !passThrough) {
9547
9551
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
9548
9552
  }
9549
9553
  if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
@@ -9558,7 +9562,6 @@ let ZipEntry$1 = class ZipEntry {
9558
9562
  lastAccessDate: localDirectory.lastAccessDate,
9559
9563
  creationDate: localDirectory.creationDate
9560
9564
  });
9561
- const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
9562
9565
  const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
9563
9566
  const zipCrypto = encrypted && !extraFieldAES;
9564
9567
  if (!passThrough) {
@@ -9585,7 +9588,7 @@ let ZipEntry$1 = class ZipEntry {
9585
9588
  writer = new WritableStream();
9586
9589
  }
9587
9590
  writer = initWriter(writer);
9588
- await initStream(writer, uncompressedSize);
9591
+ await initStream(writer, passThrough ? compressedSize : uncompressedSize);
9589
9592
  const { writable } = writer;
9590
9593
  const { onstart, onprogress, onend } = options;
9591
9594
  const workerOptions = {
@@ -10057,11 +10060,11 @@ async function addFile(zipWriter, name, reader, options) {
10057
10060
  if (getLength(rawComment) > MAX_16_BITS) {
10058
10061
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
10059
10062
  }
10060
- const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
10063
+ const version = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION, VERSION_DEFLATE);
10061
10064
  if (version > MAX_16_BITS) {
10062
10065
  throw new Error(ERR_INVALID_VERSION);
10063
10066
  }
10064
- const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
10067
+ const versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, 20);
10065
10068
  if (versionMadeBy > MAX_16_BITS) {
10066
10069
  throw new Error(ERR_INVALID_VERSION);
10067
10070
  }
@@ -10078,7 +10081,7 @@ async function addFile(zipWriter, name, reader, options) {
10078
10081
  rawPassword = getOptionValue(zipWriter, options, "rawPassword");
10079
10082
  }
10080
10083
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
10081
- const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
10084
+ const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
10082
10085
  const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
10083
10086
  const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
10084
10087
  const level = getOptionValue(zipWriter, options, "level");
@@ -10088,9 +10091,10 @@ async function addFile(zipWriter, name, reader, options) {
10088
10091
  const signal = getOptionValue(zipWriter, options, "signal");
10089
10092
  const useUnicodeFileNames = getOptionValue(zipWriter, options, "useUnicodeFileNames", true);
10090
10093
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
10094
+ const compressionMethod = getOptionValue(zipWriter, options, "compressionMethod");
10091
10095
  let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
10092
10096
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
10093
- if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
10097
+ if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
10094
10098
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
10095
10099
  }
10096
10100
  let rawExtraField = new Uint8Array();
@@ -10155,7 +10159,7 @@ async function addFile(zipWriter, name, reader, options) {
10155
10159
  }
10156
10160
  }
10157
10161
  zip64 = zip64 || false;
10158
- const encrypted = getOptionValue(zipWriter, options, "encrypted");
10162
+ const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
10159
10163
  const { signature } = options;
10160
10164
  options = Object.assign({}, options, {
10161
10165
  rawFilename,
@@ -10190,7 +10194,8 @@ async function addFile(zipWriter, name, reader, options) {
10190
10194
  useCompressionStream,
10191
10195
  passThrough,
10192
10196
  encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
10193
- signature
10197
+ signature,
10198
+ compressionMethod
10194
10199
  });
10195
10200
  const headerInfo = getHeaderInfo(options);
10196
10201
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -10538,7 +10543,7 @@ function getHeaderInfo(options) {
10538
10543
  encrypted
10539
10544
  } = options;
10540
10545
  const compressed = level !== 0 && !directory;
10541
- let version = options.version;
10546
+ let { version, compressionMethod } = options;
10542
10547
  let rawExtraFieldAES;
10543
10548
  if (encrypted && !zipCrypto) {
10544
10549
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -10593,9 +10598,10 @@ function getHeaderInfo(options) {
10593
10598
  if (dataDescriptor) {
10594
10599
  bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
10595
10600
  }
10596
- let compressionMethod = COMPRESSION_METHOD_STORE;
10601
+ if (compressionMethod === UNDEFINED_VALUE) {
10602
+ compressionMethod = compressed ? COMPRESSION_METHOD_DEFLATE : COMPRESSION_METHOD_STORE;
10603
+ }
10597
10604
  if (compressed) {
10598
- compressionMethod = COMPRESSION_METHOD_DEFLATE;
10599
10605
  if (level >= 1 && level < 3) {
10600
10606
  bitFlag = bitFlag | 0b110;
10601
10607
  }
@@ -10613,10 +10619,8 @@ function getHeaderInfo(options) {
10613
10619
  bitFlag = bitFlag | BITFLAG_ENCRYPTED;
10614
10620
  if (!zipCrypto) {
10615
10621
  version = version > VERSION_AES ? version : VERSION_AES;
10622
+ rawExtraFieldAES[9] = compressionMethod;
10616
10623
  compressionMethod = COMPRESSION_METHOD_AES;
10617
- if (compressed) {
10618
- rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
10619
- }
10620
10624
  }
10621
10625
  }
10622
10626
  const headerArray = new Uint8Array(26);
@@ -10931,7 +10935,7 @@ async function closeFile(zipWriter, comment, options) {
10931
10935
  if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
10932
10936
  lastDiskNumber++;
10933
10937
  }
10934
- let zip64 = getOptionValue(zipWriter, options, "zip64");
10938
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
10935
10939
  if (directoryOffset > MAX_32_BITS || directoryDataLength > MAX_32_BITS || filesLength > MAX_16_BITS || lastDiskNumber > MAX_16_BITS) {
10936
10940
  if (zip64 === false) {
10937
10941
  throw new Error(ERR_UNSUPPORTED_FORMAT);
@@ -11756,12 +11760,9 @@ async function exportZip(zipWriter, entry, totalSize, options) {
11756
11760
  encrypted,
11757
11761
  zipCrypto,
11758
11762
  signature,
11759
- compressionMethod
11763
+ compressionMethod,
11764
+ extraFieldAES
11760
11765
  } = child.data;
11761
- let level;
11762
- if (compressionMethod === 0) {
11763
- level = 0;
11764
- }
11765
11766
  zipEntryOptions = {
11766
11767
  externalFileAttribute,
11767
11768
  versionMadeBy,
@@ -11771,13 +11772,22 @@ async function exportZip(zipWriter, entry, totalSize, options) {
11771
11772
  lastAccessDate
11772
11773
  };
11773
11774
  if (child.passThrough) {
11775
+ let level, encryptionStrength;
11776
+ if (compressionMethod === 0) {
11777
+ level = 0;
11778
+ }
11779
+ if (extraFieldAES) {
11780
+ encryptionStrength = extraFieldAES.strength;
11781
+ }
11774
11782
  zipEntryOptions = Object.assign(zipEntryOptions, {
11775
11783
  passThrough: true,
11776
11784
  encrypted,
11777
11785
  zipCrypto,
11778
11786
  signature,
11779
11787
  uncompressedSize,
11780
- level
11788
+ level,
11789
+ encryptionStrength,
11790
+ compressionMethod
11781
11791
  });
11782
11792
  }
11783
11793
  }
package/index.d.ts CHANGED
@@ -407,7 +407,7 @@ export class HttpReader extends Reader<URLString> {
407
407
  * @param url The URL of the data.
408
408
  * @param options The options.
409
409
  */
410
- constructor(url: URLString, options?: HttpOptions);
410
+ constructor(url: URLString | URL, options?: HttpOptions);
411
411
  }
412
412
 
413
413
  /**
@@ -420,7 +420,7 @@ export class HttpRangeReader extends HttpReader {
420
420
  * @param url The URL of the data.
421
421
  * @param options The options.
422
422
  */
423
- constructor(url: URLString, options?: HttpRangeOptions);
423
+ constructor(url: URLString | URL, options?: HttpRangeOptions);
424
424
  }
425
425
 
426
426
  /**
@@ -806,7 +806,7 @@ export interface ZipReaderOptions {
806
806
  *
807
807
  * @defaultValue false
808
808
  */
809
- checkPasswordOnly: boolean;
809
+ checkPasswordOnly?: boolean;
810
810
  /**
811
811
  * `true` to check the signature of the entry.
812
812
  *
@@ -959,6 +959,10 @@ export interface EntryMetaData {
959
959
  * The number of the disk where the entry data starts.
960
960
  */
961
961
  diskNumberStart: number;
962
+ /**
963
+ * The compression method.
964
+ */
965
+ compressionMethod: number;
962
966
  }
963
967
 
964
968
  /**
@@ -1376,6 +1380,10 @@ export interface ZipWriterConstructorOptions {
1376
1380
  * The offset of the first entry in the zip file.
1377
1381
  */
1378
1382
  offset?: number;
1383
+ /**
1384
+ * The compression method (e.g. 8 for DEFLATE, 0 for STORE).
1385
+ */
1386
+ compressionMethod?: number
1379
1387
  /**
1380
1388
  * Encode the filename and the comment of the entry.
1381
1389
  *