@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-native.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 = () => { };
1967
1972
 
1968
1973
  class CodecWorker {
@@ -2149,23 +2154,8 @@ async function runWebWorker(workerData, config) {
2149
2154
  }
2150
2155
 
2151
2156
  function watchClosedStream(writableSource) {
2152
- let resolveStreamClosed;
2153
- const closed = new Promise(resolve => resolveStreamClosed = resolve);
2154
- const writable = new WritableStream({
2155
- async write(chunk) {
2156
- const writer = writableSource.getWriter();
2157
- await writer.ready;
2158
- await writer.write(chunk);
2159
- writer.releaseLock();
2160
- },
2161
- close() {
2162
- resolveStreamClosed();
2163
- },
2164
- abort(reason) {
2165
- const writer = writableSource.getWriter();
2166
- return writer.abort(reason);
2167
- }
2168
- });
2157
+ const { writable, readable } = new TransformStream();
2158
+ const closed = readable.pipeTo(writableSource, { preventClose: true });
2169
2159
  return { writable, closed };
2170
2160
  }
2171
2161
 
@@ -3454,6 +3444,7 @@ const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
3454
3444
  const OPTION_KEEP_ORDER = "keepOrder";
3455
3445
  const OPTION_LEVEL = "level";
3456
3446
  const OPTION_BUFFERED_WRITE = "bufferedWrite";
3447
+ const OPTION_CREATE_TEMP_STREAM = "createTempStream";
3457
3448
  const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
3458
3449
  const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
3459
3450
  const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
@@ -4718,7 +4709,9 @@ async function addFile(zipWriter, name, reader, options) {
4718
4709
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
4719
4710
  const keepOrder = getOptionValue(zipWriter, options, OPTION_KEEP_ORDER, true);
4720
4711
  const useWebWorkers = getOptionValue(zipWriter, options, OPTION_USE_WEB_WORKERS);
4712
+ const transferStreams = getOptionValue(zipWriter, options, OPTION_TRANSFER_STREAMS, true);
4721
4713
  const bufferedWrite = getOptionValue(zipWriter, options, OPTION_BUFFERED_WRITE);
4714
+ const createTempStream = getOptionValue(zipWriter, options, OPTION_CREATE_TEMP_STREAM);
4722
4715
  const dataDescriptorSignature = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR_SIGNATURE, false);
4723
4716
  const signal = getOptionValue(zipWriter, options, OPTION_SIGNAL);
4724
4717
  const useUnicodeFileNames = getOptionValue(zipWriter, options, OPTION_USE_UNICODE_FILE_NAMES, true);
@@ -4824,10 +4817,12 @@ async function addFile(zipWriter, name, reader, options) {
4824
4817
  rawPassword,
4825
4818
  level,
4826
4819
  useWebWorkers,
4820
+ transferStreams,
4827
4821
  encryptionStrength,
4828
4822
  extendedTimestamp,
4829
4823
  zipCrypto,
4830
4824
  bufferedWrite,
4825
+ createTempStream,
4831
4826
  keepOrder,
4832
4827
  useUnicodeFileNames,
4833
4828
  dataDescriptor,
@@ -4904,7 +4899,11 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
4904
4899
  requestLockCurrentFileEntry();
4905
4900
  }
4906
4901
  if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
4907
- fileWriter = new TransformStream(UNDEFINED_VALUE, UNDEFINED_VALUE, { highWaterMark: INFINITY_VALUE });
4902
+ if (options.createTempStream) {
4903
+ fileWriter = await options.createTempStream();
4904
+ } else {
4905
+ fileWriter = new TransformStream(UNDEFINED_VALUE, UNDEFINED_VALUE, { highWaterMark: INFINITY_VALUE });
4906
+ }
4908
4907
  fileWriter.size = 0;
4909
4908
  bufferedWrite = true;
4910
4909
  zipWriter.bufferedWrites++;
@@ -5069,6 +5068,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
5069
5068
  rawComment,
5070
5069
  rawExtraField,
5071
5070
  useWebWorkers,
5071
+ transferStreams,
5072
5072
  onstart,
5073
5073
  onprogress,
5074
5074
  onend,
@@ -5149,7 +5149,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
5149
5149
  encrypted: encrypted && !passThrough,
5150
5150
  useWebWorkers,
5151
5151
  useCompressionStream,
5152
- transferStreams: false
5152
+ transferStreams
5153
5153
  },
5154
5154
  config,
5155
5155
  streamOptions: { signal, size, onstart, onprogress, onend }