@zip.js/zip.js 2.11.1 → 2.11.2

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
@@ -3608,11 +3608,10 @@ class Reader extends Stream {
3608
3608
  const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
3609
3609
  if (data.length) {
3610
3610
  controller.enqueue(data);
3611
+ chunkOffset += data.length;
3611
3612
  }
3612
- if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
3613
+ if ((size !== UNDEFINED_VALUE && chunkOffset >= size) || (!data.length && dataSize)) {
3613
3614
  controller.close();
3614
- } else {
3615
- chunkOffset += chunkSize;
3616
3615
  }
3617
3616
  }
3618
3617
  });
@@ -6323,6 +6322,7 @@ class ZipWriter {
6323
6322
  pendingAddFileCalls: new Set(),
6324
6323
  pendingErrors: [],
6325
6324
  bufferedWrites: 0,
6325
+ directWrites: 0,
6326
6326
  lastFileEntry: UNDEFINED_VALUE
6327
6327
  });
6328
6328
  }
@@ -7173,6 +7173,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
7173
7173
  const usdz = zipWriter.options[OPTION_USDZ];
7174
7174
  let fileEntry = pendingFileEntry;
7175
7175
  let bufferedWrite;
7176
+ let directWrite;
7176
7177
  let releaseLockWriter;
7177
7178
  let writingBufferedEntryData;
7178
7179
  let writingEntryData;
@@ -7182,7 +7183,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
7182
7183
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7183
7184
  fileEntries.set(name, fileEntry);
7184
7185
  try {
7185
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7186
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
7186
7187
  bufferedWrite = true;
7187
7188
  zipWriter.bufferedWrites++;
7188
7189
  if (options.createTempStream) {
@@ -7193,6 +7194,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
7193
7194
  fileWriter.size = 0;
7194
7195
  await initStream(writer);
7195
7196
  } else {
7197
+ directWrite = true;
7198
+ zipWriter.directWrites++;
7196
7199
  fileWriter = writer;
7197
7200
  await lockPreviousFileEntry;
7198
7201
  await requestLockWriter();
@@ -7271,6 +7274,9 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
7271
7274
  if (bufferedWrite) {
7272
7275
  zipWriter.bufferedWrites--;
7273
7276
  }
7277
+ if (directWrite) {
7278
+ zipWriter.directWrites--;
7279
+ }
7274
7280
  if (releaseLockFileEntry) {
7275
7281
  releaseLockFileEntry(lockPreviousFileEntry);
7276
7282
  }
@@ -7415,8 +7421,8 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
7415
7421
  }
7416
7422
  const { writable } = writer;
7417
7423
  if (reader) {
7418
- const readable = toCompatibleReadable(createReadable(reader));
7419
7424
  const size = reader.size;
7425
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
7420
7426
  const workerOptions = {
7421
7427
  options: {
7422
7428
  codecType: CODEC_DEFLATE,
@@ -8595,7 +8601,7 @@ function formatSupported(StreamClass, format) {
8595
8601
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8596
8602
  */
8597
8603
 
8598
- const VERSION = "2.11.1";
8604
+ const VERSION = "2.11.2";
8599
8605
 
8600
8606
  /*
8601
8607
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
package/index.d.cts CHANGED
@@ -3112,10 +3112,9 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3112
3112
  * `true` to keep the order of the entry physically in the zip file.
3113
3113
  *
3114
3114
  * @remarks
3115
- * The entries are then written one after another, so concurrent calls to {@link ZipWriter#add} compress one
3116
- * entry at a time and use a single web worker. Set {@link ZipWriterConstructorOptions#bufferedWrite} to `true`
3117
- * to compress them concurrently while still keeping the order, at the cost of buffering each entry until the
3118
- * previous ones are written.
3115
+ * The entries are then written one after another, but concurrent calls to {@link ZipWriter#add} still compress
3116
+ * concurrently: one entry is written directly into the zip file while the others are buffered until it is their
3117
+ * turn, i.e. {@link ZipWriterConstructorOptions#bufferedWrite} is set automatically for them.
3119
3118
  *
3120
3119
  * @defaultValue true
3121
3120
  */
package/index.d.ts CHANGED
@@ -3112,10 +3112,9 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3112
3112
  * `true` to keep the order of the entry physically in the zip file.
3113
3113
  *
3114
3114
  * @remarks
3115
- * The entries are then written one after another, so concurrent calls to {@link ZipWriter#add} compress one
3116
- * entry at a time and use a single web worker. Set {@link ZipWriterConstructorOptions#bufferedWrite} to `true`
3117
- * to compress them concurrently while still keeping the order, at the cost of buffering each entry until the
3118
- * previous ones are written.
3115
+ * The entries are then written one after another, but concurrent calls to {@link ZipWriter#add} still compress
3116
+ * concurrently: one entry is written directly into the zip file while the others are buffered until it is their
3117
+ * turn, i.e. {@link ZipWriterConstructorOptions#bufferedWrite} is set automatically for them.
3119
3118
  *
3120
3119
  * @defaultValue true
3121
3120
  */