@zip.js/zip.js 2.6.42 → 2.6.44

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-full.js CHANGED
@@ -7106,7 +7106,7 @@
7106
7106
  }
7107
7107
  }
7108
7108
 
7109
- class SplitZipReader extends Reader {
7109
+ class SplitDataReader extends Reader {
7110
7110
 
7111
7111
  constructor(readers) {
7112
7112
  super();
@@ -7152,7 +7152,7 @@
7152
7152
  }
7153
7153
  }
7154
7154
 
7155
- class SplitZipWriter extends Stream {
7155
+ class SplitDataWriter extends Stream {
7156
7156
 
7157
7157
  constructor(writerGenerator, maxSize = 4294967296) {
7158
7158
  super();
@@ -7173,6 +7173,7 @@
7173
7173
  } else {
7174
7174
  diskSourceWriter = value;
7175
7175
  diskSourceWriter.size = 0;
7176
+ await initStream(diskSourceWriter);
7176
7177
  diskWritable = value.writable;
7177
7178
  diskWriter = diskWritable.getWriter();
7178
7179
  }
@@ -7233,6 +7234,9 @@
7233
7234
  return reader.readUint8Array(offset, size, diskNumber);
7234
7235
  }
7235
7236
 
7237
+ const SplitZipReader = SplitDataReader;
7238
+ const SplitZipWriter = SplitDataWriter;
7239
+
7236
7240
  /*
7237
7241
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
7238
7242
 
@@ -7459,7 +7463,7 @@
7459
7463
  await initStream(reader);
7460
7464
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
7461
7465
  if (Array.isArray(reader)) {
7462
- reader = new SplitZipReader(reader);
7466
+ reader = new SplitDataReader(reader);
7463
7467
  } else {
7464
7468
  reader = new BlobReader(await new Response(reader.readable).blob());
7465
7469
  }
@@ -8037,7 +8041,7 @@
8037
8041
 
8038
8042
  constructor(writer, options = {}) {
8039
8043
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
8040
- writer = new SplitZipWriter(writer);
8044
+ writer = new SplitDataWriter(writer);
8041
8045
  }
8042
8046
  if (writer instanceof WritableStream) {
8043
8047
  writer = { writable: writer };
@@ -8045,7 +8049,7 @@
8045
8049
  if (writer.writable.size === UNDEFINED_VALUE) {
8046
8050
  writer.writable.size = 0;
8047
8051
  }
8048
- const splitZipFile = writer instanceof SplitZipWriter;
8052
+ const splitZipFile = writer instanceof SplitDataWriter;
8049
8053
  if (!splitZipFile) {
8050
8054
  Object.assign(writer, {
8051
8055
  diskNumber: 0,
@@ -8102,13 +8106,15 @@
8102
8106
  }
8103
8107
 
8104
8108
  async close(comment = new Uint8Array(), options = {}) {
8109
+ const zipWriter = this;
8105
8110
  const { pendingAddFileCalls, writer } = this;
8106
8111
  const { writable } = writer;
8107
8112
  while (pendingAddFileCalls.size) {
8108
8113
  await Promise.all(Array.from(pendingAddFileCalls));
8109
8114
  }
8110
8115
  await closeFile(this, comment, options);
8111
- if (!writer.preventClose && !options.preventClose) {
8116
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
8117
+ if (!preventClose) {
8112
8118
  await writable.close();
8113
8119
  }
8114
8120
  return writer.getData ? writer.getData() : writable;
@@ -8131,20 +8137,33 @@
8131
8137
  if (getLength(rawComment) > MAX_16_BITS) {
8132
8138
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
8133
8139
  }
8134
- const version = zipWriter.options.version || options.version || 0;
8140
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
8135
8141
  if (version > MAX_16_BITS) {
8136
8142
  throw new Error(ERR_INVALID_VERSION);
8137
8143
  }
8138
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
8144
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
8139
8145
  if (versionMadeBy > MAX_16_BITS) {
8140
8146
  throw new Error(ERR_INVALID_VERSION);
8141
8147
  }
8142
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
8148
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
8143
8149
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
8144
8150
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
8151
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
8152
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
8153
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
8145
8154
  const password = getOptionValue(zipWriter, options, "password");
8146
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
8155
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
8147
8156
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
8157
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
8158
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
8159
+ const level = getOptionValue(zipWriter, options, "level");
8160
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
8161
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
8162
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
8163
+ const signal = getOptionValue(zipWriter, options, "signal");
8164
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
8165
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
8166
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
8148
8167
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
8149
8168
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
8150
8169
  }
@@ -8168,24 +8187,9 @@
8168
8187
  offset += 4 + getLength(data);
8169
8188
  });
8170
8189
  }
8171
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
8172
- if (extendedTimestamp === UNDEFINED_VALUE) {
8173
- extendedTimestamp = true;
8174
- }
8175
8190
  let maximumCompressedSize = 0;
8176
8191
  let maximumEntrySize = 0;
8177
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
8178
- if (keepOrder === UNDEFINED_VALUE) {
8179
- keepOrder = true;
8180
- }
8181
8192
  let uncompressedSize = 0;
8182
- let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
8183
- if (msDosCompatible === UNDEFINED_VALUE) {
8184
- msDosCompatible = true;
8185
- }
8186
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
8187
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
8188
- let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
8189
8193
  if (reader) {
8190
8194
  if (reader instanceof ReadableStream) {
8191
8195
  reader = {
@@ -8194,7 +8198,7 @@
8194
8198
  }
8195
8199
  await initStream(reader);
8196
8200
  if (reader.size === UNDEFINED_VALUE) {
8197
- options.dataDescriptor = true;
8201
+ dataDescriptor = true;
8198
8202
  if (zip64 || zip64 === UNDEFINED_VALUE) {
8199
8203
  zip64 = true;
8200
8204
  maximumCompressedSize = MAX_32_BITS;
@@ -8204,10 +8208,11 @@
8204
8208
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
8205
8209
  }
8206
8210
  }
8207
- const { diskOffset } = zipWriter.writer;
8211
+ const { diskOffset, diskNumber } = zipWriter.writer;
8208
8212
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
8209
8213
  uncompressedSize >= MAX_32_BITS ||
8210
- maximumCompressedSize >= MAX_32_BITS) {
8214
+ maximumCompressedSize >= MAX_32_BITS ||
8215
+ diskNumber >= MAX_16_BITS) {
8211
8216
  if (zip64 === false || !keepOrder) {
8212
8217
  throw new Error(ERR_UNSUPPORTED_FORMAT);
8213
8218
  } else {
@@ -8215,19 +8220,6 @@
8215
8220
  }
8216
8221
  }
8217
8222
  zip64 = zip64 || false;
8218
- const level = getOptionValue(zipWriter, options, "level");
8219
- const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
8220
- const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
8221
- let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
8222
- let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
8223
- const signal = getOptionValue(zipWriter, options, "signal");
8224
- const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
8225
- if (dataDescriptor === UNDEFINED_VALUE) {
8226
- dataDescriptor = true;
8227
- }
8228
- if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
8229
- dataDescriptorSignature = false;
8230
- }
8231
8223
  options = Object.assign({}, options, {
8232
8224
  rawFilename,
8233
8225
  rawComment,
@@ -8261,12 +8253,8 @@
8261
8253
  let fileEntry;
8262
8254
  try {
8263
8255
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
8256
+ } finally {
8264
8257
  zipWriter.pendingEntriesSize -= maximumEntrySize;
8265
- } catch (error) {
8266
- if (!error.corruptedEntry) {
8267
- zipWriter.pendingEntriesSize -= maximumEntrySize;
8268
- }
8269
- throw error;
8270
8258
  }
8271
8259
  Object.assign(fileEntry, { name, comment, extraField });
8272
8260
  return new Entry(fileEntry);
@@ -8304,8 +8292,7 @@
8304
8292
  await initStream(writer);
8305
8293
  } else {
8306
8294
  fileWriter = writer;
8307
- zipWriter.lockWriter = Promise.resolve();
8308
- releaseLockWriter = () => delete zipWriter.lockWriter;
8295
+ initLockWriter();
8309
8296
  }
8310
8297
  await initStream(fileWriter);
8311
8298
  const { writable, diskNumber } = writer;
@@ -8334,7 +8321,7 @@
8334
8321
  await requestLockWriter();
8335
8322
  writingBufferedEntryData = true;
8336
8323
  if (!dataDescriptor) {
8337
- blob = await setMissingInfo(fileEntry, blob, writable, options);
8324
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
8338
8325
  }
8339
8326
  fileEntry.diskNumberStart = writer.diskNumber;
8340
8327
  diskOffset = writer.diskOffset;
@@ -8344,7 +8331,7 @@
8344
8331
  }
8345
8332
  fileEntry.offset = zipWriter.offset - diskOffset;
8346
8333
  if (fileEntry.zip64) {
8347
- setZip64Info(fileEntry);
8334
+ setZip64OffsetInfo(fileEntry);
8348
8335
  } else if (fileEntry.offset >= MAX_32_BITS) {
8349
8336
  throw new Error(ERR_UNSUPPORTED_FORMAT);
8350
8337
  }
@@ -8377,6 +8364,11 @@
8377
8364
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
8378
8365
  }
8379
8366
 
8367
+ function initLockWriter() {
8368
+ zipWriter.lockWriter = Promise.resolve();
8369
+ releaseLockWriter = () => delete zipWriter.lockWriter;
8370
+ }
8371
+
8380
8372
  async function requestLockWriter() {
8381
8373
  const { lockWriter } = zipWriter;
8382
8374
  if (lockWriter) {
@@ -8535,6 +8527,7 @@
8535
8527
  } = options;
8536
8528
  const compressed = level !== 0 && !directory;
8537
8529
  const encrypted = Boolean(password && getLength(password));
8530
+ let version = options.version;
8538
8531
  let rawExtraFieldAES;
8539
8532
  if (encrypted && !zipCrypto) {
8540
8533
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -8586,7 +8579,6 @@
8586
8579
  if (compressed) {
8587
8580
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
8588
8581
  }
8589
- let version = options.version || VERSION_DEFLATE;
8590
8582
  if (zip64) {
8591
8583
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
8592
8584
  }
@@ -8720,7 +8712,7 @@
8720
8712
  }
8721
8713
  }
8722
8714
 
8723
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
8715
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
8724
8716
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
8725
8717
  const arrayBufferView = new DataView(arrayBuffer);
8726
8718
  if (!fileEntry.encrypted || zipCrypto) {
@@ -8737,7 +8729,7 @@
8737
8729
  return entryData.slice(arrayBuffer.byteLength);
8738
8730
  }
8739
8731
 
8740
- function setZip64Info(fileEntry) {
8732
+ function setZip64OffsetInfo(fileEntry) {
8741
8733
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
8742
8734
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
8743
8735
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -8746,10 +8738,10 @@
8746
8738
 
8747
8739
  async function closeFile(zipWriter, comment, options) {
8748
8740
  const { files, writer } = zipWriter;
8749
- let offset = 0;
8750
- let directoryDataLength = 0;
8751
8741
  const { diskOffset, writable } = writer;
8752
8742
  let { diskNumber } = writer;
8743
+ let offset = 0;
8744
+ let directoryDataLength = 0;
8753
8745
  let directoryOffset = zipWriter.offset - diskOffset;
8754
8746
  let filesLength = files.size;
8755
8747
  for (const [, {
@@ -8771,14 +8763,6 @@
8771
8763
  rawExtraFieldNTFS,
8772
8764
  rawExtraField);
8773
8765
  }
8774
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
8775
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
8776
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
8777
- throw new Error(ERR_UNSUPPORTED_FORMAT);
8778
- } else {
8779
- zip64 = true;
8780
- }
8781
- }
8782
8766
  const directoryArray = new Uint8Array(directoryDataLength);
8783
8767
  const directoryView = getDataView(directoryArray);
8784
8768
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -8844,13 +8828,21 @@
8844
8828
  }
8845
8829
  await initStream(writer);
8846
8830
  await writeData(writable, directoryArray);
8847
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8848
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
8849
8831
  let lastDiskNumber = writer.diskNumber;
8850
8832
  const { availableSize } = writer;
8851
- if (availableSize < getLength(endOfdirectoryArray)) {
8833
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
8852
8834
  lastDiskNumber++;
8853
8835
  }
8836
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
8837
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
8838
+ if (zip64 === false) {
8839
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
8840
+ } else {
8841
+ zip64 = true;
8842
+ }
8843
+ }
8844
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
8845
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
8854
8846
  offset = 0;
8855
8847
  if (zip64) {
8856
8848
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -8915,8 +8907,9 @@
8915
8907
  }
8916
8908
  }
8917
8909
 
8918
- function getOptionValue(zipWriter, options, name) {
8919
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
8910
+ function getOptionValue(zipWriter, options, name, defaultValue) {
8911
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
8912
+ return result === UNDEFINED_VALUE ? defaultValue : result;
8920
8913
  }
8921
8914
 
8922
8915
  function getMaximumCompressedSize(uncompressedSize) {
@@ -9021,6 +9014,8 @@
9021
9014
  exports.HttpRangeReader = HttpRangeReader;
9022
9015
  exports.HttpReader = HttpReader;
9023
9016
  exports.Reader = Reader;
9017
+ exports.SplitDataReader = SplitDataReader;
9018
+ exports.SplitDataWriter = SplitDataWriter;
9024
9019
  exports.SplitZipReader = SplitZipReader;
9025
9020
  exports.SplitZipWriter = SplitZipWriter;
9026
9021
  exports.TextReader = TextReader;