@zip.js/zip.js 2.8.60 → 2.8.61

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.
@@ -6676,6 +6676,13 @@
6676
6676
  const { comment } = metadataInfo;
6677
6677
  const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
6678
6678
  zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
6679
+ const previousFileEntry = zipWriter.lastFileEntry;
6680
+ const pendingFileEntry = {};
6681
+ let releaseLockFileEntry;
6682
+ if (metadataInfo.resolvedOptions.keepOrder) {
6683
+ pendingFileEntry.lockFileEntry = new Promise(resolve => releaseLockFileEntry = resolve);
6684
+ }
6685
+ zipWriter.lastFileEntry = pendingFileEntry;
6679
6686
  let fileEntry;
6680
6687
  try {
6681
6688
  const { resolvedOptions } = metadataInfo;
@@ -6697,10 +6704,21 @@
6697
6704
  const headerInfo = getHeaderInfo(options);
6698
6705
  const dataDescriptorInfo = getDataDescriptorInfo(options);
6699
6706
  const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
6700
- fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
6707
+ fileEntry = await getFileEntry(zipWriter, name, reader, {
6708
+ headerInfo,
6709
+ dataDescriptorInfo,
6710
+ metadataSize,
6711
+ fileEntry: pendingFileEntry,
6712
+ previousFileEntry,
6713
+ releaseLockFileEntry
6714
+ }, options);
6701
6715
  } catch (error) {
6702
6716
  zipWriter.fileEntries.delete(name);
6703
6717
  throw error;
6718
+ } finally {
6719
+ if (releaseLockFileEntry) {
6720
+ releaseLockFileEntry(previousFileEntry && previousFileEntry.lockFileEntry);
6721
+ }
6704
6722
  }
6705
6723
  Object.assign(fileEntry, {
6706
6724
  name,
@@ -7088,7 +7106,6 @@
7088
7106
  }
7089
7107
  const usdz = writerOptions[OPTION_USDZ];
7090
7108
  const files = new Map();
7091
- let layoutDependsOnWriteOrder = Boolean(usdz);
7092
7109
  const initialOffset = writerOptions[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : writerOptions[OPTION_OFFSET];
7093
7110
  let offset = initialOffset;
7094
7111
  let minimumEntrySize = INFINITY_VALUE;
@@ -7134,9 +7151,7 @@
7134
7151
  minimumEntrySize = Math.min(minimumEntrySize, entrySize);
7135
7152
  offset += entrySize;
7136
7153
  }
7137
- if (files.size && offset - minimumEntrySize >= MAX_32_BITS) {
7138
- layoutDependsOnWriteOrder = true;
7139
- }
7154
+ const layoutDependsOnWriteOrder = files.size > 1 && (usdz || offset - minimumEntrySize >= MAX_32_BITS);
7140
7155
  if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
7141
7156
  throw new Error(ERR_UNDETERMINED_SIZE);
7142
7157
  }
@@ -7164,27 +7179,23 @@
7164
7179
  signal
7165
7180
  } = options;
7166
7181
  const {
7167
- headerInfo
7182
+ headerInfo,
7183
+ fileEntry: pendingFileEntry,
7184
+ previousFileEntry,
7185
+ releaseLockFileEntry
7168
7186
  } = entryInfo;
7169
7187
  const usdz = zipWriter.options[OPTION_USDZ];
7170
- const previousFileEntry = zipWriter.lastFileEntry;
7171
- let fileEntry = {};
7188
+ let fileEntry = pendingFileEntry;
7172
7189
  let bufferedWrite;
7173
7190
  let releaseLockWriter;
7174
- let releaseLockCurrentFileEntry;
7175
7191
  let writingBufferedEntryData;
7176
7192
  let writingEntryData;
7177
7193
  let writerSizeBeforeEntry;
7178
7194
  let flushedBufferedSize = 0;
7179
7195
  let fileWriter;
7196
+ const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7180
7197
  fileEntries.set(name, fileEntry);
7181
- zipWriter.lastFileEntry = fileEntry;
7182
7198
  try {
7183
- let lockPreviousFileEntry;
7184
- if (keepOrder) {
7185
- lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
7186
- requestLockCurrentFileEntry();
7187
- }
7188
7199
  if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7189
7200
  bufferedWrite = true;
7190
7201
  zipWriter.bufferedWrites++;
@@ -7197,6 +7208,7 @@
7197
7208
  await initStream(writer);
7198
7209
  } else {
7199
7210
  fileWriter = writer;
7211
+ await lockPreviousFileEntry;
7200
7212
  await requestLockWriter();
7201
7213
  }
7202
7214
  await initStream(fileWriter);
@@ -7209,7 +7221,6 @@
7209
7221
  }
7210
7222
  const { localHeaderArray } = headerInfo;
7211
7223
  if (!bufferedWrite) {
7212
- await lockPreviousFileEntry;
7213
7224
  await skipDiskIfNeeded();
7214
7225
  }
7215
7226
  const diskNumberStart = getDiskNumber(writer);
@@ -7274,8 +7285,8 @@
7274
7285
  if (bufferedWrite) {
7275
7286
  zipWriter.bufferedWrites--;
7276
7287
  }
7277
- if (releaseLockCurrentFileEntry) {
7278
- releaseLockCurrentFileEntry();
7288
+ if (releaseLockFileEntry) {
7289
+ releaseLockFileEntry(lockPreviousFileEntry);
7279
7290
  }
7280
7291
  if (releaseLockWriter) {
7281
7292
  releaseLockWriter();
@@ -7289,10 +7300,6 @@
7289
7300
  }
7290
7301
  }
7291
7302
 
7292
- function requestLockCurrentFileEntry() {
7293
- fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
7294
- }
7295
-
7296
7303
  async function requestLockWriter() {
7297
7304
  zipWriter.writerLocked = true;
7298
7305
  const { lockWriter } = zipWriter;
@@ -8612,7 +8619,7 @@
8612
8619
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8613
8620
  */
8614
8621
 
8615
- const VERSION = "2.8.60";
8622
+ const VERSION = "2.8.61";
8616
8623
 
8617
8624
  /*
8618
8625
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9589,12 +9596,13 @@
9589
9596
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9590
9597
  options.bufferedWrite = true;
9591
9598
  }
9592
- const writeOrderGuaranteed = !options.bufferedWrite ||
9593
- (options.keepOrder !== false && zipEntry.children.every(child => !child.children.length));
9594
- return getEntriesSize(options, zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9599
+ const entries = zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9595
9600
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
9596
9601
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
9597
- }), writeOrderGuaranteed, options.globalComment);
9602
+ });
9603
+ const writeOrderGuaranteed = !options.bufferedWrite ||
9604
+ (entries.every(entry => entry.options.keepOrder !== false) && zipEntry.children.every(child => !child.children.length));
9605
+ return getEntriesSize(options, entries, writeOrderGuaranteed, options.globalComment);
9598
9606
  }
9599
9607
 
9600
9608
  getChildByName(name) {