@zip.js/zip.js 2.16.1 → 2.17.0

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 (45) hide show
  1. package/deno.json +1 -1
  2. package/dist/zip-core-external.js +169 -119
  3. package/dist/zip-core-external.min.js +1 -1
  4. package/dist/zip-core.js +138 -106
  5. package/dist/zip-core.min.js +1 -1
  6. package/dist/zip-fs-core-external.js +181 -121
  7. package/dist/zip-fs-core-external.min.js +1 -1
  8. package/dist/zip-fs-core.js +150 -108
  9. package/dist/zip-fs-core.min.js +1 -1
  10. package/dist/zip-fs-external.js +181 -121
  11. package/dist/zip-fs-external.min.js +1 -1
  12. package/dist/zip-fs-native.js +153 -111
  13. package/dist/zip-fs-native.min.js +1 -1
  14. package/dist/zip-fs.js +182 -121
  15. package/dist/zip-fs.min.js +1 -1
  16. package/dist/zip-legacy.js +140 -108
  17. package/dist/zip-legacy.min.js +1 -1
  18. package/dist/zip-native.js +141 -109
  19. package/dist/zip-native.min.js +1 -1
  20. package/dist/zip-web-worker-native.js +1 -1
  21. package/dist/zip-web-worker.js +1 -1
  22. package/dist/zip.js +170 -119
  23. package/dist/zip.min.js +1 -1
  24. package/index-native.cjs +153 -111
  25. package/index-native.min.js +1 -1
  26. package/index.cjs +182 -121
  27. package/index.d.cts +58 -20
  28. package/index.d.ts +58 -20
  29. package/index.min.js +1 -1
  30. package/lib/core/codec-pool.js +2 -0
  31. package/lib/core/codec-worker-web.js +11 -3
  32. package/lib/core/codec-worker.js +2 -1
  33. package/lib/core/streams/codec-stream.js +2 -0
  34. package/lib/core/streams/zip-entry-stream.js +123 -102
  35. package/lib/core/streams/zlib-js/zlib-streams.min.js +1 -1
  36. package/lib/core/streams/zlib-wasm/zlib-streams.js +31 -12
  37. package/lib/core/version.js +1 -1
  38. package/lib/core/web-worker-base.js +1 -1
  39. package/lib/core/web-worker-inline-native.js +1 -1
  40. package/lib/core/web-worker-inline-wasm.js +1 -1
  41. package/lib/core/zip-fs.js +16 -3
  42. package/lib/core/zip-reader.js +3 -0
  43. package/lib/core/zip-writer.js +1 -0
  44. package/lib/zip-core-reader.js +1 -0
  45. package/package.json +1 -1
package/index.d.cts CHANGED
@@ -2009,7 +2009,10 @@ export interface ZipReaderOptions {
2009
2009
  *
2010
2010
  * A signal already aborted when the operation starts rejects it with {@link ERR_ABORTED} as the
2011
2011
  * reason of the `AbortError`, or with `signal.reason` when it is set, without relying on the
2012
- * `signal` option of `pipeTo` that the oldest supported engines ignore.
2012
+ * `signal` option of `pipeTo` that the oldest supported engines ignore. A signal aborted while the
2013
+ * entry is being read rejects the operation as well, whether its compressed data is still being
2014
+ * consumed or its content still being written; on those engines, the content is written to the end
2015
+ * before the operation is rejected.
2013
2016
  */
2014
2017
  signal?: AbortSignal;
2015
2018
  /**
@@ -3423,7 +3426,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3423
3426
  *
3424
3427
  * A signal already aborted when the operation starts rejects it with {@link ERR_ABORTED} as the
3425
3428
  * reason of the `AbortError`, or with `signal.reason` when it is set, without relying on the
3426
- * `signal` option of `pipeTo` that the oldest supported engines ignore.
3429
+ * `signal` option of `pipeTo` that the oldest supported engines ignore. A signal aborted while the
3430
+ * entry is being added rejects the operation as well, whether its content is still being read or
3431
+ * its compressed data still being written; on those engines, the data is written to the end before
3432
+ * the operation is rejected.
3427
3433
  */
3428
3434
  signal?: AbortSignal;
3429
3435
  /**
@@ -4544,9 +4550,13 @@ export class ZipDirectoryEntry extends ZipEntry {
4544
4550
  * encrypted with ZipCrypto verifies the password on a single byte, so one wrong password in 256 passes
4545
4551
  * that check and fails while reading the content instead: for such entries the password is first
4546
4552
  * verified alone, the CRC32 of the content is then checked whatever the {@link ZipReaderOptions#checkCrc32}
4547
- * option says, and any failure of the read is treated as a wrong password and the next candidate is
4548
- * tried. An entry encrypted with AES verifies it on two bytes, so a failure of the read that follows is
4549
- * reported as-is, e.g. as an {@link ERR_INVALID_AUTHENTICATION_CODE} error.
4553
+ * option says, and a read failing with an {@link ERR_INVALID_CRC32}, {@link ERR_INVALID_COMPRESSED_DATA}
4554
+ * or {@link ERR_INVALID_UNCOMPRESSED_SIZE} error is treated as a wrong password and the next candidate is
4555
+ * tried. Any other failure, e.g. a failure of the reader or an {@link ERR_CODEC_OUT_OF_MEMORY} error, is
4556
+ * reported as-is. A corrupted entry read with the right password is reported as a wrong password too,
4557
+ * since nothing tells it from a wrong password passing the check. An entry encrypted with AES verifies
4558
+ * the password on two bytes, so a failure of the read that follows is reported as-is, e.g. as an
4559
+ * {@link ERR_INVALID_AUTHENTICATION_CODE} error.
4550
4560
  *
4551
4561
  * The options are set when importing the zip file, in the {@link ZipDirectoryEntryExportOptions#readerOptions}
4552
4562
  * option of an export, and when reading one entry with `{@link ZipFileEntry}#get*()`. They apply to the
@@ -4559,8 +4569,9 @@ export interface PasswordCandidatesOptions {
4559
4569
  * passwords already accepted by another entry of the same imported zip file. An empty string is
4560
4570
  * ignored.
4561
4571
  *
4562
- * When every candidate fails, the entry raises an {@link ERR_INVALID_PASSWORD} error, unless the
4563
- * {@link PasswordCandidatesOptions#requestPassword} option is set.
4572
+ * When every candidate fails, the entry raises an {@link ERR_INVALID_PASSWORD} error whose `cause` is
4573
+ * the error raised by the last candidate, unless the {@link PasswordCandidatesOptions#requestPassword}
4574
+ * option is set.
4564
4575
  *
4565
4576
  * A value which is neither an array of strings nor unset throws an {@link ERR_INVALID_PASSWORDS}
4566
4577
  * error.
@@ -4573,8 +4584,9 @@ export interface PasswordCandidatesOptions {
4573
4584
  *
4574
4585
  * A string is tried on the entry, and the function is called again when it fails, with the
4575
4586
  * {@link ERR_INVALID_PASSWORD} error. `undefined` or `null` gives up: the entry raises an
4576
- * {@link ERR_INVALID_PASSWORD} error, or an {@link ERR_ENCRYPTED} error when no candidate was
4577
- * tried. A value of another type throws an {@link ERR_INVALID_REQUEST_PASSWORD} error. The
4587
+ * {@link ERR_INVALID_PASSWORD} error whose `cause` is the error raised by the last candidate, or an
4588
+ * {@link ERR_ENCRYPTED} error when no candidate was tried. A value of another type throws an
4589
+ * {@link ERR_INVALID_REQUEST_PASSWORD} error. The
4578
4590
  * function is not called for the entries whose password is already known.
4579
4591
  *
4580
4592
  * When several entries are read concurrently, e.g. by `{@link ZipDirectoryEntry}#export*()` with the
@@ -5006,6 +5018,12 @@ export const ERR_INVALID_CODEC_MODULE: string;
5006
5018
  /**
5007
5019
  * Invalid CRC-32 checksum error, thrown when the {@link ZipReaderOptions#checkCrc32} option is set and the CRC-32
5008
5020
  * checksum of an entry does not match the value stored in the zip file.
5021
+ *
5022
+ * @remarks
5023
+ * When the inflater verifies the checksum itself, through a gzip trailer that zip.js builds from the stored
5024
+ * CRC-32 and uncompressed size, it rejects the trailer as a whole and its error is kept as the `cause`. A
5025
+ * stored uncompressed size larger than the data therefore raises this error too on that route, whereas a
5026
+ * stored size smaller than the data raises {@link ERR_INVALID_UNCOMPRESSED_SIZE} on every route.
5009
5027
  */
5010
5028
  export const ERR_INVALID_CRC32: string;
5011
5029
  /**
@@ -5014,24 +5032,44 @@ export const ERR_INVALID_CRC32: string;
5014
5032
  */
5015
5033
  export const ERR_INVALID_AUTHENTICATION_CODE: string;
5016
5034
  /**
5017
- * Invalid uncompressed size error
5035
+ * Invalid uncompressed size error, thrown when an entry inflates to more bytes than its stored uncompressed size.
5036
+ *
5037
+ * @remarks
5038
+ * An entry encrypted with AES that stores no CRC-32 (AE-2) and inflated through a gzip container, on a host
5039
+ * whose inflater lacks `"deflate-raw"`, raises this error when it inflates to fewer bytes as well, since the
5040
+ * end of its data is told by the stored size alone.
5018
5041
  */
5019
5042
  export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
5020
5043
  /**
5021
- * Invalid compressed data error
5044
+ * Invalid compressed data error, thrown when the codec rejects the compressed data of an entry.
5022
5045
  *
5023
5046
  * @remarks
5024
- * The way malformed compressed data is reported is not uniform across codec
5025
- * backends. Bytes trailing a complete DEFLATE stream (e.g. a wrong
5026
- * `compressedSize`) are tolerated by the bundled WASM and pure-JS codecs, which
5027
- * decompress the valid data and ignore the extra bytes, but are rejected by the
5028
- * native `DecompressionStream` with its own `TypeError` (on Node,
5029
- * `ERR_TRAILING_JUNK_AFTER_STREAM_END`) rather than this error. Any data that is
5030
- * returned is always validated against the entry's uncompressed size (and CRC
5031
- * when `checkCrc32` is set), so it is never silently truncated; the backends
5032
- * differ only in whether trailing bytes are ignored or raised as an error.
5047
+ * The error is the same whatever inflates the data, and the error the codec raised is kept as its
5048
+ * `cause`: the `TypeError` of a native `DecompressionStream`, whose message depends on the engine,
5049
+ * or the error of the bundled WASM or pure-JS codec. An error raised while reading the data, e.g.
5050
+ * by the reader of the zip file or by the decryption of the entry, is not a codec failure and
5051
+ * reaches the caller unchanged.
5052
+ *
5053
+ * Bytes trailing a complete DEFLATE stream (e.g. a wrong `compressedSize`) are rejected by every
5054
+ * codec, the native `DecompressionStream` (on Node.js, with `ERR_TRAILING_JUNK_AFTER_STREAM_END`
5055
+ * as the `code` of the cause) and the bundled WASM and pure-JS codecs alike. Any data that is
5056
+ * returned is always validated against the entry's uncompressed size (and CRC when
5057
+ * {@link ZipReaderOptions#checkCrc32} is set), so it is never silently truncated.
5033
5058
  */
5034
5059
  export const ERR_INVALID_COMPRESSED_DATA: string;
5060
+ /**
5061
+ * Codec out of memory error, thrown when the codec of an entry cannot allocate the memory it needs, e.g. when
5062
+ * the fixed heap of the bundled WASM module is exhausted by too many entries processed concurrently in the same
5063
+ * scope.
5064
+ *
5065
+ * @remarks
5066
+ * The error the codec raised is kept as the `cause`. The failure is recognized by the `code` property of that
5067
+ * error, `"Z_MEM_ERROR"`, which the bundled WASM codec sets and the native `DecompressionStream` of Node.js
5068
+ * would set; a codec reporting the failure without it is reported as {@link ERR_INVALID_COMPRESSED_DATA} when
5069
+ * reading, or with its own error when writing. When writing, only a codec that fails to allocate its state is
5070
+ * reported with this error: a failure while compressing keeps the error of the codec.
5071
+ */
5072
+ export const ERR_CODEC_OUT_OF_MEMORY: string;
5035
5073
  /**
5036
5074
  * Invalid password error
5037
5075
  */
package/index.d.ts CHANGED
@@ -2009,7 +2009,10 @@ export interface ZipReaderOptions {
2009
2009
  *
2010
2010
  * A signal already aborted when the operation starts rejects it with {@link ERR_ABORTED} as the
2011
2011
  * reason of the `AbortError`, or with `signal.reason` when it is set, without relying on the
2012
- * `signal` option of `pipeTo` that the oldest supported engines ignore.
2012
+ * `signal` option of `pipeTo` that the oldest supported engines ignore. A signal aborted while the
2013
+ * entry is being read rejects the operation as well, whether its compressed data is still being
2014
+ * consumed or its content still being written; on those engines, the content is written to the end
2015
+ * before the operation is rejected.
2013
2016
  */
2014
2017
  signal?: AbortSignal;
2015
2018
  /**
@@ -3423,7 +3426,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3423
3426
  *
3424
3427
  * A signal already aborted when the operation starts rejects it with {@link ERR_ABORTED} as the
3425
3428
  * reason of the `AbortError`, or with `signal.reason` when it is set, without relying on the
3426
- * `signal` option of `pipeTo` that the oldest supported engines ignore.
3429
+ * `signal` option of `pipeTo` that the oldest supported engines ignore. A signal aborted while the
3430
+ * entry is being added rejects the operation as well, whether its content is still being read or
3431
+ * its compressed data still being written; on those engines, the data is written to the end before
3432
+ * the operation is rejected.
3427
3433
  */
3428
3434
  signal?: AbortSignal;
3429
3435
  /**
@@ -4544,9 +4550,13 @@ export class ZipDirectoryEntry extends ZipEntry {
4544
4550
  * encrypted with ZipCrypto verifies the password on a single byte, so one wrong password in 256 passes
4545
4551
  * that check and fails while reading the content instead: for such entries the password is first
4546
4552
  * verified alone, the CRC32 of the content is then checked whatever the {@link ZipReaderOptions#checkCrc32}
4547
- * option says, and any failure of the read is treated as a wrong password and the next candidate is
4548
- * tried. An entry encrypted with AES verifies it on two bytes, so a failure of the read that follows is
4549
- * reported as-is, e.g. as an {@link ERR_INVALID_AUTHENTICATION_CODE} error.
4553
+ * option says, and a read failing with an {@link ERR_INVALID_CRC32}, {@link ERR_INVALID_COMPRESSED_DATA}
4554
+ * or {@link ERR_INVALID_UNCOMPRESSED_SIZE} error is treated as a wrong password and the next candidate is
4555
+ * tried. Any other failure, e.g. a failure of the reader or an {@link ERR_CODEC_OUT_OF_MEMORY} error, is
4556
+ * reported as-is. A corrupted entry read with the right password is reported as a wrong password too,
4557
+ * since nothing tells it from a wrong password passing the check. An entry encrypted with AES verifies
4558
+ * the password on two bytes, so a failure of the read that follows is reported as-is, e.g. as an
4559
+ * {@link ERR_INVALID_AUTHENTICATION_CODE} error.
4550
4560
  *
4551
4561
  * The options are set when importing the zip file, in the {@link ZipDirectoryEntryExportOptions#readerOptions}
4552
4562
  * option of an export, and when reading one entry with `{@link ZipFileEntry}#get*()`. They apply to the
@@ -4559,8 +4569,9 @@ export interface PasswordCandidatesOptions {
4559
4569
  * passwords already accepted by another entry of the same imported zip file. An empty string is
4560
4570
  * ignored.
4561
4571
  *
4562
- * When every candidate fails, the entry raises an {@link ERR_INVALID_PASSWORD} error, unless the
4563
- * {@link PasswordCandidatesOptions#requestPassword} option is set.
4572
+ * When every candidate fails, the entry raises an {@link ERR_INVALID_PASSWORD} error whose `cause` is
4573
+ * the error raised by the last candidate, unless the {@link PasswordCandidatesOptions#requestPassword}
4574
+ * option is set.
4564
4575
  *
4565
4576
  * A value which is neither an array of strings nor unset throws an {@link ERR_INVALID_PASSWORDS}
4566
4577
  * error.
@@ -4573,8 +4584,9 @@ export interface PasswordCandidatesOptions {
4573
4584
  *
4574
4585
  * A string is tried on the entry, and the function is called again when it fails, with the
4575
4586
  * {@link ERR_INVALID_PASSWORD} error. `undefined` or `null` gives up: the entry raises an
4576
- * {@link ERR_INVALID_PASSWORD} error, or an {@link ERR_ENCRYPTED} error when no candidate was
4577
- * tried. A value of another type throws an {@link ERR_INVALID_REQUEST_PASSWORD} error. The
4587
+ * {@link ERR_INVALID_PASSWORD} error whose `cause` is the error raised by the last candidate, or an
4588
+ * {@link ERR_ENCRYPTED} error when no candidate was tried. A value of another type throws an
4589
+ * {@link ERR_INVALID_REQUEST_PASSWORD} error. The
4578
4590
  * function is not called for the entries whose password is already known.
4579
4591
  *
4580
4592
  * When several entries are read concurrently, e.g. by `{@link ZipDirectoryEntry}#export*()` with the
@@ -5006,6 +5018,12 @@ export const ERR_INVALID_CODEC_MODULE: string;
5006
5018
  /**
5007
5019
  * Invalid CRC-32 checksum error, thrown when the {@link ZipReaderOptions#checkCrc32} option is set and the CRC-32
5008
5020
  * checksum of an entry does not match the value stored in the zip file.
5021
+ *
5022
+ * @remarks
5023
+ * When the inflater verifies the checksum itself, through a gzip trailer that zip.js builds from the stored
5024
+ * CRC-32 and uncompressed size, it rejects the trailer as a whole and its error is kept as the `cause`. A
5025
+ * stored uncompressed size larger than the data therefore raises this error too on that route, whereas a
5026
+ * stored size smaller than the data raises {@link ERR_INVALID_UNCOMPRESSED_SIZE} on every route.
5009
5027
  */
5010
5028
  export const ERR_INVALID_CRC32: string;
5011
5029
  /**
@@ -5014,24 +5032,44 @@ export const ERR_INVALID_CRC32: string;
5014
5032
  */
5015
5033
  export const ERR_INVALID_AUTHENTICATION_CODE: string;
5016
5034
  /**
5017
- * Invalid uncompressed size error
5035
+ * Invalid uncompressed size error, thrown when an entry inflates to more bytes than its stored uncompressed size.
5036
+ *
5037
+ * @remarks
5038
+ * An entry encrypted with AES that stores no CRC-32 (AE-2) and inflated through a gzip container, on a host
5039
+ * whose inflater lacks `"deflate-raw"`, raises this error when it inflates to fewer bytes as well, since the
5040
+ * end of its data is told by the stored size alone.
5018
5041
  */
5019
5042
  export const ERR_INVALID_UNCOMPRESSED_SIZE: string;
5020
5043
  /**
5021
- * Invalid compressed data error
5044
+ * Invalid compressed data error, thrown when the codec rejects the compressed data of an entry.
5022
5045
  *
5023
5046
  * @remarks
5024
- * The way malformed compressed data is reported is not uniform across codec
5025
- * backends. Bytes trailing a complete DEFLATE stream (e.g. a wrong
5026
- * `compressedSize`) are tolerated by the bundled WASM and pure-JS codecs, which
5027
- * decompress the valid data and ignore the extra bytes, but are rejected by the
5028
- * native `DecompressionStream` with its own `TypeError` (on Node,
5029
- * `ERR_TRAILING_JUNK_AFTER_STREAM_END`) rather than this error. Any data that is
5030
- * returned is always validated against the entry's uncompressed size (and CRC
5031
- * when `checkCrc32` is set), so it is never silently truncated; the backends
5032
- * differ only in whether trailing bytes are ignored or raised as an error.
5047
+ * The error is the same whatever inflates the data, and the error the codec raised is kept as its
5048
+ * `cause`: the `TypeError` of a native `DecompressionStream`, whose message depends on the engine,
5049
+ * or the error of the bundled WASM or pure-JS codec. An error raised while reading the data, e.g.
5050
+ * by the reader of the zip file or by the decryption of the entry, is not a codec failure and
5051
+ * reaches the caller unchanged.
5052
+ *
5053
+ * Bytes trailing a complete DEFLATE stream (e.g. a wrong `compressedSize`) are rejected by every
5054
+ * codec, the native `DecompressionStream` (on Node.js, with `ERR_TRAILING_JUNK_AFTER_STREAM_END`
5055
+ * as the `code` of the cause) and the bundled WASM and pure-JS codecs alike. Any data that is
5056
+ * returned is always validated against the entry's uncompressed size (and CRC when
5057
+ * {@link ZipReaderOptions#checkCrc32} is set), so it is never silently truncated.
5033
5058
  */
5034
5059
  export const ERR_INVALID_COMPRESSED_DATA: string;
5060
+ /**
5061
+ * Codec out of memory error, thrown when the codec of an entry cannot allocate the memory it needs, e.g. when
5062
+ * the fixed heap of the bundled WASM module is exhausted by too many entries processed concurrently in the same
5063
+ * scope.
5064
+ *
5065
+ * @remarks
5066
+ * The error the codec raised is kept as the `cause`. The failure is recognized by the `code` property of that
5067
+ * error, `"Z_MEM_ERROR"`, which the bundled WASM codec sets and the native `DecompressionStream` of Node.js
5068
+ * would set; a codec reporting the failure without it is reported as {@link ERR_INVALID_COMPRESSED_DATA} when
5069
+ * reading, or with its own error when writing. When writing, only a codec that fails to allocate its state is
5070
+ * reported with this error: a failure while compressing keeps the error of the codec.
5071
+ */
5072
+ export const ERR_CODEC_OUT_OF_MEMORY: string;
5035
5073
  /**
5036
5074
  * Invalid password error
5037
5075
  */