@zip.js/zip.js 2.7.48 → 2.7.50

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
@@ -9205,7 +9205,7 @@ const PROPERTY_NAMES = [
9205
9205
  PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
9206
9206
  "directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
9207
9207
  "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
9208
- "extraFieldExtendedTimestamp"];
9208
+ "extraFieldExtendedTimestamp", "zipCrypto"];
9209
9209
 
9210
9210
  class Entry {
9211
9211
 
@@ -9440,6 +9440,7 @@ class ZipReader {
9440
9440
  });
9441
9441
  startOffset = Math.max(offsetFileEntry, startOffset);
9442
9442
  await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
9443
+ fileEntry.zipCrypto = fileEntry.encrypted && !fileEntry.extraFieldAES;
9443
9444
  const entry = new Entry(fileEntry);
9444
9445
  entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
9445
9446
  offset = endOffset;
@@ -9557,8 +9558,12 @@ let ZipEntry$1 = class ZipEntry {
9557
9558
  lastAccessDate: localDirectory.lastAccessDate,
9558
9559
  creationDate: localDirectory.creationDate
9559
9560
  });
9560
- const encrypted = zipEntry.encrypted && localDirectory.encrypted;
9561
+ const passThrough = getOptionValue$1(zipEntry, options, "passThrough");
9562
+ const encrypted = zipEntry.encrypted && localDirectory.encrypted && !passThrough;
9561
9563
  const zipCrypto = encrypted && !extraFieldAES;
9564
+ if (!passThrough) {
9565
+ fileEntry.zipCrypto = zipCrypto;
9566
+ }
9562
9567
  if (encrypted) {
9563
9568
  if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
9564
9569
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
@@ -9590,11 +9595,11 @@ let ZipEntry$1 = class ZipEntry {
9590
9595
  rawPassword,
9591
9596
  zipCrypto,
9592
9597
  encryptionStrength: extraFieldAES && extraFieldAES.strength,
9593
- signed: getOptionValue$1(zipEntry, options, "checkSignature"),
9598
+ signed: getOptionValue$1(zipEntry, options, "checkSignature") && !passThrough,
9594
9599
  passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
9595
9600
  signature,
9596
- compressed: compressionMethod != 0,
9597
- encrypted,
9601
+ compressed: compressionMethod != 0 && !passThrough,
9602
+ encrypted: zipEntry.encrypted && !passThrough,
9598
9603
  useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers"),
9599
9604
  useCompressionStream: getOptionValue$1(zipEntry, options, "useCompressionStream"),
9600
9605
  transferStreams: getOptionValue$1(zipEntry, options, "transferStreams"),
@@ -9923,6 +9928,7 @@ const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
9923
9928
  const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
9924
9929
  const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
9925
9930
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (make sure 'keepOrder' is set to 'true')";
9931
+ const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
9926
9932
 
9927
9933
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
9928
9934
 
@@ -9943,7 +9949,7 @@ class ZipWriter {
9943
9949
  config: getConfiguration(),
9944
9950
  files: new Map(),
9945
9951
  filenames: new Set(),
9946
- offset: writer.writable.size,
9952
+ offset: options.offset === UNDEFINED_VALUE ? writer.writable.size : options.offset,
9947
9953
  pendingEntriesSize: 0,
9948
9954
  pendingAddFileCalls: new Set(),
9949
9955
  bufferedWrites: 0
@@ -10065,8 +10071,12 @@ async function addFile(zipWriter, name, reader, options) {
10065
10071
  const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
10066
10072
  const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
10067
10073
  const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
10068
- const password = getOptionValue(zipWriter, options, "password");
10069
- const rawPassword = getOptionValue(zipWriter, options, "rawPassword");
10074
+ const passThrough = getOptionValue(zipWriter, options, "passThrough");
10075
+ let password, rawPassword;
10076
+ if (!passThrough) {
10077
+ password = getOptionValue(zipWriter, options, "password");
10078
+ rawPassword = getOptionValue(zipWriter, options, "rawPassword");
10079
+ }
10070
10080
  const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
10071
10081
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
10072
10082
  const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
@@ -10080,7 +10090,7 @@ async function addFile(zipWriter, name, reader, options) {
10080
10090
  const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
10081
10091
  let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
10082
10092
  let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
10083
- if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
10093
+ if ((password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
10084
10094
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
10085
10095
  }
10086
10096
  let rawExtraField = new Uint8Array();
@@ -10106,18 +10116,28 @@ async function addFile(zipWriter, name, reader, options) {
10106
10116
  let maximumCompressedSize = 0;
10107
10117
  let maximumEntrySize = 0;
10108
10118
  let uncompressedSize = 0;
10119
+ if (passThrough) {
10120
+ ({ uncompressedSize } = options);
10121
+ if (uncompressedSize === UNDEFINED_VALUE) {
10122
+ throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
10123
+ }
10124
+ }
10109
10125
  const zip64Enabled = zip64 === true;
10110
10126
  if (reader) {
10111
10127
  reader = initReader(reader);
10112
10128
  await initStream(reader);
10113
- if (reader.size === UNDEFINED_VALUE) {
10114
- dataDescriptor = true;
10115
- if (zip64 || zip64 === UNDEFINED_VALUE) {
10116
- zip64 = true;
10117
- uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
10129
+ if (!passThrough) {
10130
+ if (reader.size === UNDEFINED_VALUE) {
10131
+ dataDescriptor = true;
10132
+ if (zip64 || zip64 === UNDEFINED_VALUE) {
10133
+ zip64 = true;
10134
+ uncompressedSize = maximumCompressedSize = MAX_32_BITS + 1;
10135
+ }
10136
+ } else {
10137
+ uncompressedSize = reader.size;
10138
+ maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
10118
10139
  }
10119
10140
  } else {
10120
- uncompressedSize = reader.size;
10121
10141
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
10122
10142
  }
10123
10143
  }
@@ -10135,6 +10155,8 @@ async function addFile(zipWriter, name, reader, options) {
10135
10155
  }
10136
10156
  }
10137
10157
  zip64 = zip64 || false;
10158
+ const encrypted = getOptionValue(zipWriter, options, "encrypted");
10159
+ const { signature } = options;
10138
10160
  options = Object.assign({}, options, {
10139
10161
  rawFilename,
10140
10162
  rawComment,
@@ -10165,7 +10187,10 @@ async function addFile(zipWriter, name, reader, options) {
10165
10187
  msDosCompatible,
10166
10188
  internalFileAttribute,
10167
10189
  externalFileAttribute,
10168
- useCompressionStream
10190
+ useCompressionStream,
10191
+ passThrough,
10192
+ encrypted: Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword))) || (passThrough && encrypted),
10193
+ signature
10169
10194
  });
10170
10195
  const headerInfo = getHeaderInfo(options);
10171
10196
  const dataDescriptorInfo = getDataDescriptorInfo(options);
@@ -10376,7 +10401,8 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10376
10401
  msDosCompatible,
10377
10402
  internalFileAttribute,
10378
10403
  externalFileAttribute,
10379
- useCompressionStream
10404
+ useCompressionStream,
10405
+ passThrough
10380
10406
  } = options;
10381
10407
  const fileEntry = {
10382
10408
  lock,
@@ -10397,9 +10423,14 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10397
10423
  externalFileAttribute,
10398
10424
  diskNumberStart
10399
10425
  };
10426
+ let {
10427
+ signature,
10428
+ uncompressedSize
10429
+ } = options;
10400
10430
  let compressedSize = 0;
10401
- let uncompressedSize = 0;
10402
- let signature;
10431
+ if (!passThrough) {
10432
+ uncompressedSize = 0;
10433
+ }
10403
10434
  const { writable } = writer;
10404
10435
  if (reader) {
10405
10436
  reader.chunkSize = getChunkSize(config);
@@ -10415,9 +10446,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10415
10446
  encryptionStrength,
10416
10447
  zipCrypto: encrypted && zipCrypto,
10417
10448
  passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
10418
- signed: true,
10419
- compressed,
10420
- encrypted,
10449
+ signed: !passThrough,
10450
+ compressed: compressed && !passThrough,
10451
+ encrypted: encrypted && !passThrough,
10421
10452
  useWebWorkers,
10422
10453
  useCompressionStream,
10423
10454
  transferStreams: false
@@ -10426,9 +10457,11 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10426
10457
  streamOptions: { signal, size, onstart, onprogress, onend }
10427
10458
  };
10428
10459
  const result = await runWorker({ readable, writable }, workerOptions);
10429
- uncompressedSize = result.inputSize;
10430
10460
  compressedSize = result.outputSize;
10431
- signature = result.signature;
10461
+ if (!passThrough) {
10462
+ uncompressedSize = result.inputSize;
10463
+ signature = result.signature;
10464
+ }
10432
10465
  writable.size += uncompressedSize;
10433
10466
  } else {
10434
10467
  await writeData(writable, localHeaderArray);
@@ -10471,6 +10504,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
10471
10504
  creationDate,
10472
10505
  lastAccessDate,
10473
10506
  encrypted,
10507
+ zipCrypto,
10474
10508
  size: metadataSize + compressedSize,
10475
10509
  compressionMethod,
10476
10510
  version,
@@ -10492,8 +10526,6 @@ function getHeaderInfo(options) {
10492
10526
  lastModDate,
10493
10527
  lastAccessDate,
10494
10528
  creationDate,
10495
- rawPassword,
10496
- password,
10497
10529
  level,
10498
10530
  zip64,
10499
10531
  zipCrypto,
@@ -10502,10 +10534,10 @@ function getHeaderInfo(options) {
10502
10534
  directory,
10503
10535
  rawExtraField,
10504
10536
  encryptionStrength,
10505
- extendedTimestamp
10537
+ extendedTimestamp,
10538
+ encrypted
10506
10539
  } = options;
10507
10540
  const compressed = level !== 0 && !directory;
10508
- const encrypted = Boolean((password && getLength(password)) || (rawPassword && getLength(rawPassword)));
10509
10541
  let version = options.version;
10510
10542
  let rawExtraFieldAES;
10511
10543
  if (encrypted && !zipCrypto) {
@@ -10564,6 +10596,15 @@ function getHeaderInfo(options) {
10564
10596
  let compressionMethod = COMPRESSION_METHOD_STORE;
10565
10597
  if (compressed) {
10566
10598
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
10599
+ if (level >= 1 && level < 3) {
10600
+ bitFlag = bitFlag | 0b110;
10601
+ }
10602
+ if (level >= 3 && level < 5) {
10603
+ bitFlag = bitFlag | 0b01;
10604
+ }
10605
+ if (level === 9) {
10606
+ bitFlag = bitFlag | 0b10;
10607
+ }
10567
10608
  }
10568
10609
  if (zip64) {
10569
10610
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
@@ -11049,7 +11090,8 @@ class ZipEntry {
11049
11090
  id: fs.entries.length,
11050
11091
  parent,
11051
11092
  children: [],
11052
- uncompressedSize: params.uncompressedSize || 0
11093
+ uncompressedSize: params.uncompressedSize || 0,
11094
+ passThrough: params.passThrough
11053
11095
  });
11054
11096
  fs.entries.push(zipEntry);
11055
11097
  if (parent) {
@@ -11392,7 +11434,8 @@ class ZipDirectoryEntry extends ZipEntry {
11392
11434
  importedEntries.push(addChild(parent, name, {
11393
11435
  data: entry,
11394
11436
  Reader: getZipBlobReader(Object.assign({}, options)),
11395
- uncompressedSize: entry.uncompressedSize
11437
+ uncompressedSize: entry.uncompressedSize,
11438
+ passThrough: options.passThrough
11396
11439
  }));
11397
11440
  }
11398
11441
  } catch (error) {
@@ -11708,8 +11751,17 @@ async function exportZip(zipWriter, entry, totalSize, options) {
11708
11751
  comment,
11709
11752
  lastModDate,
11710
11753
  creationDate,
11711
- lastAccessDate
11754
+ lastAccessDate,
11755
+ uncompressedSize,
11756
+ encrypted,
11757
+ zipCrypto,
11758
+ signature,
11759
+ compressionMethod
11712
11760
  } = child.data;
11761
+ let level;
11762
+ if (compressionMethod === 0) {
11763
+ level = 0;
11764
+ }
11713
11765
  zipEntryOptions = {
11714
11766
  externalFileAttribute,
11715
11767
  versionMadeBy,
@@ -11718,6 +11770,16 @@ async function exportZip(zipWriter, entry, totalSize, options) {
11718
11770
  creationDate,
11719
11771
  lastAccessDate
11720
11772
  };
11773
+ if (child.passThrough) {
11774
+ zipEntryOptions = Object.assign(zipEntryOptions, {
11775
+ passThrough: true,
11776
+ encrypted,
11777
+ zipCrypto,
11778
+ signature,
11779
+ uncompressedSize,
11780
+ level
11781
+ });
11782
+ }
11721
11783
  }
11722
11784
  await zipWriter.add(name, child.reader, Object.assign({
11723
11785
  directory: child.directory
@@ -11907,6 +11969,7 @@ exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
11907
11969
  exports.ERR_ITERATOR_COMPLETED_TOO_SOON = ERR_ITERATOR_COMPLETED_TOO_SOON;
11908
11970
  exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
11909
11971
  exports.ERR_SPLIT_ZIP_FILE = ERR_SPLIT_ZIP_FILE;
11972
+ exports.ERR_UNDEFINED_UNCOMPRESSED_SIZE = ERR_UNDEFINED_UNCOMPRESSED_SIZE;
11910
11973
  exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
11911
11974
  exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
11912
11975
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
package/index.d.ts CHANGED
@@ -800,19 +800,13 @@ export interface GetEntriesOptions {
800
800
  /**
801
801
  * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
802
802
  */
803
- export interface ZipReaderCheckPasswordOptions {
803
+ export interface ZipReaderOptions {
804
804
  /**
805
805
  * `true` to check only if the password is valid.
806
806
  *
807
807
  * @defaultValue false
808
808
  */
809
809
  checkPasswordOnly: boolean;
810
- }
811
-
812
- /**
813
- * Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
814
- */
815
- export interface ZipReaderOptions {
816
810
  /**
817
811
  * `true` to check the signature of the entry.
818
812
  *
@@ -823,6 +817,10 @@ export interface ZipReaderOptions {
823
817
  * The password used to decrypt the content of the entry.
824
818
  */
825
819
  password?: string;
820
+ /**
821
+ * `true` to read the data as-is without decompressing it and without decrypting it.
822
+ */
823
+ passThrough?: boolean;
826
824
  /**
827
825
  * The password used to encrypt the content of the entry (raw).
828
826
  */
@@ -873,6 +871,10 @@ export interface EntryMetaData {
873
871
  * `true` if the content of the entry is encrypted.
874
872
  */
875
873
  encrypted: boolean;
874
+ /**
875
+ * `true` if the content of the entry is encrypted with the ZipCrypto algorithm.
876
+ */
877
+ zipCrypto: boolean;
876
878
  /**
877
879
  * The size of the compressed data in bytes.
878
880
  */
@@ -979,19 +981,8 @@ export interface Entry extends EntryMetaData {
979
981
  Writer<unknown> | WritableWriter | WritableStream,
980
982
  boolean
981
983
  >,
982
- options?: EntryGetDataOptions,
984
+ options?: EntryGetDataCheckPasswordOptions
983
985
  ): Promise<Type>;
984
-
985
- /**
986
- * Tests if the password is valid.
987
- *
988
- * @param writer `undefined` or `null`.
989
- * @param options The options with `checkPasswordOnly` set to `true`.
990
- */
991
- getData?(
992
- writer: undefined | null,
993
- options: EntryGetDataCheckPasswordOptions,
994
- ): Promise<void>;
995
986
  }
996
987
 
997
988
  /**
@@ -1004,7 +995,7 @@ export interface EntryGetDataOptions
1004
995
  * Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
1005
996
  */
1006
997
  export interface EntryGetDataCheckPasswordOptions
1007
- extends EntryGetDataOptions, ZipReaderCheckPasswordOptions { }
998
+ extends EntryGetDataOptions { }
1008
999
 
1009
1000
  /**
1010
1001
  * Represents an instance used to create a zipped stream.
@@ -1184,6 +1175,14 @@ export interface ZipWriterAddDataOptions
1184
1175
  * The extra field of the entry.
1185
1176
  */
1186
1177
  extraField?: Map<number, Uint8Array>;
1178
+ /**
1179
+ * The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1180
+ */
1181
+ uncompressedSize?: number;
1182
+ /**
1183
+ * The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is not set to `true`.
1184
+ */
1185
+ signature?: number;
1187
1186
  }
1188
1187
 
1189
1188
  /**
@@ -1365,6 +1364,18 @@ export interface ZipWriterConstructorOptions {
1365
1364
  * @defaultValue false
1366
1365
  */
1367
1366
  usdz?: boolean;
1367
+ /**
1368
+ * `true` to write the data as-is without compressing it and without crypting it.
1369
+ */
1370
+ passThrough?: boolean;
1371
+ /**
1372
+ * `true` to write encrypted data when `passThrough` is set to `true`.
1373
+ */
1374
+ encrypted?: boolean;
1375
+ /**
1376
+ * The offset of the first entry in the zip file.
1377
+ */
1378
+ offset?: number;
1368
1379
  /**
1369
1380
  * Encode the filename and the comment of the entry.
1370
1381
  *
@@ -2054,3 +2065,7 @@ export const ERR_SPLIT_ZIP_FILE: string;
2054
2065
  * Iteration completed too soon error
2055
2066
  */
2056
2067
  export const ERR_ITERATOR_COMPLETED_TOO_SOON: string;
2068
+ /**
2069
+ * Undefined uncompressed size error
2070
+ */
2071
+ export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string
package/index.js CHANGED
@@ -81,6 +81,7 @@ export {
81
81
  ERR_INVALID_EXTRAFIELD_DATA,
82
82
  ERR_INVALID_ENCRYPTION_STRENGTH,
83
83
  ERR_UNSUPPORTED_FORMAT,
84
+ ERR_UNDEFINED_UNCOMPRESSED_SIZE,
84
85
  ERR_SPLIT_ZIP_FILE,
85
86
  ERR_ITERATOR_COMPLETED_TOO_SOON
86
87
  } from "./lib/zip-fs.js";