@zip.js/zip.js 2.8.42 → 2.8.44

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.
Files changed (46) hide show
  1. package/README.md +0 -37
  2. package/deno.json +1 -1
  3. package/dist/zip-core-external.js +178 -77
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +179 -76
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +178 -77
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +177 -76
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +178 -77
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +180 -77
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +180 -77
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +180 -77
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +180 -77
  20. package/dist/zip-native.min.js +1 -1
  21. package/dist/zip-web-worker-native.js +1 -1
  22. package/dist/zip-web-worker.js +1 -1
  23. package/dist/zip.js +180 -77
  24. package/dist/zip.min.js +1 -1
  25. package/index-native.cjs +180 -77
  26. package/index-native.min.js +1 -1
  27. package/index.cjs +180 -77
  28. package/index.d.cts +80 -7
  29. package/index.d.ts +80 -7
  30. package/index.min.js +1 -1
  31. package/lib/core/codec-pool.js +6 -2
  32. package/lib/core/codec-worker.js +23 -2
  33. package/lib/core/options.js +4 -0
  34. package/lib/core/streams/aes-crypto-stream.js +4 -4
  35. package/lib/core/streams/codec-stream.js +8 -2
  36. package/lib/core/streams/common-crypto.js +2 -0
  37. package/lib/core/streams/zip-entry-stream.js +102 -36
  38. package/lib/core/web-worker-inline-native.js +1 -1
  39. package/lib/core/web-worker-inline-wasm.js +1 -1
  40. package/lib/core/web-worker-wasm.js +4 -8
  41. package/lib/core/zip-entry.js +3 -0
  42. package/lib/core/zip-reader.js +35 -26
  43. package/lib/core/zip-writer.js +22 -10
  44. package/lib/zip-core-reader.js +2 -0
  45. package/package.json +1 -1
  46. package/worker-message-property-names.js +1 -1
@@ -1396,6 +1396,7 @@ const GET_RANDOM_VALUES_SUPPORTED = typeof crypto != UNDEFINED_TYPE && typeof cr
1396
1396
 
1397
1397
  const ERR_INVALID_PASSWORD = "Invalid password";
1398
1398
  const ERR_INVALID_SIGNATURE = "Invalid signature";
1399
+ const ERR_INVALID_AUTHENTICATION_CODE = ERR_INVALID_SIGNATURE;
1399
1400
  const ERR_ABORT_CHECK_PASSWORD = "zipjs-abort-check-password";
1400
1401
  const ERR_UNSUPPORTED_CRYPTO_API = "Crypto API not supported";
1401
1402
 
@@ -1462,7 +1463,7 @@ let DERIVE_BITS_SUPPORTED = CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && type
1462
1463
 
1463
1464
  class AESDecryptionStream extends TransformStream {
1464
1465
 
1465
- constructor({ password, rawPassword, encryptionStrength, checkPasswordOnly }) {
1466
+ constructor({ password, rawPassword, encryptionStrength, checkPasswordOnly, checkAuthenticationCode = true }) {
1466
1467
  super({
1467
1468
  start() {
1468
1469
  initAesCrypto(this, password, rawPassword, encryptionStrength);
@@ -1512,8 +1513,8 @@ class AESDecryptionStream extends TransformStream {
1512
1513
  for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
1513
1514
  invalidSignature |= signature[indexSignature] ^ originalSignature[indexSignature];
1514
1515
  }
1515
- if (invalidSignature) {
1516
- throw new Error(ERR_INVALID_SIGNATURE);
1516
+ if (invalidSignature && checkAuthenticationCode) {
1517
+ throw new Error(ERR_INVALID_AUTHENTICATION_CODE);
1517
1518
  }
1518
1519
  controller.enqueue(decryptedChunkArray);
1519
1520
  }
@@ -1951,6 +1952,7 @@ function toCompatibleWritable(writable) {
1951
1952
 
1952
1953
  const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
1953
1954
  const ERR_INVALID_COMPRESSED_DATA = "Invalid compressed data";
1955
+ const ERR_INVALID_CRC32 = ERR_INVALID_SIGNATURE;
1954
1956
  const ERR_UNSUPPORTED_COMPRESSION$2 = "Compression method not supported";
1955
1957
  const FORMAT_DEFLATE_RAW = "deflate-raw";
1956
1958
  const FORMAT_DEFLATE64_RAW = "deflate64-raw";
@@ -1958,19 +1960,20 @@ const FORMAT_GZIP = "gzip";
1958
1960
  const GZIP_HEADER_LENGTH = 10;
1959
1961
  const GZIP_TRAILER_LENGTH = 8;
1960
1962
  const GZIP_HEADER_BYTES = [0x1f, 0x8b, 0x08];
1963
+ const GZIP_OUTPUT_STALL_TIMEOUT = 5000;
1961
1964
 
1962
1965
  class DeflateStream extends TransformStream {
1963
1966
 
1964
1967
  constructor(options, { chunkSize, CompressionStreamZlib, CompressionStream }) {
1965
1968
  super({});
1966
- const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level, deflate64, format, compressionMethod } = options;
1969
+ const { compressed, encrypted, useCompressionStream, zipCrypto, computeCrc32, level, deflate64, format, compressionMethod } = options;
1967
1970
  const stream = this;
1968
1971
  let crc32Stream, encryptionStream, gzipCrc32Stream;
1969
1972
  let readable = super.readable;
1970
1973
  const codecStreams = format && getCodecStreams(format);
1971
- const useGzipCrc32 = signed && compressed && !deflate64 && !codecStreams && (!encrypted || zipCrypto) &&
1974
+ const useGzipCrc32 = computeCrc32 && compressed && !deflate64 && !codecStreams && (!encrypted || zipCrypto) &&
1972
1975
  Boolean(useCompressionStream && CompressionStream);
1973
- if ((!encrypted || zipCrypto) && signed && !useGzipCrc32) {
1976
+ if ((!encrypted || zipCrypto) && computeCrc32 && !useGzipCrc32) {
1974
1977
  crc32Stream = new Crc32Stream();
1975
1978
  readable = pipeThrough(readable, crc32Stream);
1976
1979
  }
@@ -2009,7 +2012,7 @@ class DeflateStream extends TransformStream {
2009
2012
  if (encrypted && !zipCrypto) {
2010
2013
  signature = encryptionStream.signature;
2011
2014
  }
2012
- if ((!encrypted || zipCrypto) && signed) {
2015
+ if ((!encrypted || zipCrypto) && computeCrc32) {
2013
2016
  signature = useGzipCrc32 ? gzipCrc32Stream.signature : new DataView(crc32Stream.value.buffer).getUint32(0);
2014
2017
  }
2015
2018
  stream.signature = signature;
@@ -2058,26 +2061,73 @@ class GzipToRawDeflateStream extends TransformStream {
2058
2061
  }
2059
2062
  }
2060
2063
 
2061
- class RawDeflateToGzipStream extends TransformStream {
2062
-
2063
- constructor(signature, uncompressedSize) {
2064
- super({
2065
- start(controller) {
2066
- const header = new Uint8Array(GZIP_HEADER_LENGTH);
2067
- header.set(GZIP_HEADER_BYTES);
2068
- controller.enqueue(header);
2069
- },
2070
- transform(chunk, controller) {
2071
- controller.enqueue(chunk);
2072
- },
2073
- flush(controller) {
2074
- const trailer = new Uint8Array(GZIP_TRAILER_LENGTH);
2075
- const dataView = getDataView(trailer);
2076
- dataView.setUint32(0, signature, true);
2077
- dataView.setUint32(4, uncompressedSize, true);
2078
- controller.enqueue(trailer);
2064
+ function pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize) {
2065
+ const crc32 = new Crc32();
2066
+ let outputLength = 0;
2067
+ let inputDone = false;
2068
+ let watchdogTimeout;
2069
+ let resolveTrailerReady, rejectTrailerReady;
2070
+ const trailerReady = new Promise((resolve, reject) => {
2071
+ resolveTrailerReady = resolve;
2072
+ rejectTrailerReady = reject;
2073
+ });
2074
+ trailerReady.catch(() => { });
2075
+ if (!outputSize) {
2076
+ resolveTrailerReady();
2077
+ }
2078
+ const gzipWrapStream = new TransformStream({
2079
+ start(controller) {
2080
+ const header = new Uint8Array(GZIP_HEADER_LENGTH);
2081
+ header.set(GZIP_HEADER_BYTES);
2082
+ controller.enqueue(header);
2083
+ },
2084
+ transform(chunk, controller) {
2085
+ controller.enqueue(chunk);
2086
+ },
2087
+ async flush(controller) {
2088
+ inputDone = true;
2089
+ startWatchdog();
2090
+ try {
2091
+ await trailerReady;
2092
+ } finally {
2093
+ stopWatchdog();
2079
2094
  }
2080
- });
2095
+ const trailer = new Uint8Array(GZIP_TRAILER_LENGTH);
2096
+ const dataView = getDataView(trailer);
2097
+ dataView.setUint32(0, crc32.get(), true);
2098
+ dataView.setUint32(4, outputSize, true);
2099
+ controller.enqueue(trailer);
2100
+ },
2101
+ cancel(reason) {
2102
+ rejectTrailerReady(reason);
2103
+ }
2104
+ });
2105
+ const outputStream = new TransformStream({
2106
+ transform(chunk, controller) {
2107
+ crc32.append(chunk);
2108
+ outputLength += chunk.length;
2109
+ if (outputLength >= outputSize) {
2110
+ resolveTrailerReady();
2111
+ } else if (inputDone) {
2112
+ startWatchdog();
2113
+ }
2114
+ controller.enqueue(chunk);
2115
+ },
2116
+ cancel(reason) {
2117
+ rejectTrailerReady(reason);
2118
+ }
2119
+ });
2120
+ readable = pipeThrough(readable, gzipWrapStream);
2121
+ readable = pipeThroughBackpressured(readable, gzipStream);
2122
+ return pipeThrough(readable, outputStream);
2123
+
2124
+ function startWatchdog() {
2125
+ stopWatchdog();
2126
+ watchdogTimeout = setTimeout(() => rejectTrailerReady(new Error(ERR_INVALID_UNCOMPRESSED_SIZE)), GZIP_OUTPUT_STALL_TIMEOUT);
2127
+ }
2128
+
2129
+ function stopWatchdog() {
2130
+ clearTimeout(watchdogTimeout);
2081
2131
  }
2082
2132
  }
2083
2133
 
@@ -2085,7 +2135,7 @@ class InflateStream extends TransformStream {
2085
2135
 
2086
2136
  constructor(options, { chunkSize, DecompressionStreamZlib, DecompressionStream }) {
2087
2137
  super({});
2088
- const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream, deflate64, format, compressionMethod, rawBitFlag, outputSize } = options;
2138
+ const { zipCrypto, encrypted, checkCrc32, signature, compressed, useCompressionStream, deflate64, format, compressionMethod, rawBitFlag, outputSize } = options;
2089
2139
  let crc32Stream, decryptionStream;
2090
2140
  let readable = super.readable;
2091
2141
  if (encrypted) {
@@ -2104,7 +2154,7 @@ class InflateStream extends TransformStream {
2104
2154
  try {
2105
2155
  readable = pipeThroughCompressionStream(readable, useCompressionStream, { chunkSize, deflate64 }, DecompressionStream, DecompressionStreamZlib);
2106
2156
  } catch (error) {
2107
- if (deflate64 || (encrypted && !zipCrypto) || signature === UNDEFINED_VALUE || outputSize === UNDEFINED_VALUE) {
2157
+ if (deflate64 || outputSize === UNDEFINED_VALUE) {
2108
2158
  throw error;
2109
2159
  }
2110
2160
  let gzipStream;
@@ -2113,46 +2163,58 @@ class InflateStream extends TransformStream {
2113
2163
  } catch {
2114
2164
  throw error;
2115
2165
  }
2116
- readable = pipeThrough(readable, new RawDeflateToGzipStream(signature, outputSize));
2117
- readable = pipeThroughBackpressured(readable, gzipStream);
2166
+ readable = pipeThroughGzipDecompressionStream(readable, gzipStream, outputSize);
2118
2167
  }
2119
2168
  }
2120
2169
  readable = mapInflateStreamError(readable);
2121
2170
  }
2122
- if ((!encrypted || zipCrypto) && signed) {
2171
+ if (checkCrc32) {
2123
2172
  crc32Stream = new Crc32Stream();
2124
2173
  readable = pipeThrough(readable, crc32Stream);
2125
2174
  }
2126
2175
  setReadable(this, readable, () => {
2127
- if ((!encrypted || zipCrypto) && signed) {
2176
+ if (checkCrc32) {
2128
2177
  const dataViewSignature = new DataView(crc32Stream.value.buffer);
2129
2178
  if (signature != dataViewSignature.getUint32(0, false)) {
2130
- throw new Error(ERR_INVALID_SIGNATURE);
2179
+ throw new Error(ERR_INVALID_CRC32);
2131
2180
  }
2132
2181
  }
2133
2182
  });
2134
2183
  }
2135
2184
  }
2136
2185
 
2137
- const deflateRawSupportByStream = new Map();
2186
+ const formatSupportByStream = new Map();
2138
2187
 
2139
- function supportsDeflateRaw(StreamClass) {
2188
+ function supportsFormat(StreamClass, format) {
2140
2189
  if (!StreamClass) {
2141
2190
  return false;
2142
2191
  }
2143
- let supported = deflateRawSupportByStream.get(StreamClass);
2192
+ let supportByFormat = formatSupportByStream.get(StreamClass);
2193
+ if (!supportByFormat) {
2194
+ supportByFormat = new Map();
2195
+ formatSupportByStream.set(StreamClass, supportByFormat);
2196
+ }
2197
+ let supported = supportByFormat.get(format);
2144
2198
  if (supported === UNDEFINED_VALUE) {
2145
2199
  try {
2146
- new StreamClass(FORMAT_DEFLATE_RAW);
2200
+ new StreamClass(format);
2147
2201
  supported = true;
2148
2202
  } catch {
2149
2203
  supported = false;
2150
2204
  }
2151
- deflateRawSupportByStream.set(StreamClass, supported);
2205
+ supportByFormat.set(format, supported);
2152
2206
  }
2153
2207
  return supported;
2154
2208
  }
2155
2209
 
2210
+ function supportsDeflateRaw(StreamClass) {
2211
+ return supportsFormat(StreamClass, FORMAT_DEFLATE_RAW);
2212
+ }
2213
+
2214
+ function supportsGzip(StreamClass) {
2215
+ return supportsFormat(StreamClass, FORMAT_GZIP);
2216
+ }
2217
+
2156
2218
  function setReadable(stream, readable, flush) {
2157
2219
  readable = pipeThrough(readable, new TransformStream({ flush }));
2158
2220
  Object.defineProperty(stream, "readable", {
@@ -2455,6 +2517,25 @@ function configureWorker({ initModule: initModuleFunction }) {
2455
2517
  initModule$1 = initModuleFunction;
2456
2518
  }
2457
2519
 
2520
+ async function supportsDeflate(config) {
2521
+ const { CompressionStream: NativeStream, CompressionStreamZlib: ZlibStream } = config;
2522
+ if (ZlibStream && !ZlibStream.requiresModule) {
2523
+ return true;
2524
+ }
2525
+ if (supportsDeflateRaw(NativeStream) || supportsGzip(NativeStream)) {
2526
+ return true;
2527
+ }
2528
+ if (ZlibStream) {
2529
+ try {
2530
+ await initModule$1(config);
2531
+ return true;
2532
+ } catch {
2533
+ return false;
2534
+ }
2535
+ }
2536
+ return false;
2537
+ }
2538
+
2458
2539
  function resetWebWorkerSupport() {
2459
2540
  webWorkerSupported = UNDEFINED_VALUE;
2460
2541
  }
@@ -2990,7 +3071,7 @@ let indexWorker = 0;
2990
3071
 
2991
3072
  async function runWorker(stream, workerOptions) {
2992
3073
  const { options, config } = workerOptions;
2993
- const { transferStreams, useWebWorkers, useCompressionStream, compressed, signed, encrypted, format, codecURI } = options;
3074
+ const { transferStreams, useWebWorkers, useCompressionStream, compressed, checkCrc32, computeCrc32, encrypted, format, codecURI } = options;
2994
3075
  const { workerURI, maxWorkers } = config;
2995
3076
  if (format) {
2996
3077
  if (codecURI) {
@@ -2999,7 +3080,7 @@ async function runWorker(stream, workerOptions) {
2999
3080
  await ensureCodecStreams(format, options.codecURI);
3000
3081
  }
3001
3082
  workerOptions.transferStreams = transferStreams || (transferStreams === UNDEFINED_VALUE && config.transferStreams);
3002
- const streamCopy = !compressed && !signed && !encrypted;
3083
+ const streamCopy = !compressed && !checkCrc32 && !computeCrc32 && !encrypted;
3003
3084
  const workerSupported = format === UNDEFINED_VALUE || Boolean(options.codecURI);
3004
3085
  workerOptions.useWebWorkers = !streamCopy && workerSupported && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
3005
3086
  workerOptions.workerURI = workerOptions.useWebWorkers && workerURI ? workerURI : UNDEFINED_VALUE;
@@ -4223,6 +4304,7 @@ const PROPERTY_NAME_DIRECTORY = "directory";
4223
4304
  const PROPERTY_NAME_EXECUTABLE = "executable";
4224
4305
  const PROPERTY_NAME_COMPRESSION_METHOD = "compressionMethod";
4225
4306
  const PROPERTY_NAME_SIGNATURE = "signature";
4307
+ const PROPERTY_NAME_CRC32 = "crc32";
4226
4308
  const PROPERTY_NAME_EXTRA_FIELD = "extraField";
4227
4309
  const PROPERTY_NAME_EXTRA_FIELD_INFOZIP = "extraFieldInfoZip";
4228
4310
  const PROPERTY_NAME_EXTRA_FIELD_UNIX = "extraFieldUnix";
@@ -4271,6 +4353,7 @@ const PROPERTY_NAMES = [
4271
4353
  PROPERTY_NAME_EXECUTABLE,
4272
4354
  PROPERTY_NAME_COMPRESSION_METHOD,
4273
4355
  PROPERTY_NAME_SIGNATURE,
4356
+ PROPERTY_NAME_CRC32,
4274
4357
  PROPERTY_NAME_EXTRA_FIELD,
4275
4358
  PROPERTY_NAME_EXTRA_FIELD_UNIX,
4276
4359
  PROPERTY_NAME_EXTRA_FIELD_INFOZIP,
@@ -4342,6 +4425,8 @@ const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
4342
4425
  const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
4343
4426
  const OPTION_CHECK_AMBIGUITY = "checkAmbiguity";
4344
4427
  const OPTION_CHECK_SIGNATURE = "checkSignature";
4428
+ const OPTION_CHECK_CRC32 = "checkCrc32";
4429
+ const OPTION_CHECK_AUTHENTICATION_CODE = "checkAuthenticationCode";
4345
4430
  const OPTION_USE_WEB_WORKERS = "useWebWorkers";
4346
4431
  const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
4347
4432
  const OPTION_TRANSFER_STREAMS = "transferStreams";
@@ -4413,6 +4498,7 @@ const CHARSET_UTF8 = "utf-8";
4413
4498
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
4414
4499
  const CHARSET_CP437 = "cp437";
4415
4500
  const BITFLAG_AMBIGUITY_MASK = BITFLAG_ENCRYPTED | BITFLAG_DATA_DESCRIPTOR | BITFLAG_LANG_ENCODING_FLAG;
4501
+ const VENDOR_VERSION_AE_1 = 1;
4416
4502
  const ZIP64_PROPERTIES = [
4417
4503
  [PROPERTY_NAME_UNCOMPRESSED_SIZE, MAX_32_BITS],
4418
4504
  [PROPERTY_NAME_COMPRESSED_SIZE, MAX_32_BITS],
@@ -4892,6 +4978,11 @@ let ZipEntry$1 = class ZipEntry {
4892
4978
  if (deflate64) {
4893
4979
  useCompressionStream = false;
4894
4980
  }
4981
+ const checkCrc32Option = getOptionValue$1(zipEntry, options, OPTION_CHECK_CRC32);
4982
+ const checkCrc32 = (checkCrc32Option === UNDEFINED_VALUE ?
4983
+ getOptionValue$1(zipEntry, options, OPTION_CHECK_SIGNATURE) :
4984
+ checkCrc32Option) && !passThrough &&
4985
+ (!encrypted || zipCrypto || (extraFieldAES && extraFieldAES.vendorVersion == VENDOR_VERSION_AE_1));
4895
4986
  const workerOptions = {
4896
4987
  options: {
4897
4988
  codecType: CODEC_INFLATE,
@@ -4899,7 +4990,8 @@ let ZipEntry$1 = class ZipEntry {
4899
4990
  rawPassword,
4900
4991
  zipCrypto,
4901
4992
  encryptionStrength: extraFieldAES && extraFieldAES.strength,
4902
- signed: getOptionValue$1(zipEntry, options, OPTION_CHECK_SIGNATURE) && !passThrough,
4993
+ checkCrc32,
4994
+ checkAuthenticationCode: getOptionValue$1(zipEntry, options, OPTION_CHECK_AUTHENTICATION_CODE),
4903
4995
  passwordVerification: zipCrypto && (dataDescriptor ? ((rawLastModDate >>> 8) & MAX_8_BITS) : ((signature >>> 24) & MAX_8_BITS)),
4904
4996
  outputSize: passThrough ? compressedSize : uncompressedSize,
4905
4997
  signature,
@@ -5015,6 +5107,7 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5015
5107
  const compressionMethod = getUint16(dataView, offset + 4);
5016
5108
  Object.assign(directory, {
5017
5109
  signature: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5110
+ crc32: getUint32(dataView, offset + HEADER_OFFSET_SIGNATURE),
5018
5111
  compressedSize: getUint32(dataView, offset + HEADER_OFFSET_COMPRESSED_SIZE),
5019
5112
  uncompressedSize: getUint32(dataView, offset + HEADER_OFFSET_UNCOMPRESSED_SIZE)
5020
5113
  });
@@ -5116,6 +5209,9 @@ function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
5116
5209
  compressionMethod: getUint16(extraFieldView, 5)
5117
5210
  });
5118
5211
  directory.compressionMethod = extraFieldAES.compressionMethod;
5212
+ if (extraFieldAES.vendorVersion != VENDOR_VERSION_AE_1) {
5213
+ directory.crc32 = UNDEFINED_VALUE;
5214
+ }
5119
5215
  }
5120
5216
 
5121
5217
  function readExtraFieldNTFS(extraFieldNTFS, directory) {
@@ -5134,26 +5230,22 @@ function readExtraFieldNTFS(extraFieldNTFS, directory) {
5134
5230
  } catch {
5135
5231
  // ignored
5136
5232
  }
5137
- try {
5138
- if (tag1Data && tag1Data.length == 24) {
5139
- const tag1View = getDataView(tag1Data);
5140
- const rawLastModDate = tag1View.getBigUint64(0, true);
5141
- const rawLastAccessDate = tag1View.getBigUint64(8, true);
5142
- const rawCreationDate = tag1View.getBigUint64(16, true);
5143
- Object.assign(extraFieldNTFS, {
5144
- rawLastModDate,
5145
- rawLastAccessDate,
5146
- rawCreationDate
5147
- });
5148
- const lastModDate = getDateNTFS(rawLastModDate);
5149
- const lastAccessDate = getDateNTFS(rawLastAccessDate);
5150
- const creationDate = getDateNTFS(rawCreationDate);
5151
- const extraFieldData = { lastModDate, lastAccessDate, creationDate };
5152
- Object.assign(extraFieldNTFS, extraFieldData);
5153
- Object.assign(directory, extraFieldData);
5154
- }
5155
- } catch {
5156
- // ignored
5233
+ if (tag1Data && tag1Data.length == 24) {
5234
+ const tag1View = getDataView(tag1Data);
5235
+ const rawLastModDate = tag1View.getBigUint64(0, true);
5236
+ const rawLastAccessDate = tag1View.getBigUint64(8, true);
5237
+ const rawCreationDate = tag1View.getBigUint64(16, true);
5238
+ Object.assign(extraFieldNTFS, {
5239
+ rawLastModDate,
5240
+ rawLastAccessDate,
5241
+ rawCreationDate
5242
+ });
5243
+ const lastModDate = getDateNTFS(rawLastModDate);
5244
+ const lastAccessDate = getDateNTFS(rawLastAccessDate);
5245
+ const creationDate = getDateNTFS(rawCreationDate);
5246
+ const extraFieldData = { lastModDate, lastAccessDate, creationDate };
5247
+ Object.assign(extraFieldNTFS, extraFieldData);
5248
+ Object.assign(directory, extraFieldData);
5157
5249
  }
5158
5250
  }
5159
5251
 
@@ -5456,11 +5548,7 @@ function getOptionValue$1(zipReader, options, name) {
5456
5548
 
5457
5549
  function getDate(timeRaw) {
5458
5550
  const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & MAX_16_BITS;
5459
- try {
5460
- return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
5461
- } catch {
5462
- // ignored
5463
- }
5551
+ return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
5464
5552
  }
5465
5553
 
5466
5554
  function getDateNTFS(timeRaw) {
@@ -5493,7 +5581,9 @@ var zipReader = /*#__PURE__*/Object.freeze({
5493
5581
  ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND,
5494
5582
  ERR_EOCDR_NOT_FOUND: ERR_EOCDR_NOT_FOUND,
5495
5583
  ERR_EXTRAFIELD_ZIP64_NOT_FOUND: ERR_EXTRAFIELD_ZIP64_NOT_FOUND,
5584
+ ERR_INVALID_AUTHENTICATION_CODE: ERR_INVALID_AUTHENTICATION_CODE,
5496
5585
  ERR_INVALID_COMPRESSED_DATA: ERR_INVALID_COMPRESSED_DATA,
5586
+ ERR_INVALID_CRC32: ERR_INVALID_CRC32,
5497
5587
  ERR_INVALID_PASSWORD: ERR_INVALID_PASSWORD,
5498
5588
  ERR_INVALID_SIGNATURE: ERR_INVALID_SIGNATURE,
5499
5589
  ERR_INVALID_UNCOMPRESSED_SIZE: ERR_INVALID_UNCOMPRESSED_SIZE,
@@ -5547,6 +5637,8 @@ const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
5547
5637
  const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
5548
5638
  const MIN_UNIX_TIME = -2147483648;
5549
5639
  const MAX_UNIX_TIME = 2147483647;
5640
+ const MIN_NTFS_TIME = BigInt(0);
5641
+ const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
5550
5642
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
5551
5643
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
5552
5644
  const ERR_UNDEFINED_READER = "Undefined reader";
@@ -5828,6 +5920,11 @@ async function addFile(zipWriter, name, reader, options) {
5828
5920
  zipWriter.files.set(name, UNDEFINED_VALUE);
5829
5921
  let fileEntry;
5830
5922
  try {
5923
+ const { resolvedOptions } = metadataInfo;
5924
+ if (resolvedOptions.level != 0 && resolvedOptions.compressionMethod === UNDEFINED_VALUE &&
5925
+ !resolvedOptions.passThrough && !(await supportsDeflate(zipWriter.config))) {
5926
+ resolvedOptions.level = 0;
5927
+ }
5831
5928
  const sizesInfo = await resolveSizes(zipWriter, reader, metadataInfo, options);
5832
5929
  ({ reader } = sizesInfo);
5833
5930
  const diskOffset = getDiskOffset(zipWriter.writer);
@@ -6048,9 +6145,6 @@ function resolveMetadata(zipWriter, name, options) {
6048
6145
  if (level !== UNDEFINED_VALUE && level != 6) {
6049
6146
  useCompressionStream = false;
6050
6147
  }
6051
- if (!useCompressionStream && !registeredCodec && (zipWriter.config.CompressionStream === UNDEFINED_VALUE && zipWriter.config.CompressionStreamZlib === UNDEFINED_VALUE)) {
6052
- level = 0;
6053
- }
6054
6148
  const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
6055
6149
  if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
6056
6150
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
@@ -6438,9 +6532,12 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6438
6532
  msdosAttributes
6439
6533
  };
6440
6534
  let {
6441
- signature,
6535
+ crc32: signature,
6442
6536
  uncompressedSize
6443
6537
  } = options;
6538
+ if (signature === UNDEFINED_VALUE) {
6539
+ ({ signature } = options);
6540
+ }
6444
6541
  let compressedSize = 0;
6445
6542
  if (!passThrough) {
6446
6543
  uncompressedSize = 0;
@@ -6458,7 +6555,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6458
6555
  encryptionStrength,
6459
6556
  zipCrypto: encrypted && zipCrypto,
6460
6557
  passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & MAX_8_BITS,
6461
- signed: !passThrough,
6558
+ computeCrc32: !passThrough,
6462
6559
  compressed: compressed && !passThrough,
6463
6560
  encrypted: encrypted && !passThrough,
6464
6561
  useWebWorkers,
@@ -6477,7 +6574,9 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6477
6574
  writer.size += compressedSize;
6478
6575
  if (!passThrough) {
6479
6576
  uncompressedSize = result.inputSize;
6480
- signature = result.signature;
6577
+ if (!encrypted || zipCrypto) {
6578
+ signature = result.signature;
6579
+ }
6481
6580
  }
6482
6581
  if ((!zip64CompressedSize && compressedSize >= MAX_32_BITS) ||
6483
6582
  (!zip64UncompressedSize && uncompressedSize >= MAX_32_BITS)) {
@@ -6516,6 +6615,7 @@ async function createFileEntry(reader, writer, { diskNumberStart, lock }, entryI
6516
6615
  headerArray,
6517
6616
  headerView,
6518
6617
  signature,
6618
+ crc32: encrypted && !zipCrypto ? UNDEFINED_VALUE : signature,
6519
6619
  extraFieldExtendedTimestampFlag,
6520
6620
  zip64UncompressedSize,
6521
6621
  zip64CompressedSize
@@ -6616,8 +6716,8 @@ function getHeaderInfo(options) {
6616
6716
  extraFieldNTFS.uint16(EXTRAFIELD_TYPE_NTFS_TAG1);
6617
6717
  extraFieldNTFS.uint16(24);
6618
6718
  extraFieldNTFS.uint64(lastModTimeNTFS);
6619
- extraFieldNTFS.uint64(getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
6620
- extraFieldNTFS.uint64(getTimeNTFS(creationDate) || lastModTimeNTFS);
6719
+ extraFieldNTFS.uint64(lastAccessDate ? getTimeNTFS(lastAccessDate) : lastModTimeNTFS);
6720
+ extraFieldNTFS.uint64(creationDate ? getTimeNTFS(creationDate) : lastModTimeNTFS);
6621
6721
  rawExtraFieldNTFS = extraFieldNTFS.array;
6622
6722
  } catch {
6623
6723
  rawExtraFieldNTFS = EMPTY_UINT8_ARRAY;
@@ -6677,7 +6777,7 @@ function getHeaderInfo(options) {
6677
6777
  if (extraFieldLength > MAX_16_BITS) {
6678
6778
  throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
6679
6779
  }
6680
- const dosLastModDate = new Date(Math.ceil(lastModDate.getTime() / 2000) * 2000);
6780
+ const dosLastModDate = new Date(Math.ceil(Math.floor(lastModDate.getTime() / 1000) / 2) * 2000);
6681
6781
  const {
6682
6782
  headerArray,
6683
6783
  headerView,
@@ -7186,7 +7286,8 @@ async function flushBufferedData(readable, writer, signal, onChunkWritten) {
7186
7286
 
7187
7287
  function getTimeNTFS(date) {
7188
7288
  if (date) {
7189
- return ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));
7289
+ const timeNTFS = ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));
7290
+ return timeNTFS < MIN_NTFS_TIME ? MIN_NTFS_TIME : timeNTFS > MAX_NTFS_TIME ? MAX_NTFS_TIME : timeNTFS;
7190
7291
  }
7191
7292
  }
7192
7293
 
@@ -9193,4 +9294,4 @@ function addChild(parent, name, params, directory) {
9193
9294
  }
9194
9295
  }
9195
9296
 
9196
- export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_PASSWORD, ERR_INVALID_SIGNATURE, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
9297
+ export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_PASSWORD, ERR_INVALID_SIGNATURE, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };