@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.
@@ -6674,6 +6674,13 @@
6674
6674
  const { comment } = metadataInfo;
6675
6675
  const extraField = options[PROPERTY_NAME_EXTRA_FIELD];
6676
6676
  zipWriter.fileEntries.set(name, UNDEFINED_VALUE);
6677
+ const previousFileEntry = zipWriter.lastFileEntry;
6678
+ const pendingFileEntry = {};
6679
+ let releaseLockFileEntry;
6680
+ if (metadataInfo.resolvedOptions.keepOrder) {
6681
+ pendingFileEntry.lockFileEntry = new Promise(resolve => releaseLockFileEntry = resolve);
6682
+ }
6683
+ zipWriter.lastFileEntry = pendingFileEntry;
6677
6684
  let fileEntry;
6678
6685
  try {
6679
6686
  const { resolvedOptions } = metadataInfo;
@@ -6695,10 +6702,21 @@
6695
6702
  const headerInfo = getHeaderInfo(options);
6696
6703
  const dataDescriptorInfo = getDataDescriptorInfo(options);
6697
6704
  const metadataSize = getLength(headerInfo.localHeaderArray, dataDescriptorInfo.dataDescriptorArray);
6698
- fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo, metadataSize }, options);
6705
+ fileEntry = await getFileEntry(zipWriter, name, reader, {
6706
+ headerInfo,
6707
+ dataDescriptorInfo,
6708
+ metadataSize,
6709
+ fileEntry: pendingFileEntry,
6710
+ previousFileEntry,
6711
+ releaseLockFileEntry
6712
+ }, options);
6699
6713
  } catch (error) {
6700
6714
  zipWriter.fileEntries.delete(name);
6701
6715
  throw error;
6716
+ } finally {
6717
+ if (releaseLockFileEntry) {
6718
+ releaseLockFileEntry(previousFileEntry && previousFileEntry.lockFileEntry);
6719
+ }
6702
6720
  }
6703
6721
  Object.assign(fileEntry, {
6704
6722
  name,
@@ -7086,7 +7104,6 @@
7086
7104
  }
7087
7105
  const usdz = writerOptions[OPTION_USDZ];
7088
7106
  const files = new Map();
7089
- let layoutDependsOnWriteOrder = Boolean(usdz);
7090
7107
  const initialOffset = writerOptions[OPTION_OFFSET] === UNDEFINED_VALUE ? 0 : writerOptions[OPTION_OFFSET];
7091
7108
  let offset = initialOffset;
7092
7109
  let minimumEntrySize = INFINITY_VALUE;
@@ -7132,9 +7149,7 @@
7132
7149
  minimumEntrySize = Math.min(minimumEntrySize, entrySize);
7133
7150
  offset += entrySize;
7134
7151
  }
7135
- if (files.size && offset - minimumEntrySize >= MAX_32_BITS) {
7136
- layoutDependsOnWriteOrder = true;
7137
- }
7152
+ const layoutDependsOnWriteOrder = files.size > 1 && (usdz || offset - minimumEntrySize >= MAX_32_BITS);
7138
7153
  if (layoutDependsOnWriteOrder && !writeOrderGuaranteed) {
7139
7154
  throw new Error(ERR_UNDETERMINED_SIZE);
7140
7155
  }
@@ -7162,27 +7177,23 @@
7162
7177
  signal
7163
7178
  } = options;
7164
7179
  const {
7165
- headerInfo
7180
+ headerInfo,
7181
+ fileEntry: pendingFileEntry,
7182
+ previousFileEntry,
7183
+ releaseLockFileEntry
7166
7184
  } = entryInfo;
7167
7185
  const usdz = zipWriter.options[OPTION_USDZ];
7168
- const previousFileEntry = zipWriter.lastFileEntry;
7169
- let fileEntry = {};
7186
+ let fileEntry = pendingFileEntry;
7170
7187
  let bufferedWrite;
7171
7188
  let releaseLockWriter;
7172
- let releaseLockCurrentFileEntry;
7173
7189
  let writingBufferedEntryData;
7174
7190
  let writingEntryData;
7175
7191
  let writerSizeBeforeEntry;
7176
7192
  let flushedBufferedSize = 0;
7177
7193
  let fileWriter;
7194
+ const lockPreviousFileEntry = keepOrder && previousFileEntry ? previousFileEntry.lockFileEntry : UNDEFINED_VALUE;
7178
7195
  fileEntries.set(name, fileEntry);
7179
- zipWriter.lastFileEntry = fileEntry;
7180
7196
  try {
7181
- let lockPreviousFileEntry;
7182
- if (keepOrder) {
7183
- lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
7184
- requestLockCurrentFileEntry();
7185
- }
7186
7197
  if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
7187
7198
  bufferedWrite = true;
7188
7199
  zipWriter.bufferedWrites++;
@@ -7195,6 +7206,7 @@
7195
7206
  await initStream(writer);
7196
7207
  } else {
7197
7208
  fileWriter = writer;
7209
+ await lockPreviousFileEntry;
7198
7210
  await requestLockWriter();
7199
7211
  }
7200
7212
  await initStream(fileWriter);
@@ -7207,7 +7219,6 @@
7207
7219
  }
7208
7220
  const { localHeaderArray } = headerInfo;
7209
7221
  if (!bufferedWrite) {
7210
- await lockPreviousFileEntry;
7211
7222
  await skipDiskIfNeeded();
7212
7223
  }
7213
7224
  const diskNumberStart = getDiskNumber(writer);
@@ -7272,8 +7283,8 @@
7272
7283
  if (bufferedWrite) {
7273
7284
  zipWriter.bufferedWrites--;
7274
7285
  }
7275
- if (releaseLockCurrentFileEntry) {
7276
- releaseLockCurrentFileEntry();
7286
+ if (releaseLockFileEntry) {
7287
+ releaseLockFileEntry(lockPreviousFileEntry);
7277
7288
  }
7278
7289
  if (releaseLockWriter) {
7279
7290
  releaseLockWriter();
@@ -7287,10 +7298,6 @@
7287
7298
  }
7288
7299
  }
7289
7300
 
7290
- function requestLockCurrentFileEntry() {
7291
- fileEntry.lockFileEntry = new Promise(resolve => releaseLockCurrentFileEntry = resolve);
7292
- }
7293
-
7294
7301
  async function requestLockWriter() {
7295
7302
  zipWriter.writerLocked = true;
7296
7303
  const { lockWriter } = zipWriter;
@@ -8610,7 +8617,7 @@
8610
8617
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8611
8618
  */
8612
8619
 
8613
- const VERSION = "2.8.60";
8620
+ const VERSION = "2.8.61";
8614
8621
 
8615
8622
  /*
8616
8623
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
@@ -9549,12 +9556,13 @@
9549
9556
  if (options.bufferedWrite === UNDEFINED_VALUE) {
9550
9557
  options.bufferedWrite = true;
9551
9558
  }
9552
- const writeOrderGuaranteed = !options.bufferedWrite ||
9553
- (options.keepOrder !== false && zipEntry.children.every(child => !child.children.length));
9554
- return getEntriesSize(options, zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9559
+ const entries = zipEntry.getChildren({ recursive: true }).filter(child => !isImplicitDirectory(child)).map(child => {
9555
9560
  const { name, entryOptions } = getChildEntryOptions(child, zipEntry, options);
9556
9561
  return { name, size: child.directory ? 0 : getDeterminedSize(child, isPassThrough(child, options)), options: entryOptions };
9557
- }), writeOrderGuaranteed, options.globalComment);
9562
+ });
9563
+ const writeOrderGuaranteed = !options.bufferedWrite ||
9564
+ (entries.every(entry => entry.options.keepOrder !== false) && zipEntry.children.every(child => !child.children.length));
9565
+ return getEntriesSize(options, entries, writeOrderGuaranteed, options.globalComment);
9558
9566
  }
9559
9567
 
9560
9568
  getChildByName(name) {