@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.
@@ -8107,7 +8107,7 @@
8107
8107
  }
8108
8108
  }
8109
8109
 
8110
- class SplitZipReader extends Reader {
8110
+ class SplitDataReader extends Reader {
8111
8111
 
8112
8112
  constructor(readers) {
8113
8113
  super();
@@ -8153,7 +8153,7 @@
8153
8153
  }
8154
8154
  }
8155
8155
 
8156
- class SplitZipWriter extends Stream {
8156
+ class SplitDataWriter extends Stream {
8157
8157
 
8158
8158
  constructor(writerGenerator, maxSize = 4294967296) {
8159
8159
  super();
@@ -8174,6 +8174,7 @@
8174
8174
  } else {
8175
8175
  diskSourceWriter = value;
8176
8176
  diskSourceWriter.size = 0;
8177
+ await initStream(diskSourceWriter);
8177
8178
  diskWritable = value.writable;
8178
8179
  diskWriter = diskWritable.getWriter();
8179
8180
  }
@@ -8234,6 +8235,9 @@
8234
8235
  return reader.readUint8Array(offset, size, diskNumber);
8235
8236
  }
8236
8237
 
8238
+ const SplitZipReader = SplitDataReader;
8239
+ const SplitZipWriter = SplitDataWriter;
8240
+
8237
8241
  /*
8238
8242
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
8239
8243
 
@@ -8460,7 +8464,7 @@
8460
8464
  await initStream(reader);
8461
8465
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
8462
8466
  if (Array.isArray(reader)) {
8463
- reader = new SplitZipReader(reader);
8467
+ reader = new SplitDataReader(reader);
8464
8468
  } else {
8465
8469
  reader = new BlobReader(await new Response(reader.readable).blob());
8466
8470
  }
@@ -9038,7 +9042,7 @@
9038
9042
 
9039
9043
  constructor(writer, options = {}) {
9040
9044
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
9041
- writer = new SplitZipWriter(writer);
9045
+ writer = new SplitDataWriter(writer);
9042
9046
  }
9043
9047
  if (writer instanceof WritableStream) {
9044
9048
  writer = { writable: writer };
@@ -9046,7 +9050,7 @@
9046
9050
  if (writer.writable.size === UNDEFINED_VALUE) {
9047
9051
  writer.writable.size = 0;
9048
9052
  }
9049
- const splitZipFile = writer instanceof SplitZipWriter;
9053
+ const splitZipFile = writer instanceof SplitDataWriter;
9050
9054
  if (!splitZipFile) {
9051
9055
  Object.assign(writer, {
9052
9056
  diskNumber: 0,
@@ -9103,13 +9107,15 @@
9103
9107
  }
9104
9108
 
9105
9109
  async close(comment = new Uint8Array(), options = {}) {
9110
+ const zipWriter = this;
9106
9111
  const { pendingAddFileCalls, writer } = this;
9107
9112
  const { writable } = writer;
9108
9113
  while (pendingAddFileCalls.size) {
9109
9114
  await Promise.all(Array.from(pendingAddFileCalls));
9110
9115
  }
9111
9116
  await closeFile(this, comment, options);
9112
- if (!writer.preventClose && !options.preventClose) {
9117
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
9118
+ if (!preventClose) {
9113
9119
  await writable.close();
9114
9120
  }
9115
9121
  return writer.getData ? writer.getData() : writable;
@@ -9132,20 +9138,33 @@
9132
9138
  if (getLength(rawComment) > MAX_16_BITS) {
9133
9139
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
9134
9140
  }
9135
- const version = zipWriter.options.version || options.version || 0;
9141
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
9136
9142
  if (version > MAX_16_BITS) {
9137
9143
  throw new Error(ERR_INVALID_VERSION);
9138
9144
  }
9139
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
9145
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
9140
9146
  if (versionMadeBy > MAX_16_BITS) {
9141
9147
  throw new Error(ERR_INVALID_VERSION);
9142
9148
  }
9143
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
9149
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
9144
9150
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
9145
9151
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
9152
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
9153
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
9154
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
9146
9155
  const password = getOptionValue(zipWriter, options, "password");
9147
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
9156
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
9148
9157
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
9158
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
9159
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
9160
+ const level = getOptionValue(zipWriter, options, "level");
9161
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
9162
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
9163
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
9164
+ const signal = getOptionValue(zipWriter, options, "signal");
9165
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9166
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
9167
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9149
9168
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
9150
9169
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
9151
9170
  }
@@ -9169,24 +9188,9 @@
9169
9188
  offset += 4 + getLength(data);
9170
9189
  });
9171
9190
  }
9172
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
9173
- if (extendedTimestamp === UNDEFINED_VALUE) {
9174
- extendedTimestamp = true;
9175
- }
9176
9191
  let maximumCompressedSize = 0;
9177
9192
  let maximumEntrySize = 0;
9178
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
9179
- if (keepOrder === UNDEFINED_VALUE) {
9180
- keepOrder = true;
9181
- }
9182
9193
  let uncompressedSize = 0;
9183
- let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
9184
- if (msDosCompatible === UNDEFINED_VALUE) {
9185
- msDosCompatible = true;
9186
- }
9187
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
9188
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
9189
- let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9190
9194
  if (reader) {
9191
9195
  if (reader instanceof ReadableStream) {
9192
9196
  reader = {
@@ -9195,7 +9199,7 @@
9195
9199
  }
9196
9200
  await initStream(reader);
9197
9201
  if (reader.size === UNDEFINED_VALUE) {
9198
- options.dataDescriptor = true;
9202
+ dataDescriptor = true;
9199
9203
  if (zip64 || zip64 === UNDEFINED_VALUE) {
9200
9204
  zip64 = true;
9201
9205
  maximumCompressedSize = MAX_32_BITS;
@@ -9205,10 +9209,11 @@
9205
9209
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
9206
9210
  }
9207
9211
  }
9208
- const { diskOffset } = zipWriter.writer;
9212
+ const { diskOffset, diskNumber } = zipWriter.writer;
9209
9213
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
9210
9214
  uncompressedSize >= MAX_32_BITS ||
9211
- maximumCompressedSize >= MAX_32_BITS) {
9215
+ maximumCompressedSize >= MAX_32_BITS ||
9216
+ diskNumber >= MAX_16_BITS) {
9212
9217
  if (zip64 === false || !keepOrder) {
9213
9218
  throw new Error(ERR_UNSUPPORTED_FORMAT);
9214
9219
  } else {
@@ -9216,19 +9221,6 @@
9216
9221
  }
9217
9222
  }
9218
9223
  zip64 = zip64 || false;
9219
- const level = getOptionValue(zipWriter, options, "level");
9220
- const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
9221
- const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
9222
- let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
9223
- let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
9224
- const signal = getOptionValue(zipWriter, options, "signal");
9225
- const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9226
- if (dataDescriptor === UNDEFINED_VALUE) {
9227
- dataDescriptor = true;
9228
- }
9229
- if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
9230
- dataDescriptorSignature = false;
9231
- }
9232
9224
  options = Object.assign({}, options, {
9233
9225
  rawFilename,
9234
9226
  rawComment,
@@ -9262,12 +9254,8 @@
9262
9254
  let fileEntry;
9263
9255
  try {
9264
9256
  fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
9257
+ } finally {
9265
9258
  zipWriter.pendingEntriesSize -= maximumEntrySize;
9266
- } catch (error) {
9267
- if (!error.corruptedEntry) {
9268
- zipWriter.pendingEntriesSize -= maximumEntrySize;
9269
- }
9270
- throw error;
9271
9259
  }
9272
9260
  Object.assign(fileEntry, { name, comment, extraField });
9273
9261
  return new Entry(fileEntry);
@@ -9305,8 +9293,7 @@
9305
9293
  await initStream(writer);
9306
9294
  } else {
9307
9295
  fileWriter = writer;
9308
- zipWriter.lockWriter = Promise.resolve();
9309
- releaseLockWriter = () => delete zipWriter.lockWriter;
9296
+ initLockWriter();
9310
9297
  }
9311
9298
  await initStream(fileWriter);
9312
9299
  const { writable, diskNumber } = writer;
@@ -9335,7 +9322,7 @@
9335
9322
  await requestLockWriter();
9336
9323
  writingBufferedEntryData = true;
9337
9324
  if (!dataDescriptor) {
9338
- blob = await setMissingInfo(fileEntry, blob, writable, options);
9325
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
9339
9326
  }
9340
9327
  fileEntry.diskNumberStart = writer.diskNumber;
9341
9328
  diskOffset = writer.diskOffset;
@@ -9345,7 +9332,7 @@
9345
9332
  }
9346
9333
  fileEntry.offset = zipWriter.offset - diskOffset;
9347
9334
  if (fileEntry.zip64) {
9348
- setZip64Info(fileEntry);
9335
+ setZip64OffsetInfo(fileEntry);
9349
9336
  } else if (fileEntry.offset >= MAX_32_BITS) {
9350
9337
  throw new Error(ERR_UNSUPPORTED_FORMAT);
9351
9338
  }
@@ -9378,6 +9365,11 @@
9378
9365
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
9379
9366
  }
9380
9367
 
9368
+ function initLockWriter() {
9369
+ zipWriter.lockWriter = Promise.resolve();
9370
+ releaseLockWriter = () => delete zipWriter.lockWriter;
9371
+ }
9372
+
9381
9373
  async function requestLockWriter() {
9382
9374
  const { lockWriter } = zipWriter;
9383
9375
  if (lockWriter) {
@@ -9536,6 +9528,7 @@
9536
9528
  } = options;
9537
9529
  const compressed = level !== 0 && !directory;
9538
9530
  const encrypted = Boolean(password && getLength(password));
9531
+ let version = options.version;
9539
9532
  let rawExtraFieldAES;
9540
9533
  if (encrypted && !zipCrypto) {
9541
9534
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -9587,7 +9580,6 @@
9587
9580
  if (compressed) {
9588
9581
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
9589
9582
  }
9590
- let version = options.version || VERSION_DEFLATE;
9591
9583
  if (zip64) {
9592
9584
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
9593
9585
  }
@@ -9721,7 +9713,7 @@
9721
9713
  }
9722
9714
  }
9723
9715
 
9724
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
9716
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
9725
9717
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
9726
9718
  const arrayBufferView = new DataView(arrayBuffer);
9727
9719
  if (!fileEntry.encrypted || zipCrypto) {
@@ -9738,7 +9730,7 @@
9738
9730
  return entryData.slice(arrayBuffer.byteLength);
9739
9731
  }
9740
9732
 
9741
- function setZip64Info(fileEntry) {
9733
+ function setZip64OffsetInfo(fileEntry) {
9742
9734
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
9743
9735
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
9744
9736
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -9747,10 +9739,10 @@
9747
9739
 
9748
9740
  async function closeFile(zipWriter, comment, options) {
9749
9741
  const { files, writer } = zipWriter;
9750
- let offset = 0;
9751
- let directoryDataLength = 0;
9752
9742
  const { diskOffset, writable } = writer;
9753
9743
  let { diskNumber } = writer;
9744
+ let offset = 0;
9745
+ let directoryDataLength = 0;
9754
9746
  let directoryOffset = zipWriter.offset - diskOffset;
9755
9747
  let filesLength = files.size;
9756
9748
  for (const [, {
@@ -9772,14 +9764,6 @@
9772
9764
  rawExtraFieldNTFS,
9773
9765
  rawExtraField);
9774
9766
  }
9775
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
9776
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
9777
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
9778
- throw new Error(ERR_UNSUPPORTED_FORMAT);
9779
- } else {
9780
- zip64 = true;
9781
- }
9782
- }
9783
9767
  const directoryArray = new Uint8Array(directoryDataLength);
9784
9768
  const directoryView = getDataView(directoryArray);
9785
9769
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -9845,13 +9829,21 @@
9845
9829
  }
9846
9830
  await initStream(writer);
9847
9831
  await writeData(writable, directoryArray);
9848
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
9849
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
9850
9832
  let lastDiskNumber = writer.diskNumber;
9851
9833
  const { availableSize } = writer;
9852
- if (availableSize < getLength(endOfdirectoryArray)) {
9834
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
9853
9835
  lastDiskNumber++;
9854
9836
  }
9837
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
9838
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
9839
+ if (zip64 === false) {
9840
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
9841
+ } else {
9842
+ zip64 = true;
9843
+ }
9844
+ }
9845
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
9846
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
9855
9847
  offset = 0;
9856
9848
  if (zip64) {
9857
9849
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -9916,8 +9908,9 @@
9916
9908
  }
9917
9909
  }
9918
9910
 
9919
- function getOptionValue(zipWriter, options, name) {
9920
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9911
+ function getOptionValue(zipWriter, options, name, defaultValue) {
9912
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9913
+ return result === UNDEFINED_VALUE ? defaultValue : result;
9921
9914
  }
9922
9915
 
9923
9916
  function getMaximumCompressedSize(uncompressedSize) {
@@ -10603,7 +10596,7 @@
10603
10596
  configure({ baseURL });
10604
10597
  e(configure);
10605
10598
 
10606
- /// <reference types="./index" />
10599
+ /// <reference types="./index.d.ts" />
10607
10600
 
10608
10601
  configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
10609
10602
 
@@ -10638,6 +10631,8 @@
10638
10631
  exports.HttpRangeReader = HttpRangeReader;
10639
10632
  exports.HttpReader = HttpReader;
10640
10633
  exports.Reader = Reader;
10634
+ exports.SplitDataReader = SplitDataReader;
10635
+ exports.SplitDataWriter = SplitDataWriter;
10641
10636
  exports.SplitZipReader = SplitZipReader;
10642
10637
  exports.SplitZipWriter = SplitZipWriter;
10643
10638
  exports.TextReader = TextReader;