@zip.js/zip.js 2.8.19 → 2.8.21

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
@@ -1963,6 +1963,11 @@ const MODULE_WORKER_OPTIONS = { type: "module" };
1963
1963
 
1964
1964
  let webWorkerSupported, webWorkerURI, webWorkerOptions;
1965
1965
  let transferStreamsSupported = true;
1966
+ try {
1967
+ transferStreamsSupported = typeof structuredClone == FUNCTION_TYPE && structuredClone(new DOMException("", "AbortError")).code !== UNDEFINED_VALUE;
1968
+ } catch {
1969
+ // ignored
1970
+ }
1966
1971
  let initModule$1 = () => { };
1967
1972
 
1968
1973
  function configureWorker({ initModule: initModuleFunction }) {
@@ -2153,23 +2158,8 @@ async function runWebWorker(workerData, config) {
2153
2158
  }
2154
2159
 
2155
2160
  function watchClosedStream(writableSource) {
2156
- let resolveStreamClosed;
2157
- const closed = new Promise(resolve => resolveStreamClosed = resolve);
2158
- const writable = new WritableStream({
2159
- async write(chunk) {
2160
- const writer = writableSource.getWriter();
2161
- await writer.ready;
2162
- await writer.write(chunk);
2163
- writer.releaseLock();
2164
- },
2165
- close() {
2166
- resolveStreamClosed();
2167
- },
2168
- abort(reason) {
2169
- const writer = writableSource.getWriter();
2170
- return writer.abort(reason);
2171
- }
2172
- });
2161
+ const { writable, readable } = new TransformStream();
2162
+ const closed = readable.pipeTo(writableSource, { preventClose: true });
2173
2163
  return { writable, closed };
2174
2164
  }
2175
2165
 
@@ -3458,6 +3448,7 @@ const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
3458
3448
  const OPTION_KEEP_ORDER = "keepOrder";
3459
3449
  const OPTION_LEVEL = "level";
3460
3450
  const OPTION_BUFFERED_WRITE = "bufferedWrite";
3451
+ const OPTION_CREATE_TEMP_STREAM = "createTempStream";
3461
3452
  const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
3462
3453
  const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
3463
3454
  const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
@@ -4722,7 +4713,9 @@ async function addFile(zipWriter, name, reader, options) {
4722
4713
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
4723
4714
  const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
4724
4715
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
4716
+ const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS, true);
4725
4717
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
4718
+ const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
4726
4719
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, false);
4727
4720
  const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
4728
4721
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
@@ -4828,10 +4821,12 @@ async function addFile(zipWriter, name, reader, options) {
4828
4821
  rawPassword,
4829
4822
  level,
4830
4823
  useWebWorkers,
4824
+ transferStreams,
4831
4825
  encryptionStrength,
4832
4826
  extendedTimestamp,
4833
4827
  zipCrypto,
4834
4828
  bufferedWrite,
4829
+ createTempStream,
4835
4830
  keepOrder,
4836
4831
  useUnicodeFileNames,
4837
4832
  dataDescriptor,
@@ -4908,7 +4903,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
4908
4903
  requestLockCurrentFileEntry();
4909
4904
  }
4910
4905
  if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
4911
- fileWriter = new TransformStream(UNDEFINED_VALUE, UNDEFINED_VALUE, { highWaterMark: INFINITY_VALUE });
4906
+ if (options.createTempStream) {
4907
+ fileWriter = await options.createTempStream();
4908
+ } else {
4909
+ fileWriter = new TransformStream(UNDEFINED_VALUE, UNDEFINED_VALUE, { highWaterMark: INFINITY_VALUE });
4910
+ }
4912
4911
  fileWriter.size = 0;
4913
4912
  bufferedWrite = true;
4914
4913
  zipWriter.bufferedWrites++;
@@ -5073,6 +5072,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
5073
5072
  rawComment,
5074
5073
  rawExtraField,
5075
5074
  useWebWorkers,
5075
+ transferStreams,
5076
5076
  onstart,
5077
5077
  onprogress,
5078
5078
  onend,
@@ -5153,7 +5153,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
5153
5153
  encrypted: encrypted && !passThrough,
5154
5154
  useWebWorkers,
5155
5155
  useCompressionStream,
5156
- transferStreams: false
5156
+ transferStreams
5157
5157
  },
5158
5158
  config,
5159
5159
  streamOptions: { signal, size, onstart, onprogress, onend }
package/index.d.ts CHANGED
@@ -293,6 +293,12 @@ export interface WorkerConfiguration {
293
293
  * @defaultValue true
294
294
  */
295
295
  useCompressionStream?: boolean;
296
+ /**
297
+ * `true` to transfer stream ownership to web workers.
298
+ *
299
+ * @defaultValue true
300
+ */
301
+ transferStreams?: boolean;
296
302
  }
297
303
 
298
304
  /**
@@ -885,12 +891,6 @@ export interface ZipReaderOptions {
885
891
  * @defaultValue false
886
892
  */
887
893
  preventClose?: boolean;
888
- /**
889
- * `true` to transfer streams to web workers when decompressing data.
890
- *
891
- * @defaultValue true
892
- */
893
- transferStreams?: boolean;
894
894
  }
895
895
 
896
896
  /**