@zip.js/zip.js 2.14.1 → 2.16.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 (41) hide show
  1. package/BENCHMARKS.md +21 -11
  2. package/deno.json +1 -1
  3. package/dist/zip-core-external.js +217 -98
  4. package/dist/zip-core-external.min.js +1 -1
  5. package/dist/zip-core.js +217 -98
  6. package/dist/zip-core.min.js +1 -1
  7. package/dist/zip-fs-core-external.js +217 -98
  8. package/dist/zip-fs-core-external.min.js +1 -1
  9. package/dist/zip-fs-core.js +217 -98
  10. package/dist/zip-fs-core.min.js +1 -1
  11. package/dist/zip-fs-external.js +217 -98
  12. package/dist/zip-fs-external.min.js +1 -1
  13. package/dist/zip-fs-native.js +219 -100
  14. package/dist/zip-fs-native.min.js +1 -1
  15. package/dist/zip-fs.js +219 -100
  16. package/dist/zip-fs.min.js +1 -1
  17. package/dist/zip-legacy.js +219 -100
  18. package/dist/zip-legacy.min.js +1 -1
  19. package/dist/zip-native.js +219 -100
  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 +219 -100
  24. package/dist/zip.min.js +1 -1
  25. package/index-native.cjs +219 -100
  26. package/index-native.min.js +1 -1
  27. package/index.cjs +219 -100
  28. package/index.d.cts +46 -13
  29. package/index.d.ts +46 -13
  30. package/index.min.js +1 -1
  31. package/lib/core/codec-pool.js +35 -19
  32. package/lib/core/codec-worker.js +4 -2
  33. package/lib/core/io.js +3 -2
  34. package/lib/core/streams/zip-entry-stream.js +151 -66
  35. package/lib/core/util/decode-text.js +15 -1
  36. package/lib/core/version.js +1 -1
  37. package/lib/core/web-worker-inline-native.js +1 -1
  38. package/lib/core/web-worker-inline-wasm.js +1 -1
  39. package/lib/core/zip-reader.js +12 -10
  40. package/lib/core/zlib-streams-inline.js +1 -1
  41. package/package.json +1 -1
package/index.d.cts CHANGED
@@ -194,6 +194,19 @@ declare class TransformStreamLike {
194
194
  * Represents a generic class compressing data, e.g. the native `CompressionStream` class.
195
195
  */
196
196
  declare class CompressionStreamLike extends TransformStreamLike {
197
+ /**
198
+ * The formats the class supports, e.g. `["deflate-raw", "gzip"]`. When it is declared, the library reads it
199
+ * instead of probing a format by constructing the class, which a class that requires a module cannot afford.
200
+ */
201
+ static supportedFormats?: string[];
202
+ /**
203
+ * `true` when the class cannot be constructed before the module the entry point loads is ready, i.e. the
204
+ * WebAssembly module of zip.js or the module loaded by the `init` function passed to {@link initWorker}.
205
+ * The library then waits for the module before constructing the class, uses `CompressionStream` instead when
206
+ * the module fails to load, and constructs the class with the `"gzip"` format in order to read the CRC-32 of
207
+ * the data from the trailer, so the class must support that format.
208
+ */
209
+ static requiresModule?: boolean;
197
210
  /**
198
211
  * Creates the stream
199
212
  *
@@ -207,6 +220,19 @@ declare class CompressionStreamLike extends TransformStreamLike {
207
220
  * Represents a generic class decompressing data, e.g. the native `DecompressionStream` class.
208
221
  */
209
222
  declare class DecompressionStreamLike extends TransformStreamLike {
223
+ /**
224
+ * The formats the class supports, e.g. `["deflate-raw", "deflate64-raw"]`. When it is declared, the library
225
+ * reads it instead of probing a format by constructing the class, which a class that requires a module cannot
226
+ * afford.
227
+ */
228
+ static supportedFormats?: string[];
229
+ /**
230
+ * `true` when the class cannot be constructed before the module the entry point loads is ready, i.e. the
231
+ * WebAssembly module of zip.js or the module loaded by the `init` function passed to {@link initWorker}.
232
+ * The library then waits for the module before constructing the class, and uses `DecompressionStream`
233
+ * instead when the module fails to load.
234
+ */
235
+ static requiresModule?: boolean;
210
236
  /**
211
237
  * Creates the stream
212
238
  *
@@ -1646,15 +1672,18 @@ export interface GetEntriesOptions {
1646
1672
  * The encoding of the filename of the entry.
1647
1673
  *
1648
1674
  * The option is ignored when the general purpose bit 11 is set in the header of the entry: such a
1649
- * filename is always decoded as UTF-8. It is only read when the bit is not set, and the filename is
1650
- * then decoded as IBM Code Page 437 when the option is not set either.
1675
+ * filename is always decoded as UTF-8. It is only read when the bit is not set. When the option is not
1676
+ * set either, a filename holding bytes outside ASCII is decoded as UTF-8 if they form valid UTF-8, since
1677
+ * many writers store UTF-8 without setting the bit (macOS Archive Utility, `ditto`, the macOS build of
1678
+ * Info-ZIP `zip`, Java 6), and as IBM Code Page 437 otherwise. Set the option to decode such filenames
1679
+ * as another legacy encoding instead.
1651
1680
  */
1652
1681
  filenameEncoding?: string;
1653
1682
  /**
1654
1683
  * The encoding of the comment of the entry.
1655
1684
  *
1656
- * The option is ignored when the general purpose bit 11 is set in the header of the entry, see
1657
- * {@link GetEntriesOptions#filenameEncoding}.
1685
+ * The option is ignored when the general purpose bit 11 is set in the header of the entry, and valid
1686
+ * UTF-8 is detected when the option is not set, see {@link GetEntriesOptions#filenameEncoding}.
1658
1687
  */
1659
1688
  commentEncoding?: string;
1660
1689
  /**
@@ -1670,9 +1699,11 @@ export interface GetEntriesOptions {
1670
1699
  * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
1671
1700
  * tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
1672
1701
  * concatenated archive), central directory records not accounted for by the end of central directory record, an
1673
- * end of central directory record disagreeing with its zip64 counterpart, and duplicate filenames. When reading
1674
- * the content of an entry, it also validates the local file header against the central directory record (see
1675
- * {@link ZipReaderOptions#checkAmbiguity}).
1702
+ * end of central directory record disagreeing with its zip64 counterpart, and duplicate filenames. Filenames are
1703
+ * compared exactly, after {@link GetEntriesOptions#normalizeFilename}: two names differing only by letter case or
1704
+ * by Unicode normalization form are distinct entries, even though they collide on a case-insensitive or
1705
+ * normalizing filesystem. When reading the content of an entry, it also validates the local file header against
1706
+ * the central directory record (see {@link ZipReaderOptions#checkAmbiguity}).
1676
1707
  *
1677
1708
  * This is the boolean form of {@link GetEntriesOptions#strictness}: `true` means `"strict"` and `false` means
1678
1709
  * any value but `"strict"`. When both options are set, the value passed to {@link ZipReader#getEntries} takes
@@ -1710,15 +1741,17 @@ export interface GetEntriesOptions {
1710
1741
  * {@link ERR_UNSAFE_FILENAME} error carrying the offending name in its `filename` property.
1711
1742
  *
1712
1743
  * - `"strict"`: reject the names rejected by `"balanced"`, plus the names that do not map cleanly to a file
1713
- * path, i.e. empty names and names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`).
1744
+ * path, i.e. empty names, names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`), and
1745
+ * names containing a NUL character.
1714
1746
  * - `"balanced"`: reject names that would escape the directory they are extracted into, i.e. names containing
1715
- * a `".."` path component, and absolute names, i.e. names starting with `"/"`, with a drive letter (e.g.
1716
- * `"C:/file.txt"`) or with two backslashes (UNC paths).
1747
+ * a `".."` path component delimited by slashes or by backslashes (e.g. `"..\\file.txt"`, which a Windows host
1748
+ * resolves as a parent directory), and absolute names, i.e. names starting with `"/"`, with a drive letter
1749
+ * (e.g. `"C:/file.txt"`) or with a backslash (root-relative and UNC paths on Windows).
1717
1750
  * - `"tolerant"`: never reject a name.
1718
1751
  *
1719
- * A backslash is never interpreted as a path separator: it is a valid filename character on UNIX systems, and
1720
- * it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with another
1721
- * charset.
1752
+ * A backslash is otherwise not interpreted as a path separator: it is a valid filename character on UNIX
1753
+ * systems, and it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with
1754
+ * another charset.
1722
1755
  *
1723
1756
  * Names are validated, never rewritten, so the filename reported for an entry always matches its central
1724
1757
  * directory record.
package/index.d.ts CHANGED
@@ -194,6 +194,19 @@ declare class TransformStreamLike {
194
194
  * Represents a generic class compressing data, e.g. the native `CompressionStream` class.
195
195
  */
196
196
  declare class CompressionStreamLike extends TransformStreamLike {
197
+ /**
198
+ * The formats the class supports, e.g. `["deflate-raw", "gzip"]`. When it is declared, the library reads it
199
+ * instead of probing a format by constructing the class, which a class that requires a module cannot afford.
200
+ */
201
+ static supportedFormats?: string[];
202
+ /**
203
+ * `true` when the class cannot be constructed before the module the entry point loads is ready, i.e. the
204
+ * WebAssembly module of zip.js or the module loaded by the `init` function passed to {@link initWorker}.
205
+ * The library then waits for the module before constructing the class, uses `CompressionStream` instead when
206
+ * the module fails to load, and constructs the class with the `"gzip"` format in order to read the CRC-32 of
207
+ * the data from the trailer, so the class must support that format.
208
+ */
209
+ static requiresModule?: boolean;
197
210
  /**
198
211
  * Creates the stream
199
212
  *
@@ -207,6 +220,19 @@ declare class CompressionStreamLike extends TransformStreamLike {
207
220
  * Represents a generic class decompressing data, e.g. the native `DecompressionStream` class.
208
221
  */
209
222
  declare class DecompressionStreamLike extends TransformStreamLike {
223
+ /**
224
+ * The formats the class supports, e.g. `["deflate-raw", "deflate64-raw"]`. When it is declared, the library
225
+ * reads it instead of probing a format by constructing the class, which a class that requires a module cannot
226
+ * afford.
227
+ */
228
+ static supportedFormats?: string[];
229
+ /**
230
+ * `true` when the class cannot be constructed before the module the entry point loads is ready, i.e. the
231
+ * WebAssembly module of zip.js or the module loaded by the `init` function passed to {@link initWorker}.
232
+ * The library then waits for the module before constructing the class, and uses `DecompressionStream`
233
+ * instead when the module fails to load.
234
+ */
235
+ static requiresModule?: boolean;
210
236
  /**
211
237
  * Creates the stream
212
238
  *
@@ -1646,15 +1672,18 @@ export interface GetEntriesOptions {
1646
1672
  * The encoding of the filename of the entry.
1647
1673
  *
1648
1674
  * The option is ignored when the general purpose bit 11 is set in the header of the entry: such a
1649
- * filename is always decoded as UTF-8. It is only read when the bit is not set, and the filename is
1650
- * then decoded as IBM Code Page 437 when the option is not set either.
1675
+ * filename is always decoded as UTF-8. It is only read when the bit is not set. When the option is not
1676
+ * set either, a filename holding bytes outside ASCII is decoded as UTF-8 if they form valid UTF-8, since
1677
+ * many writers store UTF-8 without setting the bit (macOS Archive Utility, `ditto`, the macOS build of
1678
+ * Info-ZIP `zip`, Java 6), and as IBM Code Page 437 otherwise. Set the option to decode such filenames
1679
+ * as another legacy encoding instead.
1651
1680
  */
1652
1681
  filenameEncoding?: string;
1653
1682
  /**
1654
1683
  * The encoding of the comment of the entry.
1655
1684
  *
1656
- * The option is ignored when the general purpose bit 11 is set in the header of the entry, see
1657
- * {@link GetEntriesOptions#filenameEncoding}.
1685
+ * The option is ignored when the general purpose bit 11 is set in the header of the entry, and valid
1686
+ * UTF-8 is detected when the option is not set, see {@link GetEntriesOptions#filenameEncoding}.
1658
1687
  */
1659
1688
  commentEncoding?: string;
1660
1689
  /**
@@ -1670,9 +1699,11 @@ export interface GetEntriesOptions {
1670
1699
  * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
1671
1700
  * tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
1672
1701
  * concatenated archive), central directory records not accounted for by the end of central directory record, an
1673
- * end of central directory record disagreeing with its zip64 counterpart, and duplicate filenames. When reading
1674
- * the content of an entry, it also validates the local file header against the central directory record (see
1675
- * {@link ZipReaderOptions#checkAmbiguity}).
1702
+ * end of central directory record disagreeing with its zip64 counterpart, and duplicate filenames. Filenames are
1703
+ * compared exactly, after {@link GetEntriesOptions#normalizeFilename}: two names differing only by letter case or
1704
+ * by Unicode normalization form are distinct entries, even though they collide on a case-insensitive or
1705
+ * normalizing filesystem. When reading the content of an entry, it also validates the local file header against
1706
+ * the central directory record (see {@link ZipReaderOptions#checkAmbiguity}).
1676
1707
  *
1677
1708
  * This is the boolean form of {@link GetEntriesOptions#strictness}: `true` means `"strict"` and `false` means
1678
1709
  * any value but `"strict"`. When both options are set, the value passed to {@link ZipReader#getEntries} takes
@@ -1710,15 +1741,17 @@ export interface GetEntriesOptions {
1710
1741
  * {@link ERR_UNSAFE_FILENAME} error carrying the offending name in its `filename` property.
1711
1742
  *
1712
1743
  * - `"strict"`: reject the names rejected by `"balanced"`, plus the names that do not map cleanly to a file
1713
- * path, i.e. empty names and names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`).
1744
+ * path, i.e. empty names, names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`), and
1745
+ * names containing a NUL character.
1714
1746
  * - `"balanced"`: reject names that would escape the directory they are extracted into, i.e. names containing
1715
- * a `".."` path component, and absolute names, i.e. names starting with `"/"`, with a drive letter (e.g.
1716
- * `"C:/file.txt"`) or with two backslashes (UNC paths).
1747
+ * a `".."` path component delimited by slashes or by backslashes (e.g. `"..\\file.txt"`, which a Windows host
1748
+ * resolves as a parent directory), and absolute names, i.e. names starting with `"/"`, with a drive letter
1749
+ * (e.g. `"C:/file.txt"`) or with a backslash (root-relative and UNC paths on Windows).
1717
1750
  * - `"tolerant"`: never reject a name.
1718
1751
  *
1719
- * A backslash is never interpreted as a path separator: it is a valid filename character on UNIX systems, and
1720
- * it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with another
1721
- * charset.
1752
+ * A backslash is otherwise not interpreted as a path separator: it is a valid filename character on UNIX
1753
+ * systems, and it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with
1754
+ * another charset.
1722
1755
  *
1723
1756
  * Names are validated, never rewritten, so the filename reported for an entry always matches its central
1724
1757
  * directory record.