@zip.js/zip.js 2.11.4 → 2.12.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.
- package/deno.json +1 -1
- package/dist/zip-core-external.js +427 -110
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +437 -107
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +492 -230
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +505 -227
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +492 -230
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +507 -229
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +508 -230
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +439 -109
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +439 -109
- package/dist/zip-native.min.js +1 -1
- package/dist/zip-web-worker-native.js +1 -1
- package/dist/zip-web-worker.js +1 -1
- package/dist/zip.js +440 -110
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +507 -229
- package/index-native.min.js +1 -1
- package/index.cjs +508 -230
- package/index.d.cts +468 -59
- package/index.d.ts +468 -59
- package/index.min.js +1 -1
- package/lib/core/codec-worker-web.js +10 -2
- package/lib/core/codec-worker.js +4 -3
- package/lib/core/configuration.js +20 -5
- package/lib/core/constants.js +2 -0
- package/lib/core/io.js +13 -5
- package/lib/core/options.js +16 -0
- package/lib/core/streams/codec-stream.js +6 -0
- package/lib/core/util/warnings.js +42 -0
- package/lib/core/version.js +1 -1
- package/lib/core/web-worker-base.js +4 -3
- package/lib/core/web-worker-inline-native.js +1 -1
- package/lib/core/web-worker-inline-wasm.js +1 -1
- package/lib/core/zip-entry.js +49 -1
- package/lib/core/zip-fs.js +43 -132
- package/lib/core/zip-reader.js +106 -48
- package/lib/core/zip-writer.js +236 -54
- package/lib/zip-core-base.js +9 -3
- package/lib/zip-core-reader.js +2 -0
- package/lib/zip-core-writer.js +6 -1
- package/lib/zip-module-wasm-base.js +2 -2
- package/package.json +5 -3
package/index.d.ts
CHANGED
|
@@ -461,6 +461,8 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
461
461
|
* The base URL against which the relative URIs are resolved, i.e. {@link Configuration#workerURI},
|
|
462
462
|
* {@link Configuration#wasmURI} and {@link CodecDefinition#codecURI}.
|
|
463
463
|
*
|
|
464
|
+
* It must be a string, see {@link ERR_INVALID_BASE_URI}: it is posted to the web workers, and a `URL` object cannot be cloned.
|
|
465
|
+
*
|
|
464
466
|
* @defaultValue the URL of the module of zip.js
|
|
465
467
|
*/
|
|
466
468
|
baseURI?: string;
|
|
@@ -481,9 +483,13 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
481
483
|
* The worker is created as a module worker, unless the URI is a Data URI or a Blob URI, in which case it is created as a classic
|
|
482
484
|
* worker. See {@link Configuration#createWorker} for an example of classic worker script installing a polyfill of the Streams API.
|
|
483
485
|
*
|
|
486
|
+
* It can also be a function returning the URI, which is how the builds embedding the worker script produce it on demand. The
|
|
487
|
+
* function is called with `useBlobURI` set to `true` first, and called again with `false` when creating the worker from the Blob
|
|
488
|
+
* URI it returned failed, e.g. when the CSP of the page blocks Blob URIs. Anything else is rejected, see {@link ERR_INVALID_URI}.
|
|
489
|
+
*
|
|
484
490
|
* @defaultValue "./core/web-worker-wasm.js", or "./core/web-worker-native.js" for the builds using the native implementations
|
|
485
491
|
*/
|
|
486
|
-
workerURI?: string;
|
|
492
|
+
workerURI?: string | ((useBlobURI: boolean) => string);
|
|
487
493
|
/**
|
|
488
494
|
* The function used to create the web workers, taking precedence over `workerURI`.
|
|
489
495
|
*
|
|
@@ -524,9 +530,13 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
524
530
|
* });
|
|
525
531
|
* ```
|
|
526
532
|
*
|
|
533
|
+
* It can also be a function returning the URI, called the first time the module is needed. That is how the builds embedding the
|
|
534
|
+
* WebAssembly module produce their Data URI, and the way to defer an expensive resolution until it is known to be useful.
|
|
535
|
+
* Anything else is rejected, see {@link ERR_INVALID_URI}.
|
|
536
|
+
*
|
|
527
537
|
* @defaultValue "./core/streams/zlib-wasm/zlib-streams.wasm"
|
|
528
538
|
*/
|
|
529
|
-
wasmURI?: string;
|
|
539
|
+
wasmURI?: string | (() => string);
|
|
530
540
|
/**
|
|
531
541
|
* The size of the chunks in bytes during data compression/decompression.
|
|
532
542
|
*
|
|
@@ -572,6 +582,13 @@ export interface Configuration extends WorkerConfiguration {
|
|
|
572
582
|
|
|
573
583
|
/**
|
|
574
584
|
* Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link FileEntry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
|
|
585
|
+
*
|
|
586
|
+
* @remarks
|
|
587
|
+
* The three options below are read as truthy values, they are not converted. Any non-empty string is therefore
|
|
588
|
+
* `true`, `"false"` and `"0"` included. This is deliberate, so that an expression such as
|
|
589
|
+
* `useWebWorkers: supported && enabled` keeps working, but it differs from the numeric options, which do accept
|
|
590
|
+
* the string a form control, a query string or an environment variable yields. A boolean read from one of those
|
|
591
|
+
* must be converted by the caller.
|
|
575
592
|
*/
|
|
576
593
|
export interface WorkerConfiguration {
|
|
577
594
|
/**
|
|
@@ -1095,6 +1112,9 @@ export interface WritableWriter {
|
|
|
1095
1112
|
* updated as the data is written, so a writer needing the value (e.g. to compute the offset of a
|
|
1096
1113
|
* disk) can read it. A value set before the first write is kept and used as the starting offset
|
|
1097
1114
|
* instead of being reset to 0.
|
|
1115
|
+
*
|
|
1116
|
+
* It must therefore be assignable, see {@link ERR_WRITER_SIZE_NOT_WRITABLE}: a getter with no setter
|
|
1117
|
+
* is rejected when the writer is passed, not once the first entry has been written.
|
|
1098
1118
|
*/
|
|
1099
1119
|
size?: number;
|
|
1100
1120
|
/**
|
|
@@ -1348,6 +1368,10 @@ export class ZipReaderStream<T> {
|
|
|
1348
1368
|
* @remarks The properties deposited on an entry while its data is read, i.e.
|
|
1349
1369
|
* {@link EntryMetaData#warnings} and {@link EntryMetaData#localDirectory}, are shared with the
|
|
1350
1370
|
* chunk, so they are readable on it once its `readable` property has been consumed.
|
|
1371
|
+
*
|
|
1372
|
+
* An entry is decompressed on demand, when its `readable` property starts being read, so a chunk
|
|
1373
|
+
* whose data is never read costs nothing and skipping entries is free. Cancelling this stream
|
|
1374
|
+
* releases the entry being read, cancels the source and closes the underlying {@link ZipReader}.
|
|
1351
1375
|
*/
|
|
1352
1376
|
readable: ReadableStream<
|
|
1353
1377
|
Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
|
|
@@ -1479,6 +1503,8 @@ export class ZipReader<Type> {
|
|
|
1479
1503
|
* one of them and the evidence is already in hand, the same reason string is deposited as a warning instead —
|
|
1480
1504
|
* {@link WARNING_APPENDED_DATA}, {@link WARNING_PREPENDED_DATA}, {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA},
|
|
1481
1505
|
* {@link WARNING_DUPLICATE_FILENAME} and {@link WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY}.
|
|
1506
|
+
* {@link WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY} is the one reason of that group which is never tolerated,
|
|
1507
|
+
* so it is only ever the reason of an error.
|
|
1482
1508
|
*
|
|
1483
1509
|
* The warnings related to the local file header of an entry are deposited on
|
|
1484
1510
|
* {@link EntryMetaData#warnings} when its data is read, not here.
|
|
@@ -1510,6 +1536,16 @@ export class ZipReader<Type> {
|
|
|
1510
1536
|
* {@link ZipReader#getEntries} can therefore still be read after calling it.
|
|
1511
1537
|
*/
|
|
1512
1538
|
close(): Promise<void>;
|
|
1539
|
+
/**
|
|
1540
|
+
* Calls {@link ZipReader#close}, making the instance usable with `await using`
|
|
1541
|
+
*
|
|
1542
|
+
* @remarks
|
|
1543
|
+
* The method is only defined when the runtime provides `Symbol.asyncDispose`. Its declaration is
|
|
1544
|
+
* ignored by TypeScript versions that do not declare the symbol either, i.e. before 5.2 or without
|
|
1545
|
+
* the `esnext.disposable` library, so that the declarations of the library keep compiling there.
|
|
1546
|
+
*/
|
|
1547
|
+
// @ts-ignore Symbol.asyncDispose is declared from TypeScript 5.2 with the esnext.disposable library
|
|
1548
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
1513
1549
|
}
|
|
1514
1550
|
|
|
1515
1551
|
/**
|
|
@@ -1775,18 +1811,20 @@ export interface DirectoryEncryptionInfo {
|
|
|
1775
1811
|
export interface ZipReaderOptions {
|
|
1776
1812
|
/**
|
|
1777
1813
|
* How tolerant the reader should be when the local file header of an entry disagrees with its central
|
|
1778
|
-
* directory record.
|
|
1814
|
+
* directory record.
|
|
1779
1815
|
*
|
|
1780
1816
|
* - `"strict"`: compare the filename, the general purpose bit flag, the compression method, the CRC-32
|
|
1781
|
-
* checksum and the sizes.
|
|
1782
|
-
* - `"balanced"`: compare everything except the filename.
|
|
1783
|
-
* - `"tolerant"`: compare
|
|
1817
|
+
* checksum and the sizes, and throw an {@link ERR_AMBIGUOUS_ARCHIVE} error on any difference.
|
|
1818
|
+
* - `"balanced"`: compare everything except the filename, and throw on any difference.
|
|
1819
|
+
* - `"tolerant"`: compare everything except the filename, and deposit the differences on
|
|
1820
|
+
* {@link EntryMetaData#warnings} instead of throwing.
|
|
1784
1821
|
*
|
|
1785
1822
|
* Every field except the filename is read from the local file header anyway, to locate the entry data, so
|
|
1786
1823
|
* the comparison `"balanced"` performs reads no additional bytes. Comparing the filename reads the filename
|
|
1787
1824
|
* bytes as well, which costs one extra read per entry whenever the local file header carries no extra field
|
|
1788
|
-
* — the common case in practice
|
|
1789
|
-
* whole comparison explicitly
|
|
1825
|
+
* — the common case in practice, and the reason the filename is left out below `"strict"`. Use
|
|
1826
|
+
* {@link ZipReaderOptions#checkLocalDirectory} to request or suppress the whole comparison explicitly, and
|
|
1827
|
+
* {@link ZipReaderOptions#checkLocalFilename} to include or exclude the filename on its own.
|
|
1790
1828
|
*
|
|
1791
1829
|
* @defaultValue "balanced"
|
|
1792
1830
|
*/
|
|
@@ -1809,21 +1847,40 @@ export interface ZipReaderOptions {
|
|
|
1809
1847
|
*/
|
|
1810
1848
|
checkAmbiguity?: boolean;
|
|
1811
1849
|
/**
|
|
1812
|
-
* `true` to
|
|
1813
|
-
* {@link FileEntry#getData}, `false` to
|
|
1850
|
+
* `true` to reject the entry with an {@link ERR_AMBIGUOUS_ARCHIVE} error when its local file header
|
|
1851
|
+
* disagrees with its central directory record while calling {@link FileEntry#getData}, `false` to deposit
|
|
1852
|
+
* the differences on {@link EntryMetaData#warnings} instead. This is the entry-level half of
|
|
1814
1853
|
* {@link ZipReaderOptions#checkAmbiguity}, exposed on its own so it can be enabled without the archive-level
|
|
1815
1854
|
* checks and disabled without giving up the rest of {@link ZipReaderOptions#strictness}. It is the only way to
|
|
1816
1855
|
* validate the local file headers of a self-extracting archive, since
|
|
1817
1856
|
* {@link GetEntriesOptions#checkAmbiguity} rejects prepended data outright.
|
|
1818
1857
|
*
|
|
1819
1858
|
* `true` compares the filename as well, like {@link ZipReaderOptions#strictness} set to `"strict"`; `false`
|
|
1820
|
-
* compares
|
|
1821
|
-
*
|
|
1859
|
+
* compares everything except the filename, like `"tolerant"`. Set
|
|
1860
|
+
* {@link ZipReaderOptions#checkLocalFilename} to control the filename comparison on its own. An explicit
|
|
1861
|
+
* value takes precedence over the strictness default at every level.
|
|
1822
1862
|
*
|
|
1823
1863
|
* @defaultValue `true` when {@link ZipReaderOptions#strictness} is `"strict"` or `"balanced"`, `false` when
|
|
1824
1864
|
* it is `"tolerant"`.
|
|
1825
1865
|
*/
|
|
1826
1866
|
checkLocalDirectory?: boolean;
|
|
1867
|
+
/**
|
|
1868
|
+
* `true` to compare the filename of the local file header with the one of the central directory record when
|
|
1869
|
+
* calling {@link FileEntry#getData}, `false` to leave the filename out of that comparison.
|
|
1870
|
+
*
|
|
1871
|
+
* Comparing the filename costs one extra read per entry whenever the local file header carries no extra
|
|
1872
|
+
* field, which is why it is left out below {@link ZipReaderOptions#strictness} set to `"strict"`. This option
|
|
1873
|
+
* selects what is compared without changing whether a difference throws or warns, which
|
|
1874
|
+
* {@link ZipReaderOptions#checkLocalDirectory} decides. It is therefore the only way to obtain
|
|
1875
|
+
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME} as a warning, with
|
|
1876
|
+
* `{ checkLocalFilename: true, checkLocalDirectory: false }`, and the only way to keep every other check of
|
|
1877
|
+
* `"strict"` without paying the extra read, with `{ checkLocalFilename: false, strictness: "strict" }`.
|
|
1878
|
+
*
|
|
1879
|
+
* @defaultValue the value of {@link ZipReaderOptions#checkLocalDirectory} when it is set, otherwise `true`
|
|
1880
|
+
* when {@link ZipReaderOptions#strictness} is `"strict"` and `false` when it is `"balanced"` or
|
|
1881
|
+
* `"tolerant"`.
|
|
1882
|
+
*/
|
|
1883
|
+
checkLocalFilename?: boolean;
|
|
1827
1884
|
/**
|
|
1828
1885
|
* `true` to check only if the password is valid.
|
|
1829
1886
|
*
|
|
@@ -1875,9 +1932,31 @@ export interface ZipReaderOptions {
|
|
|
1875
1932
|
*/
|
|
1876
1933
|
password?: string;
|
|
1877
1934
|
/**
|
|
1878
|
-
* `true` to read the data as-is without decompressing it and without decrypting it
|
|
1935
|
+
* `true` to read the data as-is without decompressing it and without decrypting it, `"compressed"` to decrypt
|
|
1936
|
+
* it without decompressing it.
|
|
1937
|
+
*
|
|
1938
|
+
* @remarks
|
|
1939
|
+
* The codecs run in a fixed order, the data is decrypted and then decompressed, so this option selects how
|
|
1940
|
+
* many of these two stages are skipped rather than which one. `"compressed"` therefore returns the data of the
|
|
1941
|
+
* entry still compressed but no longer encrypted, and it is the only way to obtain it: the value `true` returns
|
|
1942
|
+
* the stored bytes, which are still encrypted, and an unset value returns the content itself. Reading an entry
|
|
1943
|
+
* which is not encrypted gives the same result with `true` and with `"compressed"`.
|
|
1944
|
+
*
|
|
1945
|
+
* Since the encryption is undone, `"compressed"` needs the {@link ZipReaderOptions#password} option and
|
|
1946
|
+
* throws an {@link ERR_INVALID_PASSWORD} error when it is wrong, whereas `true` never looks at the password.
|
|
1947
|
+
* The {@link ZipReaderOptions#checkAuthenticationCode} option applies as well. The
|
|
1948
|
+
* {@link ZipReaderOptions#checkCrc32} option does not, since the CRC32 of the entry describes its
|
|
1949
|
+
* content and the content is not decompressed.
|
|
1950
|
+
*
|
|
1951
|
+
* Two entries holding the same content encrypted with two different passwords have no bytes in common when
|
|
1952
|
+
* they are read with `true`, because the salt is drawn per entry. Read with `"compressed"` they are identical,
|
|
1953
|
+
* which is what makes it possible to compare the content of encrypted entries without decompressing them.
|
|
1954
|
+
*
|
|
1955
|
+
* A value which is neither a boolean, `"compressed"` nor unset throws an {@link ERR_INVALID_PASS_THROUGH_VALUE}
|
|
1956
|
+
* error. The filesystem API copies entries verbatim and only accepts a boolean, see
|
|
1957
|
+
* {@link ERR_UNSUPPORTED_PASS_THROUGH_VALUE}.
|
|
1879
1958
|
*/
|
|
1880
|
-
passThrough?: boolean;
|
|
1959
|
+
passThrough?: boolean | "compressed";
|
|
1881
1960
|
/**
|
|
1882
1961
|
* The password used to encrypt the content of the entry (raw).
|
|
1883
1962
|
*/
|
|
@@ -2189,9 +2268,11 @@ export interface LocalDirectory {
|
|
|
2189
2268
|
* The filename of the entry stored in the local file header (raw), which is allowed to differ from
|
|
2190
2269
|
* {@link EntryMetaData#rawFilename}.
|
|
2191
2270
|
*
|
|
2192
|
-
* Only defined when the local filename has been read, i.e. when the {@link ZipReaderOptions#
|
|
2193
|
-
* is set to `
|
|
2194
|
-
*
|
|
2271
|
+
* Only defined when the local filename has been read, i.e. when the {@link ZipReaderOptions#checkLocalFilename}
|
|
2272
|
+
* option is set to `true`, or is unset and either the {@link ZipReaderOptions#strictness} option is set to
|
|
2273
|
+
* `"strict"` or the {@link ZipReaderOptions#checkLocalDirectory} option is set to `true`. Setting
|
|
2274
|
+
* `checkLocalFilename` to `false` suppresses the read whatever the other two say, since reading it costs one
|
|
2275
|
+
* read the central directory does not need.
|
|
2195
2276
|
*/
|
|
2196
2277
|
rawFilename?: Uint8Array;
|
|
2197
2278
|
/**
|
|
@@ -2280,6 +2361,19 @@ export interface EntryError extends Error {
|
|
|
2280
2361
|
* `true` if the zip file is corrupted because the entry data could not be written entirely.
|
|
2281
2362
|
*/
|
|
2282
2363
|
corruptedEntry?: boolean;
|
|
2364
|
+
/**
|
|
2365
|
+
* The number of bytes of the entry that reached the writer before the failure, set whenever a
|
|
2366
|
+
* compression or decompression stream fails, i.e. on a corrupt entry, an invalid CRC32, a reader
|
|
2367
|
+
* erroring mid-entry or an aborted signal.
|
|
2368
|
+
*
|
|
2369
|
+
* @remarks
|
|
2370
|
+
* It is the counterpart of {@link EntryError#corruptedEntry}: the first says the entry is
|
|
2371
|
+
* incomplete, this one says how much of it was written. zip.js reads it itself to keep the offsets
|
|
2372
|
+
* of the entries written after the failed one correct, which is what makes the salvage described in
|
|
2373
|
+
* {@link ZipWriter#close} possible, so it counts the bytes the writer actually received rather than
|
|
2374
|
+
* the bytes the codec produced.
|
|
2375
|
+
*/
|
|
2376
|
+
outputSize?: number;
|
|
2283
2377
|
/**
|
|
2284
2378
|
* The entry whose data overlaps the data of the entry being read, set on the
|
|
2285
2379
|
* {@link ERR_OVERLAPPING_ENTRY} error raised by {@link ZipReaderOptions#checkOverlappingEntry}.
|
|
@@ -2625,14 +2719,18 @@ export interface EntryMetaData {
|
|
|
2625
2719
|
* disabled, e.g. with `strictness: "tolerant"` — the local file header mismatches the enabled check rejects
|
|
2626
2720
|
* with {@link ERR_AMBIGUOUS_ARCHIVE}: {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG},
|
|
2627
2721
|
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD} and
|
|
2628
|
-
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES}
|
|
2629
|
-
* {@link
|
|
2722
|
+
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES}, plus
|
|
2723
|
+
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME} when
|
|
2724
|
+
* {@link ZipReaderOptions#checkLocalFilename} is enabled on its own, since disabling
|
|
2725
|
+
* {@link ZipReaderOptions#checkLocalDirectory} leaves the filename out of the comparison. The archive-level
|
|
2726
|
+
* warnings are deposited on {@link ZipReader#warnings} instead.
|
|
2630
2727
|
*/
|
|
2631
2728
|
warnings?: ArchiveWarning[];
|
|
2632
2729
|
}
|
|
2633
2730
|
|
|
2634
2731
|
/**
|
|
2635
|
-
* Represents a non-fatal diagnostic deposited on {@link ZipReader#warnings}
|
|
2732
|
+
* Represents a non-fatal diagnostic deposited on {@link ZipReader#warnings}, {@link EntryMetaData#warnings} or
|
|
2733
|
+
* {@link ZipWriter#warnings}.
|
|
2636
2734
|
*/
|
|
2637
2735
|
export interface ArchiveWarning {
|
|
2638
2736
|
/**
|
|
@@ -2853,6 +2951,20 @@ export class ZipWriter<Type> {
|
|
|
2853
2951
|
* `true` if the zip contains at least one entry that has been partially written.
|
|
2854
2952
|
*/
|
|
2855
2953
|
readonly hasCorruptedEntries?: boolean;
|
|
2954
|
+
/**
|
|
2955
|
+
* The non-fatal diagnostics deposited while writing the entries, accumulated over the life of the instance.
|
|
2956
|
+
*
|
|
2957
|
+
* @remarks
|
|
2958
|
+
* A warning reports an adjustment the writer made silently rather than failing, so what it produced is not
|
|
2959
|
+
* what was asked for: {@link WARNING_COMPRESSION_UNAVAILABLE} when no deflate codec is available and the
|
|
2960
|
+
* entries are stored instead, and {@link WARNING_CLAMPED_LAST_MODIFICATION_DATE} when a date outside the
|
|
2961
|
+
* MS-DOS range is written and no extra field carries the original value.
|
|
2962
|
+
*
|
|
2963
|
+
* Each reason is deposited once, with the filename of the first entry it applied to, so an archive whose
|
|
2964
|
+
* entries are all affected reports one warning rather than one per entry. Read it after the entries have been
|
|
2965
|
+
* added; {@link ZipWriter#close} deposits none of its own.
|
|
2966
|
+
*/
|
|
2967
|
+
warnings?: ArchiveWarning[];
|
|
2856
2968
|
|
|
2857
2969
|
/**
|
|
2858
2970
|
* Adds the entries of an existing zip file into the current zip. This method can be called at any
|
|
@@ -2919,7 +3031,10 @@ export class ZipWriter<Type> {
|
|
|
2919
3031
|
* particular, Windows path separators ("\\") are not converted and become part of the filename,
|
|
2920
3032
|
* which is interpreted inconsistently by zip tools, and leading or trailing whitespace is
|
|
2921
3033
|
* preserved, which Windows filesystems cannot represent at the end of a name.
|
|
2922
|
-
* @param reader The
|
|
3034
|
+
* @param reader The {@link Reader} instance used to read the content of the entry. It can be
|
|
3035
|
+
* omitted, or passed as `undefined` or `null`, to write an entry with no content: a directory, or
|
|
3036
|
+
* an empty file. The two spellings are equivalent; `null` is the convenient one when the value
|
|
3037
|
+
* comes from a conditional expression, as in a loop copying entries where directories have no data.
|
|
2923
3038
|
* @param options The options.
|
|
2924
3039
|
* @returns A promise resolving to an {@link EntryMetaData} instance.
|
|
2925
3040
|
*/
|
|
@@ -2931,7 +3046,8 @@ export class ZipWriter<Type> {
|
|
|
2931
3046
|
| ReadableStream
|
|
2932
3047
|
| Reader<unknown>[]
|
|
2933
3048
|
| ReadableReader[]
|
|
2934
|
-
| ReadableStream[]
|
|
3049
|
+
| ReadableStream[]
|
|
3050
|
+
| null,
|
|
2935
3051
|
options?: ZipWriterAddDataOptions
|
|
2936
3052
|
): Promise<EntryMetaData>;
|
|
2937
3053
|
|
|
@@ -2959,11 +3075,29 @@ export class ZipWriter<Type> {
|
|
|
2959
3075
|
* counts as reporting them: catching the error of this method and calling it again finalizes the
|
|
2960
3076
|
* zip file without the failed entries.
|
|
2961
3077
|
*
|
|
3078
|
+
* Once the zip file has been finalized, calling this method again does nothing and returns the same
|
|
3079
|
+
* content. Only a call that threw can be retried, which is what makes the salvage above possible.
|
|
3080
|
+
*
|
|
2962
3081
|
* @param comment The global comment of the zip file.
|
|
2963
3082
|
* @param options The options.
|
|
2964
3083
|
* @returns The content of the zip file.
|
|
2965
3084
|
*/
|
|
2966
3085
|
close(comment?: Uint8Array, options?: ZipWriterCloseOptions): Promise<Type>;
|
|
3086
|
+
/**
|
|
3087
|
+
* Calls {@link ZipWriter#close}, making the instance usable with `await using`
|
|
3088
|
+
*
|
|
3089
|
+
* @remarks
|
|
3090
|
+
* The zip file is therefore finalized when the block is left, including when it is left by an
|
|
3091
|
+
* error: the entries written until then are readable, like the ones a salvaging
|
|
3092
|
+
* {@link ZipWriter#close} keeps. Closing the instance explicitly to collect its content stays the
|
|
3093
|
+
* common case, and the disposal that follows does nothing.
|
|
3094
|
+
*
|
|
3095
|
+
* The method is only defined when the runtime provides `Symbol.asyncDispose`. Its declaration is
|
|
3096
|
+
* ignored by TypeScript versions that do not declare the symbol either, i.e. before 5.2 or without
|
|
3097
|
+
* the `esnext.disposable` library, so that the declarations of the library keep compiling there.
|
|
3098
|
+
*/
|
|
3099
|
+
// @ts-ignore Symbol.asyncDispose is declared from TypeScript 5.2 with the esnext.disposable library
|
|
3100
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
2967
3101
|
}
|
|
2968
3102
|
|
|
2969
3103
|
/**
|
|
@@ -3009,23 +3143,72 @@ export interface ZipWriterAddDataOptions
|
|
|
3009
3143
|
*/
|
|
3010
3144
|
centralExtraField?: Map<number, Uint8Array>;
|
|
3011
3145
|
/**
|
|
3012
|
-
* The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is
|
|
3146
|
+
* The uncompressed size of the entry. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is unset
|
|
3147
|
+
* or `false`. It is required when it is set to `true` or to `"compressed"`, since the size cannot be derived from data which is not
|
|
3148
|
+
* decompressed.
|
|
3013
3149
|
*/
|
|
3014
3150
|
uncompressedSize?: number;
|
|
3015
3151
|
/**
|
|
3016
|
-
* The CRC-32 checksum of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is
|
|
3152
|
+
* The CRC-32 checksum of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option is unset
|
|
3153
|
+
* or `false`, and it is the caller's to supply otherwise, since the checksum cannot be computed from data which is not decompressed.
|
|
3017
3154
|
*
|
|
3018
|
-
* When the entry is AES-encrypted
|
|
3019
|
-
*
|
|
3020
|
-
* {@link
|
|
3155
|
+
* When the entry is AES-encrypted, this option is only stored when the encryption stage is passed through too, i.e. when
|
|
3156
|
+
* {@link ZipWriterConstructorOptions#passThrough} is set to `true` and the data is copied verbatim from an archive which already
|
|
3157
|
+
* published the checksum (see {@link ZipWriterConstructorOptions#encrypted}). The entry is then marked as AE-1. When the option is
|
|
3158
|
+
* set to `"compressed"` the writer performs the encryption itself, so storing the checksum of the content would disclose what that
|
|
3159
|
+
* encryption hides: the option is ignored, the entry is marked as AE-2 and the checksum fields are set to 0. See the remarks of
|
|
3160
|
+
* {@link ZipWriterConstructorOptions#password}.
|
|
3021
3161
|
*/
|
|
3022
3162
|
crc32?: number;
|
|
3023
3163
|
/**
|
|
3024
|
-
* The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option
|
|
3164
|
+
* The signature (CRC32 checksum) of the content. This option is ignored if the {@link ZipWriterConstructorOptions#passThrough} option
|
|
3165
|
+
* is unset or `false`.
|
|
3025
3166
|
*
|
|
3026
3167
|
* @deprecated Use {@link ZipWriterAddDataOptions#crc32} instead.
|
|
3027
3168
|
*/
|
|
3028
3169
|
signature?: number;
|
|
3170
|
+
/**
|
|
3171
|
+
* The entry the data comes from, e.g. one returned by {@link ZipReader#getEntries}, used as a source of default values for the
|
|
3172
|
+
* options describing it.
|
|
3173
|
+
*
|
|
3174
|
+
* @remarks
|
|
3175
|
+
* Copying an entry from one zip file into another needs about ten options forwarded, and forwarding a subset of them corrupts the
|
|
3176
|
+
* copy silently rather than throwing: the writer cannot tell that {@link EntryMetaData#compressionMethod} describes data it is
|
|
3177
|
+
* about to store verbatim. This option hands it the entry instead, and the options describing that entry are read from it.
|
|
3178
|
+
*
|
|
3179
|
+
* {@link EntryMetaData#externalFileAttributes}, {@link EntryMetaData#versionMadeBy}, {@link EntryMetaData#comment},
|
|
3180
|
+
* {@link EntryMetaData#lastModDate}, {@link EntryMetaData#creationDate}, {@link EntryMetaData#lastAccessDate},
|
|
3181
|
+
* {@link EntryMetaData#internalFileAttributes}, {@link DirectoryEntry#directory}, {@link EntryMetaData#uid},
|
|
3182
|
+
* {@link EntryMetaData#gid} and the extra fields of the entry which zip.js does not interpret itself are always read from it.
|
|
3183
|
+
*
|
|
3184
|
+
* {@link ZipWriterAddDataOptions#uncompressedSize}, {@link ZipWriterAddDataOptions#crc32},
|
|
3185
|
+
* {@link EntryMetaData#compressionMethod}, {@link ZipWriterConstructorOptions#dataDescriptor} and
|
|
3186
|
+
* {@link ZipWriterConstructorOptions#rawLastModDate} are read from it as well when the
|
|
3187
|
+
* {@link ZipWriterConstructorOptions#passThrough} option is set, since the data is then stored as it is read.
|
|
3188
|
+
* {@link ZipWriterConstructorOptions#encrypted}, {@link ZipWriterConstructorOptions#zipCrypto} and
|
|
3189
|
+
* {@link ZipWriterConstructorOptions#encryptionStrength} are only read from it when that option is set to `true`, i.e. when the
|
|
3190
|
+
* encryption stage is passed through too: with `"compressed"` the writer performs the encryption itself and the scheme is the
|
|
3191
|
+
* caller's to choose, so carrying the scheme of the source over would rekey an entry into the very scheme it was read from.
|
|
3192
|
+
*
|
|
3193
|
+
* Every value read from the entry is a default against the options of the same {@link ZipWriter#add} call: an option written
|
|
3194
|
+
* next to it wins. Against the options the {@link ZipWriter} was constructed with the precedence is the other way round, since
|
|
3195
|
+
* the values read from the entry are merged into the options of the call, so a date pinned on the writer does not normalize a
|
|
3196
|
+
* copied entry. Note that {@link ZipDirectoryEntry#exportZip} resolves the same conflict the opposite way, an export option
|
|
3197
|
+
* overriding the metadata of an imported entry. The filename is not one of these values, it stays the
|
|
3198
|
+
* first argument of {@link ZipWriter#add}, so an entry can be copied under another name.
|
|
3199
|
+
*
|
|
3200
|
+
* {@link ZipWriterConstructorOptions#encrypted} is one of the values read from the entry, so copying an encrypted entry with
|
|
3201
|
+
* `passThrough` set to `true` takes the branch documented on that option: the ciphertext is written as-is and keeps the
|
|
3202
|
+
* password it was encrypted with, while a {@link ZipWriterConstructorOptions#password} in scope encrypts the other entries
|
|
3203
|
+
* only. Re-keying an entry is what `passThrough` set to `"compressed"` is for, since the encryption stage runs there.
|
|
3204
|
+
*
|
|
3205
|
+
* A value which is not an object throws an {@link ERR_INVALID_ENTRY} error, and changing the
|
|
3206
|
+
* {@link ZipWriterConstructorOptions#lastModDate} of an entry encrypted with ZipCrypto throws an
|
|
3207
|
+
* {@link ERR_ZIP_CRYPTO_LAST_MOD_DATE} error when the encryption stage is passed through as well, i.e. when
|
|
3208
|
+
* {@link ZipWriterConstructorOptions#passThrough} is `true` rather than `"compressed"`. Under `"compressed"` the
|
|
3209
|
+
* entry is encrypted again, or not encrypted at all, so the date is free to change. See the remarks of that option.
|
|
3210
|
+
*/
|
|
3211
|
+
entry?: Entry;
|
|
3029
3212
|
}
|
|
3030
3213
|
|
|
3031
3214
|
/**
|
|
@@ -3094,9 +3277,13 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
3094
3277
|
*
|
|
3095
3278
|
* When no deflate implementation is available at all, i.e. the environment provides no usable
|
|
3096
3279
|
* `CompressionStream` and the embedded implementation cannot be loaded, the entry is stored
|
|
3097
|
-
* instead of being compressed rather than failing. The
|
|
3098
|
-
* the entry returned by {@link ZipWriter#add} is `0
|
|
3099
|
-
*
|
|
3280
|
+
* instead of being compressed rather than failing. The fallback is reported twice: the
|
|
3281
|
+
* {@link EntryMetaData#compressionMethod} of the entry returned by {@link ZipWriter#add} is `0`,
|
|
3282
|
+
* and {@link WARNING_COMPRESSION_UNAVAILABLE} is deposited on {@link ZipWriter#warnings}.
|
|
3283
|
+
*
|
|
3284
|
+
* When the {@link ZipWriterConstructorOptions#passThrough} option passes the compression stage through,
|
|
3285
|
+
* nothing is compressed and this option declares the level bits of the general purpose bit flag instead,
|
|
3286
|
+
* see the remarks of that option.
|
|
3100
3287
|
*
|
|
3101
3288
|
* @defaultValue 6
|
|
3102
3289
|
*/
|
|
@@ -3214,6 +3401,14 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
3214
3401
|
*
|
|
3215
3402
|
* When set to `false`, the maximum last modification date cannot exceed December 31, 2107 and the maximum accuracy is 2 seconds, dates being truncated to the whole second and odd seconds rounded up to the next even second.
|
|
3216
3403
|
*
|
|
3404
|
+
* @remarks Some zip-based formats forbid any extra field on a specific entry, which the default value of this
|
|
3405
|
+
* option would write. OpenDocument requires its `mimetype` entry to come first, to be stored without compression
|
|
3406
|
+
* and to carry no extra field, so a conformant ODF package needs both this option set to `false` and
|
|
3407
|
+
* {@link ZipWriterConstructorOptions#level} set to `0` on that entry. EPUB asks for the same pair: OCF states
|
|
3408
|
+
* that the `mimetype` file must not be compressed or encrypted and that there must not be an extra field in its
|
|
3409
|
+
* ZIP header, which is what pins the byte offset of `application/epub+zip` so a reader can sniff the format
|
|
3410
|
+
* without parsing the archive, and epubcheck reports an extra field there as an error.
|
|
3411
|
+
*
|
|
3217
3412
|
* @defaultValue true
|
|
3218
3413
|
*/
|
|
3219
3414
|
extendedTimestamp?: boolean;
|
|
@@ -3263,15 +3458,24 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
3263
3458
|
* `true` to mark the file names as UTF-8 setting the general purpose bit 11 in the header (see Appendix D -
|
|
3264
3459
|
* Language Encoding (EFS)), `false` to mark the names as compliant with the original IBM Code Page 437.
|
|
3265
3460
|
*
|
|
3266
|
-
*
|
|
3267
|
-
*
|
|
3461
|
+
* By default the flag is derived from the content: it is set when the encoded name or the encoded comment
|
|
3462
|
+
* of the entry holds a byte outside printable ASCII, and cleared otherwise. Printable ASCII is spelled
|
|
3463
|
+
* identically in UTF-8 and in Code Page 437, so the flag carries no information there, and every other
|
|
3464
|
+
* writer decides it the same way. A control character is not printable ASCII: Code Page 437 maps the bytes
|
|
3465
|
+
* 0x01 to 0x1f and the byte 0x7f to the IBM graphic characters rather than to the control characters
|
|
3466
|
+
* themselves, so a name or a comment holding one of them keeps the flag and stays readable. The comment is
|
|
3467
|
+
* part of the test because the flag announces its encoding too, so deriving from the name alone would
|
|
3468
|
+
* mislabel an ASCII name carrying a comment written in another language.
|
|
3469
|
+
*
|
|
3470
|
+
* Note that setting this option only sets the flag, it does not ensure that the file names are in the
|
|
3471
|
+
* correct encoding: when it is set to `false`, the names are still encoded in UTF-8 unless the
|
|
3268
3472
|
* {@link ZipWriterConstructorOptions#encodeText} option is also set to encode them in the intended code page.
|
|
3269
3473
|
* Setting it to `false` alone therefore produces an archive whose file names are mislabeled, holding UTF-8
|
|
3270
3474
|
* bytes announced as Code Page 437: the names holding characters outside of ASCII are decoded incorrectly
|
|
3271
3475
|
* by the readers honoring the flag, including {@link ZipReader} unless
|
|
3272
3476
|
* {@link GetEntriesOptions#filenameEncoding} is set to `"utf-8"`.
|
|
3273
3477
|
*
|
|
3274
|
-
* @defaultValue true
|
|
3478
|
+
* @defaultValue `true` when the encoded name or comment holds a byte outside ASCII, `false` otherwise
|
|
3275
3479
|
*/
|
|
3276
3480
|
useUnicodeFileNames?: boolean;
|
|
3277
3481
|
/**
|
|
@@ -3426,20 +3630,49 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
3426
3630
|
*/
|
|
3427
3631
|
usdz?: boolean;
|
|
3428
3632
|
/**
|
|
3429
|
-
* `true` to write the data as-is without compressing it and without crypting it
|
|
3633
|
+
* `true` to write the data as-is without compressing it and without crypting it, `"compressed"` to encrypt it
|
|
3634
|
+
* without compressing it.
|
|
3430
3635
|
*
|
|
3431
3636
|
* @remarks
|
|
3432
|
-
* The data is never compressed, so the {@link ZipWriterConstructorOptions#level} option
|
|
3433
|
-
*
|
|
3434
|
-
*
|
|
3435
|
-
*
|
|
3436
|
-
*
|
|
3637
|
+
* The data is never compressed, so the {@link ZipWriterConstructorOptions#level} option selects no codec, and
|
|
3638
|
+
* neither does the {@link ZipWriterAddDataOptions#compressionMethod} option: both describe how the data is
|
|
3639
|
+
* already compressed and are written as-is in the entry headers, the method in its own field and the level in
|
|
3640
|
+
* the level bits of the general purpose bit flag. The method must be set, otherwise an
|
|
3641
|
+
* {@link ERR_UNDEFINED_COMPRESSION_METHOD} error is thrown; the level is optional and leaves those bits unset.
|
|
3642
|
+
* The {@link ZipWriterAddDataOptions#crc32} option must be set as well, otherwise an {@link ERR_UNDEFINED_CRC32}
|
|
3643
|
+
* error is thrown, unless the entry is written as AES in AE-2 format, which stores no checksum.
|
|
3644
|
+
*
|
|
3645
|
+
* The level is read from the options of the entry only. A level set on the options of the writer applies to
|
|
3646
|
+
* the entries the writer compresses itself and is not inherited here, since it would describe data the writer
|
|
3647
|
+
* never produced. A stored entry carries no level bits either way, they describe a deflate stream.
|
|
3648
|
+
*
|
|
3649
|
+
* The entries with no content, e.g. the directories, ignore this option entirely. Setting the {@link ZipWriterConstructorOptions#password} or the
|
|
3437
3650
|
* {@link ZipWriterConstructorOptions#rawPassword} option throws an
|
|
3438
3651
|
* {@link ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH} error, unless the
|
|
3439
3652
|
* {@link ZipWriterConstructorOptions#encrypted} option is set to `true` to declare that the data is already
|
|
3440
3653
|
* encrypted. In that case the password encrypts the other entries only, and the data written as-is keeps the
|
|
3441
3654
|
* password it was encrypted with, which is not verified.
|
|
3442
3655
|
*
|
|
3656
|
+
* The codecs run in a fixed order, the data is compressed and then encrypted, so this option selects how many
|
|
3657
|
+
* of these two stages are skipped rather than which one. `"compressed"` declares that the data is already
|
|
3658
|
+
* compressed but not yet encrypted, so the compression stage is skipped and the encryption stage runs: it
|
|
3659
|
+
* encrypts an entry without recompressing it, which is what the `true` value cannot express and why it rejects
|
|
3660
|
+
* a password. The {@link ZipWriterAddDataOptions#uncompressedSize} and
|
|
3661
|
+
* {@link ZipWriterAddDataOptions#compressionMethod} options are still the caller's to declare, since neither
|
|
3662
|
+
* can be derived from data which is not decompressed.
|
|
3663
|
+
*
|
|
3664
|
+
* The CRC32 of the entry cannot be computed either, so the {@link ZipWriterAddDataOptions#crc32} option is
|
|
3665
|
+
* the caller's to declare as well. It is written as-is for an entry which is not AES-encrypted, i.e. for a
|
|
3666
|
+
* plain or a ZipCrypto entry, both of which store the checksum in clear anyway. It is dropped for an
|
|
3667
|
+
* AES-encrypted entry, which is marked AE-2 with the checksum fields set to 0: the encryption stage runs
|
|
3668
|
+
* here, so this is a new encryption, and a stored plaintext checksum would let an attacker verify guessed
|
|
3669
|
+
* content without knowing the password. Only the `true` value may mark an entry AE-1, and only because the
|
|
3670
|
+
* data is then copied verbatim from an archive which already published that checksum.
|
|
3671
|
+
*
|
|
3672
|
+
* A value which is neither a boolean, `"compressed"` nor unset throws an {@link ERR_INVALID_PASS_THROUGH_VALUE}
|
|
3673
|
+
* error. The filesystem API copies entries verbatim and only accepts a boolean, see
|
|
3674
|
+
* {@link ERR_UNSUPPORTED_PASS_THROUGH_VALUE}.
|
|
3675
|
+
*
|
|
3443
3676
|
* When the data was encrypted with ZipCrypto, the verification byte stored in the encrypted data depends on
|
|
3444
3677
|
* the last modification date of the source entry if the data descriptor is used. The
|
|
3445
3678
|
* {@link ZipWriterConstructorOptions#dataDescriptor} and {@link ZipWriterConstructorOptions#rawLastModDate}
|
|
@@ -3447,9 +3680,12 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
|
|
|
3447
3680
|
* {@link ERR_INVALID_PASSWORD} error. The filesystem API forwards them when exporting entries and throws an
|
|
3448
3681
|
* {@link ERR_ZIP_CRYPTO_LAST_MOD_DATE} error if the date is overridden.
|
|
3449
3682
|
*/
|
|
3450
|
-
passThrough?: boolean;
|
|
3683
|
+
passThrough?: boolean | "compressed";
|
|
3451
3684
|
/**
|
|
3452
3685
|
* `true` to write encrypted data when `passThrough` is set to `true`.
|
|
3686
|
+
*
|
|
3687
|
+
* @remarks It declares that the data is already encrypted, so it does not apply when `passThrough` is set to
|
|
3688
|
+
* `"compressed"`, which encrypts the data itself.
|
|
3453
3689
|
*/
|
|
3454
3690
|
encrypted?: boolean;
|
|
3455
3691
|
/**
|
|
@@ -4125,16 +4361,36 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
4125
4361
|
/**
|
|
4126
4362
|
* Creates a zip file via a custom {@link Writer} instance containing the entry and its descendants
|
|
4127
4363
|
*
|
|
4128
|
-
* @
|
|
4364
|
+
* @remarks A {@link ZipWriter} instance can be passed instead of a {@link Writer}, the symmetric
|
|
4365
|
+
* counterpart of passing a {@link ZipReader} to {@link ZipDirectoryEntry#importZip}. The entries are
|
|
4366
|
+
* added to that writer and the archive is left open, so the caller closes it with
|
|
4367
|
+
* {@link ZipWriter#close} and can add entries of its own before or after, export several trees into
|
|
4368
|
+
* one archive, and read {@link ZipWriter#warnings}, which is otherwise unreachable through the
|
|
4369
|
+
* filesystem API. The options of that writer keep governing the entries, exactly as they do for a
|
|
4370
|
+
* direct call to {@link ZipWriter#add}, and the options passed here take precedence over them. The
|
|
4371
|
+
* options that only apply when the writer is created are ignored. `bufferedWrite` is not one of
|
|
4372
|
+
* them, it is honored here as it is on {@link ZipWriter#add}; what differs is its default, which
|
|
4373
|
+
* the export sets to `true` only for a writer it creates itself. A supplied writer therefore
|
|
4374
|
+
* buffers only when the option is passed here or to its own constructor.
|
|
4375
|
+
*
|
|
4376
|
+
* The archive is closed by the caller, so everything that happens at close time is the caller's to pass to
|
|
4377
|
+
* {@link ZipWriter#close}, and passing it here instead does nothing. That covers
|
|
4378
|
+
* {@link ZipDirectoryEntryExportOptions#globalComment}, which is the first argument of that method, and
|
|
4379
|
+
* {@link ZipWriterCloseOptions#signCentralDirectory}, which is one of its options. Both describe the whole
|
|
4380
|
+
* archive rather than the exported tree, so an archive composed of several trees carries one of each,
|
|
4381
|
+
* written by the single {@link ZipWriter#close} call that finalizes it.
|
|
4382
|
+
*
|
|
4383
|
+
* @param writer The {@link Writer} instance, or the {@link ZipWriter} instance to add the entries to.
|
|
4129
4384
|
* @param options The options.
|
|
4130
|
-
* @returns A promise resolving to the data.
|
|
4385
|
+
* @returns A promise resolving to the data, or to the {@link ZipWriter} instance it was passed.
|
|
4131
4386
|
*/
|
|
4132
4387
|
exportZip(
|
|
4133
4388
|
writer:
|
|
4134
4389
|
| Writer<unknown>
|
|
4135
4390
|
| WritableWriter
|
|
4136
4391
|
| WritableStream
|
|
4137
|
-
| AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream
|
|
4392
|
+
| AsyncGenerator<Writer<unknown> | WritableWriter | WritableStream>
|
|
4393
|
+
| ZipWriter<unknown>,
|
|
4138
4394
|
options?: ZipDirectoryEntryExportOptions
|
|
4139
4395
|
): Promise<unknown>;
|
|
4140
4396
|
/**
|
|
@@ -4142,7 +4398,10 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
4142
4398
|
* and its descendants, without reading or compressing any data.
|
|
4143
4399
|
*
|
|
4144
4400
|
* Pass the same options object that will be passed to the export method, otherwise the result
|
|
4145
|
-
* will not match. The
|
|
4401
|
+
* will not match. The computation assumes the export creates the writer, where `bufferedWrite`
|
|
4402
|
+
* defaults to `true`; a {@link ZipWriter} passed to {@link ZipDirectoryEntry#exportZip} defaults
|
|
4403
|
+
* it to `false` instead, which adds a data descriptor to every entry, so pass the value that
|
|
4404
|
+
* writer uses here too. The size is only determinable when every descendant is stored (i.e. `level` is
|
|
4146
4405
|
* set to 0) or passed through, and has a known size; {@link ERR_UNDETERMINED_SIZE} is thrown
|
|
4147
4406
|
* otherwise. Encryption does not prevent it, the overhead of ZipCrypto and AES being fixed.
|
|
4148
4407
|
*
|
|
@@ -4155,13 +4414,20 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
4155
4414
|
* {@link ERR_UNDETERMINED_SIZE} is also thrown when the size depends on the order in which the
|
|
4156
4415
|
* entries are physically written, which the buffered write path only determines at write time.
|
|
4157
4416
|
* This happens when `usdz` is set, since the alignment padding depends on the offset of each
|
|
4158
|
-
* entry, and when the archive exceeds 4GB
|
|
4159
|
-
* are then extended to 64 bits.
|
|
4160
|
-
*
|
|
4161
|
-
*
|
|
4162
|
-
*
|
|
4417
|
+
* entry, and when the archive exceeds 4GB and the order could change the result, since the
|
|
4418
|
+
* offsets recorded in the central directory are then extended to 64 bits. Entries of equal size
|
|
4419
|
+
* put the same entries past 4GB whatever the order, so they stay determinable unless they differ
|
|
4420
|
+
* in whether they already carry a zip64 field, which changes the cost of crossing that boundary.
|
|
4421
|
+
* Passing `bufferedWrite: false` makes both determinable again, as does exporting a tree holding no
|
|
4422
|
+
* directory that was added explicitly and has children: the directories a name holding `"/"` creates are
|
|
4423
|
+
* exempt, so `addText("a/b.txt", text)` stays determinable, while `addDirectory("a")` followed by two
|
|
4424
|
+
* `addText` calls on it does not. It is thrown as well when
|
|
4163
4425
|
* `signCentralDirectory` is set, the length of the signature being unknown until it is computed.
|
|
4164
4426
|
*
|
|
4427
|
+
* An entry asking for compression is stored instead when no deflate implementation is reachable,
|
|
4428
|
+
* which is what the export writes as well. Its size is determinable then, so the same call throws
|
|
4429
|
+
* on a platform carrying deflate and returns a size on one that does not.
|
|
4430
|
+
*
|
|
4165
4431
|
* @param options The options.
|
|
4166
4432
|
* @returns A promise resolving to the size in bytes.
|
|
4167
4433
|
* @throws {@link ERR_UNDETERMINED_SIZE} if the size cannot be determined.
|
|
@@ -4173,7 +4439,15 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
4173
4439
|
* Represents the options passed to `{@link ZipDirectoryEntry}#import*()`.
|
|
4174
4440
|
*/
|
|
4175
4441
|
export interface ZipDirectoryEntryImportOptions
|
|
4176
|
-
extends ZipReaderConstructorOptions {
|
|
4442
|
+
extends Omit<ZipReaderConstructorOptions, "passThrough"> {
|
|
4443
|
+
/**
|
|
4444
|
+
* `true` to import the entries of the zip file as-is, without decompressing and decrypting them
|
|
4445
|
+
*
|
|
4446
|
+
* @remarks Only a boolean, where {@link ZipReaderOptions#passThrough} also takes `"compressed"`: the
|
|
4447
|
+
* filesystem copies each entry through a writer, which has nowhere to put content that is still
|
|
4448
|
+
* compressed. `"compressed"` throws an {@link ERR_UNSUPPORTED_PASS_THROUGH_VALUE} error.
|
|
4449
|
+
*/
|
|
4450
|
+
passThrough?: boolean;
|
|
4177
4451
|
/**
|
|
4178
4452
|
* The policy applied when two entries of the imported zip file claim the same node of the tree
|
|
4179
4453
|
*
|
|
@@ -4296,12 +4570,20 @@ export interface ZipDirectoryEntryExportOptions
|
|
|
4296
4570
|
* @remarks
|
|
4297
4571
|
* The {@link ZipWriterAddDataOptions#comment} option is the comment of an entry: setting it here
|
|
4298
4572
|
* comments every entry of the exported zip file instead of the zip file itself.
|
|
4573
|
+
*
|
|
4574
|
+
* Ignored by {@link ZipDirectoryEntry#exportZip} when it is given a {@link ZipWriter}, since the archive is
|
|
4575
|
+
* then closed by the caller: pass it to {@link ZipWriter#close} instead.
|
|
4299
4576
|
*/
|
|
4300
4577
|
globalComment?: Uint8Array;
|
|
4301
4578
|
/**
|
|
4302
4579
|
* The function called for signing the central directory, see
|
|
4303
4580
|
* {@link ZipWriterCloseOptions#signCentralDirectory}.
|
|
4304
4581
|
*
|
|
4582
|
+
* @remarks
|
|
4583
|
+
* Ignored by {@link ZipDirectoryEntry#exportZip} when it is given a {@link ZipWriter}, since the archive is
|
|
4584
|
+
* then closed by the caller: pass it to {@link ZipWriter#close} instead, which also keeps a single signature
|
|
4585
|
+
* over an archive composed of several exported trees.
|
|
4586
|
+
*
|
|
4305
4587
|
* @param directory The raw data of the central directory records.
|
|
4306
4588
|
* @returns The data of the digital signature record.
|
|
4307
4589
|
*/
|
|
@@ -4322,7 +4604,7 @@ export interface ZipDirectoryEntryExportOptions
|
|
|
4322
4604
|
*
|
|
4323
4605
|
* A value which is neither an object nor unset throws an {@link ERR_INVALID_READER_OPTIONS} error.
|
|
4324
4606
|
*/
|
|
4325
|
-
readerOptions?: ZipReaderConstructorOptions;
|
|
4607
|
+
readerOptions?: Omit<ZipReaderConstructorOptions, "passThrough"> & { passThrough?: boolean };
|
|
4326
4608
|
}
|
|
4327
4609
|
|
|
4328
4610
|
/**
|
|
@@ -4355,7 +4637,7 @@ export interface ZipDirectoryEntryExportFileSystemHandleOptions
|
|
|
4355
4637
|
*
|
|
4356
4638
|
* A value which is neither an object nor unset throws an {@link ERR_INVALID_READER_OPTIONS} error.
|
|
4357
4639
|
*/
|
|
4358
|
-
readerOptions?: ZipReaderConstructorOptions;
|
|
4640
|
+
readerOptions?: Omit<ZipReaderConstructorOptions, "passThrough"> & { passThrough?: boolean };
|
|
4359
4641
|
}
|
|
4360
4642
|
|
|
4361
4643
|
/**
|
|
@@ -4488,6 +4770,14 @@ export const fs: {
|
|
|
4488
4770
|
* HTTP range error
|
|
4489
4771
|
*/
|
|
4490
4772
|
export const ERR_HTTP_RANGE: string;
|
|
4773
|
+
/**
|
|
4774
|
+
* HTTP status error (thrown by {@link HttpReader} when the server answers with a status other than 2xx, except
|
|
4775
|
+
* 416, which throws {@link ERR_HTTP_RANGE} instead)
|
|
4776
|
+
*
|
|
4777
|
+
* @remarks This message is a prefix: the status text, or the status code when the server sends none, is
|
|
4778
|
+
* appended to it, so it is matched with `String#startsWith` rather than with an equality test.
|
|
4779
|
+
*/
|
|
4780
|
+
export const ERR_HTTP_STATUS: string;
|
|
4491
4781
|
/**
|
|
4492
4782
|
* HTTP resource changed while being read error
|
|
4493
4783
|
*/
|
|
@@ -4630,6 +4920,27 @@ export const ERR_INVALID_SIGNAL: string;
|
|
|
4630
4920
|
* {@link Configuration#useWebWorkers} set to `false` to compress and decompress data in the main thread instead.
|
|
4631
4921
|
*/
|
|
4632
4922
|
export const ERR_INVALID_MAX_WORKERS: string;
|
|
4923
|
+
/**
|
|
4924
|
+
* Invalid baseURI error
|
|
4925
|
+
*
|
|
4926
|
+
* @remarks
|
|
4927
|
+
* Thrown by {@link configure} when {@link Configuration#baseURI} is neither falsy nor a string. A `URL` object used to be
|
|
4928
|
+
* accepted here, because `new URL(uri, baseURI)` stringifies its base, and then failed much later with a `DataCloneError`
|
|
4929
|
+
* the first time a web worker ran, since the base URL is posted to it. Unlike {@link Configuration#workerURI} and
|
|
4930
|
+
* {@link Configuration#wasmURI}, it cannot be a function: it is resolved before any URI is.
|
|
4931
|
+
*/
|
|
4932
|
+
export const ERR_INVALID_BASE_URI: string;
|
|
4933
|
+
/**
|
|
4934
|
+
* Invalid URI error
|
|
4935
|
+
*
|
|
4936
|
+
* @remarks
|
|
4937
|
+
* Thrown by {@link configure} when {@link Configuration#workerURI} or {@link Configuration#wasmURI} is neither falsy, a string,
|
|
4938
|
+
* nor a function. A function is not called at that point, so what it returns is not validated here: one returning something
|
|
4939
|
+
* other than a string fails later and quietly, when loading the worker throws and the codecs fall back to the main thread.
|
|
4940
|
+
* A falsy value keeps meaning "no worker" and "no WebAssembly module", which is how the
|
|
4941
|
+
* entry points excluding them unset their URI.
|
|
4942
|
+
*/
|
|
4943
|
+
export const ERR_INVALID_URI: string;
|
|
4633
4944
|
/**
|
|
4634
4945
|
* Invalid version error
|
|
4635
4946
|
*/
|
|
@@ -4747,12 +5058,23 @@ export const ERR_UNDEFINED_UNCOMPRESSED_SIZE: string;
|
|
|
4747
5058
|
* Undefined compression method error
|
|
4748
5059
|
*/
|
|
4749
5060
|
export const ERR_UNDEFINED_COMPRESSION_METHOD: string;
|
|
5061
|
+
/**
|
|
5062
|
+
* Undefined CRC32 error (thrown by {@link ZipWriter#add} when the {@link ZipWriterConstructorOptions#passThrough}
|
|
5063
|
+
* option is set and the {@link ZipWriterAddDataOptions#crc32} option is unset on an entry which stores a checksum)
|
|
5064
|
+
*
|
|
5065
|
+
* @remarks The checksum cannot be computed from data which is not decompressed, and every entry stores one except
|
|
5066
|
+
* an AES entry in AE-2 format, so writing the data as-is without declaring it would store a zero which other tools
|
|
5067
|
+
* reject. Copying an entry read with the {@link ZipReaderOptions#passThrough} option set to `"compressed"` from an
|
|
5068
|
+
* AE-2 source into an entry which is not AES-encrypted is therefore refused rather than written: that source
|
|
5069
|
+
* published no checksum to carry over.
|
|
5070
|
+
*/
|
|
5071
|
+
export const ERR_UNDEFINED_CRC32: string;
|
|
4750
5072
|
export const ERR_UNDETERMINED_SIZE: string;
|
|
4751
5073
|
/**
|
|
4752
5074
|
* Undefined reader error
|
|
4753
5075
|
*
|
|
4754
5076
|
* @remarks Thrown when adding an entry with the {@link ZipWriterConstructorOptions#passThrough} option set to `true`
|
|
4755
|
-
* and no Reader instance: the headers of such an entry describe its content verbatim and would declare content that
|
|
5077
|
+
* or to `"compressed"` and no Reader instance: the headers of such an entry describe its content verbatim and would declare content that
|
|
4756
5078
|
* is not there. Directory entries are exempt, they have no content to write as-is.
|
|
4757
5079
|
*/
|
|
4758
5080
|
export const ERR_UNDEFINED_READER: string;
|
|
@@ -4769,6 +5091,15 @@ export const ERR_INVALID_READER: string;
|
|
|
4769
5091
|
* Writer not initialized error
|
|
4770
5092
|
*/
|
|
4771
5093
|
export const ERR_WRITER_NOT_INITIALIZED: string;
|
|
5094
|
+
/**
|
|
5095
|
+
* Invalid writer size error
|
|
5096
|
+
*
|
|
5097
|
+
* @remarks
|
|
5098
|
+
* Thrown when {@link WritableWriter#size} cannot be assigned, e.g. when it is a getter with no setter, a read-only
|
|
5099
|
+
* property or a frozen object. zip.js writes the number of bytes written into that property, so a writer refusing the
|
|
5100
|
+
* assignment used to fail with a bare `TypeError` from the engine, and only once the first entry had been written.
|
|
5101
|
+
*/
|
|
5102
|
+
export const ERR_WRITER_SIZE_NOT_WRITABLE: string;
|
|
4772
5103
|
/**
|
|
4773
5104
|
* Zip file not empty error
|
|
4774
5105
|
*/
|
|
@@ -4828,6 +5159,28 @@ export const ERR_INVALID_PASSWORD_TYPE: string;
|
|
|
4828
5159
|
* or set the {@link ZipWriterAddDataOptions#uncompressedSize} option of each entry holding compressed data.
|
|
4829
5160
|
*/
|
|
4830
5161
|
export const ERR_INVALID_PASS_THROUGH: string;
|
|
5162
|
+
/**
|
|
5163
|
+
* Invalid passThrough value error (thrown by {@link ZipReader#getEntries}, {@link FileEntry#getData} and
|
|
5164
|
+
* {@link ZipWriter#add} when the {@link ZipReaderOptions#passThrough} or the
|
|
5165
|
+
* {@link ZipWriterConstructorOptions#passThrough} option is neither a boolean, `"compressed"` nor unset)
|
|
5166
|
+
*
|
|
5167
|
+
* @remarks The option accepts a fixed set of values rather than any truthy one, because a misspelled string would
|
|
5168
|
+
* otherwise pass both codec stages through and produce an archive holding data which is not the data the caller
|
|
5169
|
+
* meant to write, with no error at any point.
|
|
5170
|
+
*/
|
|
5171
|
+
export const ERR_INVALID_PASS_THROUGH_VALUE: string;
|
|
5172
|
+
/**
|
|
5173
|
+
* Unsupported passThrough value error (thrown by {@link ZipDirectoryEntry#importZip} and by
|
|
5174
|
+
* `{@link ZipDirectoryEntry}#export*()` when the {@link ZipReaderOptions#passThrough} option is set to
|
|
5175
|
+
* `"compressed"`)
|
|
5176
|
+
*
|
|
5177
|
+
* @remarks The filesystem API copies the entries of an imported zip file verbatim, forwarding the encryption
|
|
5178
|
+
* metadata of each source entry to the Writer. Data which has been decrypted but not decompressed would be written
|
|
5179
|
+
* under that metadata, i.e. an archive whose entries are marked encrypted over content which is not, so the value
|
|
5180
|
+
* is refused rather than accepted and mishandled. Use {@link FileEntry#getData} and {@link ZipWriter#add} directly
|
|
5181
|
+
* to decrypt an entry without decompressing it.
|
|
5182
|
+
*/
|
|
5183
|
+
export const ERR_UNSUPPORTED_PASS_THROUGH_VALUE: string;
|
|
4831
5184
|
/**
|
|
4832
5185
|
* Invalid readerOptions error (thrown by `{@link ZipDirectoryEntry}#export*()`,
|
|
4833
5186
|
* {@link ZipDirectoryEntry#getExportedSize} and {@link ZipDirectoryEntry#exportFileSystemHandle} when the
|
|
@@ -4839,9 +5192,16 @@ export const ERR_INVALID_PASS_THROUGH: string;
|
|
|
4839
5192
|
*/
|
|
4840
5193
|
export const ERR_INVALID_READER_OPTIONS: string;
|
|
4841
5194
|
/**
|
|
4842
|
-
*
|
|
4843
|
-
*
|
|
4844
|
-
|
|
5195
|
+
* Invalid entry error (thrown by {@link ZipWriter#add} when the {@link ZipWriterAddDataOptions#entry} option is
|
|
5196
|
+
* neither an entry nor unset)
|
|
5197
|
+
*/
|
|
5198
|
+
export const ERR_INVALID_ENTRY: string;
|
|
5199
|
+
/**
|
|
5200
|
+
* Locked last modification date error (thrown by {@link ZipWriter#add} when the date of an entry encrypted with
|
|
5201
|
+
* ZipCrypto is changed while it is copied with the {@link ZipWriterConstructorOptions#passThrough} option set, and
|
|
5202
|
+
* by `{@link ZipDirectoryEntry}#export*()` and {@link ZipDirectoryEntry#getExportedSize} when the date of such an
|
|
5203
|
+
* entry exported with {@link ZipReaderOptions#passThrough} set in
|
|
5204
|
+
* {@link ZipDirectoryEntryExportOptions#readerOptions} is changed)
|
|
4845
5205
|
*
|
|
4846
5206
|
* @remarks The ZipCrypto encryption header embeds a password verification byte derived from the time of the
|
|
4847
5207
|
* entry: the encrypted data, copied as-is, only decrypts when the time in the rewritten headers still matches.
|
|
@@ -4868,8 +5228,28 @@ export const ERR_INVALID_DUPLICATES: string;
|
|
|
4868
5228
|
*/
|
|
4869
5229
|
export const ERR_READABLE_CONSUMED: string;
|
|
4870
5230
|
/**
|
|
4871
|
-
*
|
|
4872
|
-
*
|
|
5231
|
+
* Ancestor entry error (thrown by {@link ZipFS#move} and {@link ZipEntry#rename} when the destination is the
|
|
5232
|
+
* moved entry itself or one of its descendants, which would detach the moved subtree from the tree)
|
|
5233
|
+
*/
|
|
5234
|
+
export const ERR_ANCESTOR_ENTRY: string;
|
|
5235
|
+
/**
|
|
5236
|
+
* Root directory move error (thrown by {@link ZipFS#move} when the entry being moved is the root of the
|
|
5237
|
+
* filesystem, which has no parent to be detached from)
|
|
5238
|
+
*/
|
|
5239
|
+
export const ERR_ROOT_DIRECTORY_NOT_MOVABLE: string;
|
|
5240
|
+
/**
|
|
5241
|
+
* Target entry not a directory error (thrown by {@link ZipFS#move} when the destination entry is a file)
|
|
5242
|
+
*/
|
|
5243
|
+
export const ERR_TARGET_NOT_DIRECTORY: string;
|
|
5244
|
+
/**
|
|
5245
|
+
* Parent entry not a directory error (thrown by the `add*()` methods of {@link ZipDirectoryEntry} when they are
|
|
5246
|
+
* called on an entry that is not a directory)
|
|
5247
|
+
*/
|
|
5248
|
+
export const ERR_PARENT_NOT_DIRECTORY: string;
|
|
5249
|
+
/**
|
|
5250
|
+
* Aborted operation error (thrown by {@link FileEntry#getData}, {@link ZipWriter#add} and
|
|
5251
|
+
* {@link ZipDirectoryEntry#exportFileSystemHandle} when they are aborted via {@link ZipReaderOptions#signal} or
|
|
5252
|
+
* {@link ZipWriterAddDataOptions#signal} on platforms which do not support the `reason` argument of
|
|
4873
5253
|
* `AbortController#abort()`)
|
|
4874
5254
|
*
|
|
4875
5255
|
* @remarks The reason passed by the caller is discarded by these platforms and cannot be recovered, so a
|
|
@@ -4957,6 +5337,19 @@ export const WARNING_DUPLICATE_FILENAME: string;
|
|
|
4957
5337
|
* both (see {@link ZipReader#warnings}); the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
|
|
4958
5338
|
*/
|
|
4959
5339
|
export const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: string;
|
|
5340
|
+
/**
|
|
5341
|
+
* Warning reason: more than one end of central directory record reaches the end of the file, so another reader
|
|
5342
|
+
* may select a different one and list different entries; the reason of {@link ERR_AMBIGUOUS_ARCHIVE} when
|
|
5343
|
+
* {@link ZipReaderOptions#checkAmbiguity} is enabled
|
|
5344
|
+
*/
|
|
5345
|
+
export const WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY: string;
|
|
5346
|
+
/**
|
|
5347
|
+
* Warning reason: the filename of the local file header contradicts the central directory; the reason of
|
|
5348
|
+
* {@link ERR_AMBIGUOUS_ARCHIVE} when {@link ZipReaderOptions#checkLocalDirectory} is enabled, and deposited on
|
|
5349
|
+
* {@link EntryMetaData#warnings} when {@link ZipReaderOptions#checkLocalFilename} is enabled while
|
|
5350
|
+
* {@link ZipReaderOptions#checkLocalDirectory} is disabled
|
|
5351
|
+
*/
|
|
5352
|
+
export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_FILENAME: string;
|
|
4960
5353
|
/**
|
|
4961
5354
|
* Warning reason: the general purpose bit flag of the local file header contradicts the central directory
|
|
4962
5355
|
* (see {@link EntryMetaData#warnings}); the reason of {@link ERR_AMBIGUOUS_ARCHIVE} when
|
|
@@ -4975,3 +5368,19 @@ export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: string;
|
|
|
4975
5368
|
* {@link ZipReaderOptions#checkLocalDirectory} is enabled
|
|
4976
5369
|
*/
|
|
4977
5370
|
export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES: string;
|
|
5371
|
+
/**
|
|
5372
|
+
* Warning reason: no deflate codec is available, so the entry is stored instead of being compressed
|
|
5373
|
+
* (see {@link ZipWriter#warnings} and {@link EntryMetaData#compressionMethod})
|
|
5374
|
+
*/
|
|
5375
|
+
export const WARNING_COMPRESSION_UNAVAILABLE: string;
|
|
5376
|
+
/**
|
|
5377
|
+
* Warning reason: the last modification date is outside the range the MS-DOS field can hold, i.e. before 1980
|
|
5378
|
+
* or after 2107, and no extra field carries the original value, so the date written is the nearest bound
|
|
5379
|
+
* (see {@link ZipWriter#warnings} and {@link EntryMetaData#lastModDate})
|
|
5380
|
+
*
|
|
5381
|
+
* @remarks {@link ZipWriterConstructorOptions#extendedTimestamp} is enabled by default and preserves the
|
|
5382
|
+
* original value, so this reason only appears when no extra field is left to carry it: when it and
|
|
5383
|
+
* {@link ZipWriterConstructorOptions#ntfsTimestamp} are both disabled, and also when the date falls outside
|
|
5384
|
+
* the range an extended timestamp can hold, 1901-12-13 to 2038-01-19, and `ntfsTimestamp` alone is disabled.
|
|
5385
|
+
*/
|
|
5386
|
+
export const WARNING_CLAMPED_LAST_MODIFICATION_DATE: string;
|