@zip.js/zip.js 2.6.43 → 2.6.45

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
@@ -8103,7 +8103,7 @@ class Uint8ArrayWriter extends Writer {
8103
8103
  }
8104
8104
  }
8105
8105
 
8106
- class SplitZipReader extends Reader {
8106
+ class SplitDataReader extends Reader {
8107
8107
 
8108
8108
  constructor(readers) {
8109
8109
  super();
@@ -8149,7 +8149,7 @@ class SplitZipReader extends Reader {
8149
8149
  }
8150
8150
  }
8151
8151
 
8152
- class SplitZipWriter extends Stream {
8152
+ class SplitDataWriter extends Stream {
8153
8153
 
8154
8154
  constructor(writerGenerator, maxSize = 4294967296) {
8155
8155
  super();
@@ -8158,6 +8158,7 @@ class SplitZipWriter extends Stream {
8158
8158
  diskNumber: 0,
8159
8159
  diskOffset: 0,
8160
8160
  size: 0,
8161
+ maxSize,
8161
8162
  availableSize: maxSize
8162
8163
  });
8163
8164
  let diskSourceWriter, diskWritable, diskWriter;
@@ -8170,6 +8171,7 @@ class SplitZipWriter extends Stream {
8170
8171
  } else {
8171
8172
  diskSourceWriter = value;
8172
8173
  diskSourceWriter.size = 0;
8174
+ await initStream(diskSourceWriter);
8173
8175
  diskWritable = value.writable;
8174
8176
  diskWriter = diskWritable.getWriter();
8175
8177
  }
@@ -8230,6 +8232,9 @@ function readUint8Array(reader, offset, size, diskNumber) {
8230
8232
  return reader.readUint8Array(offset, size, diskNumber);
8231
8233
  }
8232
8234
 
8235
+ const SplitZipReader = SplitDataReader;
8236
+ const SplitZipWriter = SplitDataWriter;
8237
+
8233
8238
  /*
8234
8239
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
8235
8240
 
@@ -8456,7 +8461,7 @@ class ZipReader {
8456
8461
  await initStream(reader);
8457
8462
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
8458
8463
  if (Array.isArray(reader)) {
8459
- reader = new SplitZipReader(reader);
8464
+ reader = new SplitDataReader(reader);
8460
8465
  } else {
8461
8466
  reader = new BlobReader(await new Response(reader.readable).blob());
8462
8467
  }
@@ -9034,7 +9039,7 @@ class ZipWriter {
9034
9039
 
9035
9040
  constructor(writer, options = {}) {
9036
9041
  if (writer.writable === UNDEFINED_VALUE && typeof writer.next == FUNCTION_TYPE$1) {
9037
- writer = new SplitZipWriter(writer);
9042
+ writer = new SplitDataWriter(writer);
9038
9043
  }
9039
9044
  if (writer instanceof WritableStream) {
9040
9045
  writer = { writable: writer };
@@ -9042,12 +9047,13 @@ class ZipWriter {
9042
9047
  if (writer.writable.size === UNDEFINED_VALUE) {
9043
9048
  writer.writable.size = 0;
9044
9049
  }
9045
- const splitZipFile = writer instanceof SplitZipWriter;
9050
+ const splitZipFile = writer instanceof SplitDataWriter;
9046
9051
  if (!splitZipFile) {
9047
9052
  Object.assign(writer, {
9048
9053
  diskNumber: 0,
9049
9054
  diskOffset: 0,
9050
- availableSize: Infinity
9055
+ availableSize: Infinity,
9056
+ maxSize: Infinity
9051
9057
  });
9052
9058
  }
9053
9059
  Object.assign(this, {
@@ -9099,13 +9105,15 @@ class ZipWriter {
9099
9105
  }
9100
9106
 
9101
9107
  async close(comment = new Uint8Array(), options = {}) {
9108
+ const zipWriter = this;
9102
9109
  const { pendingAddFileCalls, writer } = this;
9103
9110
  const { writable } = writer;
9104
9111
  while (pendingAddFileCalls.size) {
9105
9112
  await Promise.all(Array.from(pendingAddFileCalls));
9106
9113
  }
9107
9114
  await closeFile(this, comment, options);
9108
- if (!writer.preventClose && !options.preventClose) {
9115
+ const preventClose = getOptionValue(zipWriter, options, "preventClose");
9116
+ if (!preventClose) {
9109
9117
  await writable.close();
9110
9118
  }
9111
9119
  return writer.getData ? writer.getData() : writable;
@@ -9128,20 +9136,33 @@ async function addFile(zipWriter, name, reader, options) {
9128
9136
  if (getLength(rawComment) > MAX_16_BITS) {
9129
9137
  throw new Error(ERR_INVALID_ENTRY_COMMENT);
9130
9138
  }
9131
- const version = zipWriter.options.version || options.version || 0;
9139
+ const version = getOptionValue(zipWriter, options, "version", VERSION_DEFLATE);
9132
9140
  if (version > MAX_16_BITS) {
9133
9141
  throw new Error(ERR_INVALID_VERSION);
9134
9142
  }
9135
- const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
9143
+ const versionMadeBy = getOptionValue(zipWriter, options, "versionMadeBy", 20);
9136
9144
  if (versionMadeBy > MAX_16_BITS) {
9137
9145
  throw new Error(ERR_INVALID_VERSION);
9138
9146
  }
9139
- const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
9147
+ const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE, new Date());
9140
9148
  const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
9141
9149
  const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
9150
+ const msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE, true);
9151
+ const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, 0);
9152
+ const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, 0);
9142
9153
  const password = getOptionValue(zipWriter, options, "password");
9143
- const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
9154
+ const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength", 3);
9144
9155
  const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
9156
+ const extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp", true);
9157
+ const keepOrder = getOptionValue(zipWriter, options, "keepOrder", true);
9158
+ const level = getOptionValue(zipWriter, options, "level");
9159
+ const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
9160
+ const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
9161
+ const dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature", false);
9162
+ const signal = getOptionValue(zipWriter, options, "signal");
9163
+ const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9164
+ let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor", true);
9165
+ let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9145
9166
  if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
9146
9167
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
9147
9168
  }
@@ -9165,24 +9186,9 @@ async function addFile(zipWriter, name, reader, options) {
9165
9186
  offset += 4 + getLength(data);
9166
9187
  });
9167
9188
  }
9168
- let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
9169
- if (extendedTimestamp === UNDEFINED_VALUE) {
9170
- extendedTimestamp = true;
9171
- }
9172
9189
  let maximumCompressedSize = 0;
9173
9190
  let maximumEntrySize = 0;
9174
- let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
9175
- if (keepOrder === UNDEFINED_VALUE) {
9176
- keepOrder = true;
9177
- }
9178
9191
  let uncompressedSize = 0;
9179
- let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
9180
- if (msDosCompatible === UNDEFINED_VALUE) {
9181
- msDosCompatible = true;
9182
- }
9183
- const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
9184
- const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
9185
- let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
9186
9192
  if (reader) {
9187
9193
  if (reader instanceof ReadableStream) {
9188
9194
  reader = {
@@ -9191,7 +9197,7 @@ async function addFile(zipWriter, name, reader, options) {
9191
9197
  }
9192
9198
  await initStream(reader);
9193
9199
  if (reader.size === UNDEFINED_VALUE) {
9194
- options.dataDescriptor = true;
9200
+ dataDescriptor = true;
9195
9201
  if (zip64 || zip64 === UNDEFINED_VALUE) {
9196
9202
  zip64 = true;
9197
9203
  maximumCompressedSize = MAX_32_BITS;
@@ -9201,10 +9207,11 @@ async function addFile(zipWriter, name, reader, options) {
9201
9207
  maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
9202
9208
  }
9203
9209
  }
9204
- const { diskOffset } = zipWriter.writer;
9210
+ const { diskOffset, diskNumber, maxSize } = zipWriter.writer;
9205
9211
  if (zipWriter.offset + zipWriter.pendingEntriesSize - diskOffset >= MAX_32_BITS ||
9206
9212
  uncompressedSize >= MAX_32_BITS ||
9207
- maximumCompressedSize >= MAX_32_BITS) {
9213
+ maximumCompressedSize >= MAX_32_BITS ||
9214
+ diskNumber + Math.ceil(zipWriter.pendingEntriesSize / maxSize) >= MAX_16_BITS) {
9208
9215
  if (zip64 === false || !keepOrder) {
9209
9216
  throw new Error(ERR_UNSUPPORTED_FORMAT);
9210
9217
  } else {
@@ -9212,19 +9219,6 @@ async function addFile(zipWriter, name, reader, options) {
9212
9219
  }
9213
9220
  }
9214
9221
  zip64 = zip64 || false;
9215
- const level = getOptionValue(zipWriter, options, "level");
9216
- const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
9217
- const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
9218
- let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
9219
- let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
9220
- const signal = getOptionValue(zipWriter, options, "signal");
9221
- const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
9222
- if (dataDescriptor === UNDEFINED_VALUE) {
9223
- dataDescriptor = true;
9224
- }
9225
- if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
9226
- dataDescriptorSignature = false;
9227
- }
9228
9222
  options = Object.assign({}, options, {
9229
9223
  rawFilename,
9230
9224
  rawComment,
@@ -9297,8 +9291,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
9297
9291
  await initStream(writer);
9298
9292
  } else {
9299
9293
  fileWriter = writer;
9300
- zipWriter.lockWriter = Promise.resolve();
9301
- releaseLockWriter = () => delete zipWriter.lockWriter;
9294
+ initLockWriter();
9302
9295
  }
9303
9296
  await initStream(fileWriter);
9304
9297
  const { writable, diskNumber } = writer;
@@ -9327,7 +9320,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
9327
9320
  await requestLockWriter();
9328
9321
  writingBufferedEntryData = true;
9329
9322
  if (!dataDescriptor) {
9330
- blob = await setMissingInfo(fileEntry, blob, writable, options);
9323
+ blob = await writeMissingHeaderInfo(fileEntry, blob, writable, options);
9331
9324
  }
9332
9325
  fileEntry.diskNumberStart = writer.diskNumber;
9333
9326
  diskOffset = writer.diskOffset;
@@ -9337,7 +9330,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
9337
9330
  }
9338
9331
  fileEntry.offset = zipWriter.offset - diskOffset;
9339
9332
  if (fileEntry.zip64) {
9340
- setZip64Info(fileEntry);
9333
+ setZip64OffsetInfo(fileEntry);
9341
9334
  } else if (fileEntry.offset >= MAX_32_BITS) {
9342
9335
  throw new Error(ERR_UNSUPPORTED_FORMAT);
9343
9336
  }
@@ -9370,6 +9363,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
9370
9363
  fileEntry.lock = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
9371
9364
  }
9372
9365
 
9366
+ function initLockWriter() {
9367
+ zipWriter.lockWriter = Promise.resolve();
9368
+ releaseLockWriter = () => delete zipWriter.lockWriter;
9369
+ }
9370
+
9373
9371
  async function requestLockWriter() {
9374
9372
  const { lockWriter } = zipWriter;
9375
9373
  if (lockWriter) {
@@ -9528,6 +9526,7 @@ function getHeaderInfo(options) {
9528
9526
  } = options;
9529
9527
  const compressed = level !== 0 && !directory;
9530
9528
  const encrypted = Boolean(password && getLength(password));
9529
+ let version = options.version;
9531
9530
  let rawExtraFieldAES;
9532
9531
  if (encrypted && !zipCrypto) {
9533
9532
  rawExtraFieldAES = new Uint8Array(getLength(EXTRAFIELD_DATA_AES) + 2);
@@ -9579,7 +9578,6 @@ function getHeaderInfo(options) {
9579
9578
  if (compressed) {
9580
9579
  compressionMethod = COMPRESSION_METHOD_DEFLATE;
9581
9580
  }
9582
- let version = options.version || VERSION_DEFLATE;
9583
9581
  if (zip64) {
9584
9582
  version = version > VERSION_ZIP64 ? version : VERSION_ZIP64;
9585
9583
  }
@@ -9713,7 +9711,7 @@ function setEntryInfo(entryInfo, options) {
9713
9711
  }
9714
9712
  }
9715
9713
 
9716
- async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
9714
+ async function writeMissingHeaderInfo(fileEntry, entryData, writable, { zipCrypto }) {
9717
9715
  const arrayBuffer = await sliceAsArrayBuffer(entryData, 0, 26);
9718
9716
  const arrayBufferView = new DataView(arrayBuffer);
9719
9717
  if (!fileEntry.encrypted || zipCrypto) {
@@ -9730,7 +9728,7 @@ async function setMissingInfo(fileEntry, entryData, writable, { zipCrypto }) {
9730
9728
  return entryData.slice(arrayBuffer.byteLength);
9731
9729
  }
9732
9730
 
9733
- function setZip64Info(fileEntry) {
9731
+ function setZip64OffsetInfo(fileEntry) {
9734
9732
  const { rawExtraFieldZip64, offset, diskNumberStart } = fileEntry;
9735
9733
  const rawExtraFieldZip64View = getDataView(rawExtraFieldZip64);
9736
9734
  setBigUint64(rawExtraFieldZip64View, 20, BigInt(offset));
@@ -9739,10 +9737,10 @@ function setZip64Info(fileEntry) {
9739
9737
 
9740
9738
  async function closeFile(zipWriter, comment, options) {
9741
9739
  const { files, writer } = zipWriter;
9742
- let offset = 0;
9743
- let directoryDataLength = 0;
9744
9740
  const { diskOffset, writable } = writer;
9745
9741
  let { diskNumber } = writer;
9742
+ let offset = 0;
9743
+ let directoryDataLength = 0;
9746
9744
  let directoryOffset = zipWriter.offset - diskOffset;
9747
9745
  let filesLength = files.size;
9748
9746
  for (const [, {
@@ -9764,14 +9762,6 @@ async function closeFile(zipWriter, comment, options) {
9764
9762
  rawExtraFieldNTFS,
9765
9763
  rawExtraField);
9766
9764
  }
9767
- let zip64 = options.zip64 || zipWriter.options.zip64 || false;
9768
- if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
9769
- if (options.zip64 === false || zipWriter.options.zip64 === false) {
9770
- throw new Error(ERR_UNSUPPORTED_FORMAT);
9771
- } else {
9772
- zip64 = true;
9773
- }
9774
- }
9775
9765
  const directoryArray = new Uint8Array(directoryDataLength);
9776
9766
  const directoryView = getDataView(directoryArray);
9777
9767
  for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
@@ -9837,13 +9827,21 @@ async function closeFile(zipWriter, comment, options) {
9837
9827
  }
9838
9828
  await initStream(writer);
9839
9829
  await writeData(writable, directoryArray);
9840
- const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
9841
- const endOfdirectoryView = getDataView(endOfdirectoryArray);
9842
9830
  let lastDiskNumber = writer.diskNumber;
9843
9831
  const { availableSize } = writer;
9844
- if (availableSize < getLength(endOfdirectoryArray)) {
9832
+ if (availableSize < END_OF_CENTRAL_DIR_LENGTH) {
9845
9833
  lastDiskNumber++;
9846
9834
  }
9835
+ let zip64 = getOptionValue(zipWriter, options, "zip64");
9836
+ if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS || lastDiskNumber >= MAX_16_BITS) {
9837
+ if (zip64 === false) {
9838
+ throw new Error(ERR_UNSUPPORTED_FORMAT);
9839
+ } else {
9840
+ zip64 = true;
9841
+ }
9842
+ }
9843
+ const endOfdirectoryArray = new Uint8Array(zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH);
9844
+ const endOfdirectoryView = getDataView(endOfdirectoryArray);
9847
9845
  offset = 0;
9848
9846
  if (zip64) {
9849
9847
  setUint32(endOfdirectoryView, 0, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
@@ -9908,8 +9906,9 @@ function getTimeNTFS(date) {
9908
9906
  }
9909
9907
  }
9910
9908
 
9911
- function getOptionValue(zipWriter, options, name) {
9912
- return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9909
+ function getOptionValue(zipWriter, options, name, defaultValue) {
9910
+ const result = options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
9911
+ return result === UNDEFINED_VALUE ? defaultValue : result;
9913
9912
  }
9914
9913
 
9915
9914
  function getMaximumCompressedSize(uncompressedSize) {
@@ -10595,7 +10594,7 @@ try {
10595
10594
  configure({ baseURL });
10596
10595
  e(configure);
10597
10596
 
10598
- /// <reference types="./index" />
10597
+ /// <reference types="./index.d.ts" />
10599
10598
 
10600
10599
  configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
10601
10600
 
@@ -10630,6 +10629,8 @@ exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
10630
10629
  exports.HttpRangeReader = HttpRangeReader;
10631
10630
  exports.HttpReader = HttpReader;
10632
10631
  exports.Reader = Reader;
10632
+ exports.SplitDataReader = SplitDataReader;
10633
+ exports.SplitDataWriter = SplitDataWriter;
10633
10634
  exports.SplitZipReader = SplitZipReader;
10634
10635
  exports.SplitZipWriter = SplitZipWriter;
10635
10636
  exports.TextReader = TextReader;
package/index.d.ts CHANGED
@@ -365,10 +365,17 @@ export class Data64URIReader extends Reader<string> { }
365
365
  */
366
366
  export class Uint8ArrayReader extends Reader<Uint8Array> { }
367
367
 
368
+ /**
369
+ * Represents a `Reader` instance used to read data provided as an array of `Reader` instances (i.e. split zip files).
370
+ *
371
+ * @deprecated Use {@link SplitDataReader} instead.
372
+ */
373
+ export class SplitZipReader extends SplitDataReader
374
+
368
375
  /**
369
376
  * Represents a `Reader` instance used to read data provided as an array of `Reader` instances (i.e. split zip files).
370
377
  */
371
- export class SplitZipReader extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> { }
378
+ export class SplitDataReader extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> { }
372
379
 
373
380
  /**
374
381
  * Represents a URL stored into a `string`.
@@ -554,10 +561,17 @@ export class Data64URIWriter extends Writer<string> {
554
561
  constructor(mimeString?: string)
555
562
  }
556
563
 
564
+ /**
565
+ * Represents a `Writer` instance used to retrieve the written data from a generator of `Writer` instances (i.e. split zip files).
566
+ *
567
+ * @deprecated Use {@link SplitDataWriter} instead.
568
+ */
569
+ export class SplitZipWriter extends SplitDataWriter
570
+
557
571
  /**
558
572
  * Represents a `Writer` instance used to retrieve the written data from a generator of `Writer` instances (i.e. split zip files).
559
573
  */
560
- export class SplitZipWriter implements Initializable, WritableWriter {
574
+ export class SplitDataWriter implements Initializable, WritableWriter {
561
575
  /**
562
576
  * The `WritableStream` instance.
563
577
  */
@@ -567,7 +581,7 @@ export class SplitZipWriter implements Initializable, WritableWriter {
567
581
  */
568
582
  init(): Promise<void>
569
583
  /**
570
- * Creates the `SplitZipWriter` instance
584
+ * Creates the `SplitDataWriter` instance
571
585
  *
572
586
  * @param writerGenerator The MIME type of the content.
573
587
  * @param maxSize The maximum size of the data written into `Writer` instances (default: 4GB).
@@ -875,7 +889,7 @@ export class ZipWriter<Type> {
875
889
  * @param writer The `Writer` instance where the zip content will be written.
876
890
  * @param options The options.
877
891
  */
878
- constructor(writer: Writer<Type> | WritableWriter | WritableStream | SplitZipWriter | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream, boolean>, options?: ZipWriterConstructorOptions)
892
+ constructor(writer: Writer<Type> | WritableWriter | WritableStream | AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream, boolean>, options?: ZipWriterConstructorOptions)
879
893
  /**
880
894
  * `true` if the zip contains at least one entry that has been partially written.
881
895
  */
@@ -949,6 +963,12 @@ interface ZipWriterConstructorOptions {
949
963
  * @defaultValue false
950
964
  */
951
965
  zip64?: boolean
966
+ /**
967
+ * `true` to prevent closing of `Writer#writable`.
968
+ *
969
+ * @defaultValue false
970
+ */
971
+ preventClose?: boolean
952
972
  /**
953
973
  * The level of compression.
954
974
  *
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference types="./index" />
1
+ /// <reference types="./index.d.ts" />
2
2
 
3
3
  /*
4
4
  Copyright (c) 2022 Gildas Lormeau. All rights reserved.
@@ -56,6 +56,8 @@ export {
56
56
  Uint8ArrayReader,
57
57
  SplitZipReader,
58
58
  SplitZipWriter,
59
+ SplitDataReader,
60
+ SplitDataWriter,
59
61
  ERR_HTTP_RANGE,
60
62
  ERR_BAD_FORMAT,
61
63
  ERR_EOCDR_NOT_FOUND,
package/lib/core/io.js CHANGED
@@ -521,7 +521,7 @@ class Uint8ArrayWriter extends Writer {
521
521
  }
522
522
  }
523
523
 
524
- class SplitZipReader extends Reader {
524
+ class SplitDataReader extends Reader {
525
525
 
526
526
  constructor(readers) {
527
527
  super();
@@ -567,7 +567,7 @@ class SplitZipReader extends Reader {
567
567
  }
568
568
  }
569
569
 
570
- class SplitZipWriter extends Stream {
570
+ class SplitDataWriter extends Stream {
571
571
 
572
572
  constructor(writerGenerator, maxSize = 4294967296) {
573
573
  super();
@@ -576,6 +576,7 @@ class SplitZipWriter extends Stream {
576
576
  diskNumber: 0,
577
577
  diskOffset: 0,
578
578
  size: 0,
579
+ maxSize,
579
580
  availableSize: maxSize
580
581
  });
581
582
  let diskSourceWriter, diskWritable, diskWriter;
@@ -588,6 +589,7 @@ class SplitZipWriter extends Stream {
588
589
  } else {
589
590
  diskSourceWriter = value;
590
591
  diskSourceWriter.size = 0;
592
+ await initStream(diskSourceWriter);
591
593
  diskWritable = value.writable;
592
594
  diskWriter = diskWritable.getWriter();
593
595
  }
@@ -648,6 +650,9 @@ function readUint8Array(reader, offset, size, diskNumber) {
648
650
  return reader.readUint8Array(offset, size, diskNumber);
649
651
  }
650
652
 
653
+ const SplitZipReader = SplitDataReader;
654
+ const SplitZipWriter = SplitDataWriter;
655
+
651
656
  export {
652
657
  initStream,
653
658
  readUint8Array,
@@ -665,6 +670,8 @@ export {
665
670
  HttpRangeReader,
666
671
  SplitZipReader,
667
672
  SplitZipWriter,
673
+ SplitDataReader,
674
+ SplitDataWriter,
668
675
  ERR_HTTP_RANGE,
669
676
  ERR_ITERATOR_COMPLETED_TOO_SOON
670
677
  };
@@ -73,7 +73,7 @@ import {
73
73
  initStream,
74
74
  readUint8Array,
75
75
  BlobReader,
76
- SplitZipReader
76
+ SplitDataReader
77
77
  } from "./io.js";
78
78
  import { decodeText } from "./util/decode-text.js";
79
79
  import { Crc32 } from "./streams/codecs/crc32.js";
@@ -147,7 +147,7 @@ class ZipReader {
147
147
  await initStream(reader);
148
148
  if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
149
149
  if (Array.isArray(reader)) {
150
- reader = new SplitZipReader(reader);
150
+ reader = new SplitDataReader(reader);
151
151
  } else {
152
152
  reader = new BlobReader(await new Response(reader.readable).blob());
153
153
  }