@xlsxflow/core 1.1.5 → 1.1.6

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/dist/index.mjs CHANGED
@@ -60,9 +60,11 @@ class ZipStreamWriter {
60
60
  const writer = compressor.writable.getWriter();
61
61
  const reader = compressor.readable.getReader();
62
62
  const input = inputStream.getReader();
63
- // Node's and Bun's CompressionStream accept thousands of writes without backpressure, so one chunk
64
- // is fed at a time: a write resolves once the chunk is compressed, which waits while nobody reads
63
+ // Node's and Bun's CompressionStream accept thousands of writes without backpressure, so only a few
64
+ // chunks are fed ahead: a write resolves once the chunk is compressed, which waits while nobody reads
65
65
  // the output. Rows are then only pulled as fast as the ZIP is consumed.
66
+ // A few writes in flight keep the compressor busy while the next chunk is built
67
+ const inFlight = [];
66
68
  const feed = (async () => {
67
69
  try {
68
70
  while (true) {
@@ -72,8 +74,13 @@ class ZipStreamWriter {
72
74
  await this.roomInQueue();
73
75
  uncompressedSize += value.length;
74
76
  crc = crc32Update(crc, value);
75
- await writer.write(value);
77
+ const written = writer.write(value);
78
+ written.catch(() => { }); // after a failure, writes nobody awaits any more must not go unhandled
79
+ inFlight.push(written);
80
+ if (inFlight.length >= 4)
81
+ await inFlight.shift();
76
82
  }
83
+ await Promise.all(inFlight);
77
84
  await writer.close();
78
85
  }
79
86
  catch (err) {