@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/lib/core/io.js CHANGED
@@ -91,11 +91,10 @@ class Reader extends Stream {
91
91
  const data = await readUint8Array(reader, offset + chunkOffset, dataSize);
92
92
  if (data.length) {
93
93
  controller.enqueue(data);
94
+ chunkOffset += data.length;
94
95
  }
95
- if ((chunkOffset + chunkSize >= size) || (!data.length && dataSize)) {
96
+ if ((size !== UNDEFINED_VALUE && chunkOffset >= size) || (!data.length && dataSize)) {
96
97
  controller.close();
97
- } else {
98
- chunkOffset += chunkSize;
99
98
  }
100
99
  }
101
100
  });
@@ -26,6 +26,6 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- const VERSION = "2.11.1";
29
+ const VERSION = "2.11.2";
30
30
 
31
31
  export { VERSION };
@@ -63,6 +63,10 @@
63
63
  * failing before they reach getFileEntry().
64
64
  * - `zipWriter.lockWriter`/`writerLocked` is the mutex over the writer; only the holder may write
65
65
  * into it or read the position variables above.
66
+ * - At most one entry is written directly into the writer at a time, every other one is buffered.
67
+ * `bufferedWrites`/`directWrites` record the choice in the same synchronous block that makes it,
68
+ * because `writerLocked` is only raised an await later: concurrent add() calls all decide before
69
+ * that, and would all pick the direct path and then serialize on the previous entry's lock.
66
70
  * - Both write paths await the lock of the previous entry before requesting the writer lock.
67
71
  * Requesting it first would deadlock an entry written directly into the writer (i.e. without
68
72
  * being buffered) against a buffered predecessor, which needs that same lock to be flushed.
@@ -306,6 +310,7 @@ class ZipWriter {
306
310
  pendingAddFileCalls: new Set(),
307
311
  pendingErrors: [],
308
312
  bufferedWrites: 0,
313
+ directWrites: 0,
309
314
  lastFileEntry: UNDEFINED_VALUE
310
315
  });
311
316
  }
@@ -1194,6 +1199,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
1194
1199
  const usdz = zipWriter.options[OPTION_USDZ];
1195
1200
  let fileEntry = pendingFileEntry;
1196
1201
  let bufferedWrite;
1202
+ let directWrite;
1197
1203
  let releaseLockWriter;
1198
1204
  let writingBufferedEntryData;
1199
1205
  let writingEntryData;
@@ -1203,7 +1209,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
1203
1209
  const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
1204
1210
  fileEntries.set(name, fileEntry);
1205
1211
  try {
1206
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
1212
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || zipWriter.directWrites || (!dataDescriptor && !emptyEntry)) {
1207
1213
  bufferedWrite = true;
1208
1214
  zipWriter.bufferedWrites++;
1209
1215
  if (options.createTempStream) {
@@ -1214,6 +1220,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
1214
1220
  fileWriter.size = 0;
1215
1221
  await initStream(writer);
1216
1222
  } else {
1223
+ directWrite = true;
1224
+ zipWriter.directWrites++;
1217
1225
  fileWriter = writer;
1218
1226
  await lockPreviousFileEntry;
1219
1227
  await requestLockWriter();
@@ -1292,6 +1300,9 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
1292
1300
  if (bufferedWrite) {
1293
1301
  zipWriter.bufferedWrites--;
1294
1302
  }
1303
+ if (directWrite) {
1304
+ zipWriter.directWrites--;
1305
+ }
1295
1306
  if (releaseLockFileEntry) {
1296
1307
  releaseLockFileEntry(lockPreviousFileEntry);
1297
1308
  }
@@ -1436,8 +1447,8 @@ async function createFileEntry(reader, writer, { diskNumberStart, lockFileEntry
1436
1447
  }
1437
1448
  const { writable } = writer;
1438
1449
  if (reader) {
1439
- const readable = toCompatibleReadable(createReadable(reader));
1440
1450
  const size = reader.size;
1451
+ const readable = toCompatibleReadable(createReadable(reader, { size }));
1441
1452
  const workerOptions = {
1442
1453
  options: {
1443
1454
  codecType: CODEC_DEFLATE,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.11.1",
6
+ "version": "2.11.2",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",