@zip.js/zip.js 2.19.0 → 2.21.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/BENCHMARKS.md +154 -130
- package/deno.json +1 -1
- package/dist/zip-core-external.js +440 -225
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +441 -224
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +440 -225
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +441 -224
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +440 -225
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +441 -224
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +441 -224
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +441 -224
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +441 -224
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +441 -224
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +441 -224
- package/index-native.min.js +1 -1
- package/index.cjs +441 -224
- package/index.d.cts +117 -24
- package/index.d.ts +117 -24
- package/index.min.js +1 -1
- package/lib/core/constants.js +7 -0
- package/lib/core/version.js +1 -1
- package/lib/core/zip-reader.js +225 -76
- package/lib/core/zip-writer.js +214 -147
- package/lib/zip-core-reader.js +2 -0
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1543,9 +1543,13 @@ export class ZipReader<Type> {
|
|
|
1543
1543
|
* `strictness: "strict"` rejects with {@link ERR_AMBIGUOUS_ARCHIVE}: when the effective strictness tolerates
|
|
1544
1544
|
* one of them and the evidence is already in hand, the same reason string is deposited as a warning instead —
|
|
1545
1545
|
* {@link WARNING_APPENDED_DATA}, {@link WARNING_PREPENDED_DATA}, {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA},
|
|
1546
|
-
* {@link
|
|
1547
|
-
* {@link
|
|
1548
|
-
*
|
|
1546
|
+
* {@link WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET}, {@link WARNING_DUPLICATE_FILENAME} and
|
|
1547
|
+
* {@link WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY}.
|
|
1548
|
+
* {@link WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY} is never deposited as a warning: `"balanced"` rejects it
|
|
1549
|
+
* like `"strict"`, and `"tolerant"` reads the last record and reports the stale one as
|
|
1550
|
+
* {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA}. {@link WARNING_MISSING_ZIP64_EXTRA_FIELD} is deposited when an
|
|
1551
|
+
* entry cannot be read because its central directory record lacks a Zip64 extra field, and `"strict"` throws
|
|
1552
|
+
* {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND} for it.
|
|
1549
1553
|
*
|
|
1550
1554
|
* The warnings related to the local file header of an entry are deposited on
|
|
1551
1555
|
* {@link EntryMetaData#warnings} when its data is read, not here.
|
|
@@ -1758,9 +1762,10 @@ export interface GetEntriesOptions {
|
|
|
1758
1762
|
* systems, and it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with
|
|
1759
1763
|
* another charset.
|
|
1760
1764
|
*
|
|
1761
|
-
* Names are validated, never rewritten
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1765
|
+
* Names are validated, never rewritten: the filename reported for an entry is the one its central directory
|
|
1766
|
+
* record stores, decoded, or the one of its Unicode Path extra field when the entry carries a valid one (see
|
|
1767
|
+
* {@link EntryMetaData#extraFieldUnicodePath}), and the bytes of the record stay available in
|
|
1768
|
+
* {@link EntryMetaData#rawFilename}. The name validated is that final name.
|
|
1764
1769
|
*
|
|
1765
1770
|
* @defaultValue The value of {@link GetEntriesOptions#strictness}.
|
|
1766
1771
|
*/
|
|
@@ -1885,7 +1890,10 @@ export interface ZipReaderOptions {
|
|
|
1885
1890
|
* (e.g. streaming readers based on local file headers) interpret the entry differently. This detects mismatched
|
|
1886
1891
|
* filenames, general purpose bit flags (encryption, data descriptor and language encoding flags), compression
|
|
1887
1892
|
* methods, CRC-32 checksums and sizes. The extra fields are not compared because the zip specification allows
|
|
1888
|
-
* them to differ.
|
|
1893
|
+
* them to differ. A local file header whose CRC-32 checksum and sizes are all zero without the data descriptor
|
|
1894
|
+
* flag is tolerated, because some streaming writers leave these fields blank. When the entry has a data
|
|
1895
|
+
* descriptor, its CRC-32 checksum and sizes are compared with the central directory record instead, provided
|
|
1896
|
+
* the descriptor is read, i.e. when {@link ZipReaderOptions#checkOverlappingEntry} is set.
|
|
1889
1897
|
*
|
|
1890
1898
|
* This is the boolean form of {@link ZipReaderOptions#strictness}: `true` means `"strict"` and `false` means
|
|
1891
1899
|
* any value but `"strict"`. When both options are set, the value passed to {@link FileEntry#getData} takes
|
|
@@ -2521,7 +2529,9 @@ export interface EntryMetaData {
|
|
|
2521
2529
|
* `true` if the entry is an executable file
|
|
2522
2530
|
*
|
|
2523
2531
|
* Always `false` when {@link EntryMetaData#symlink} is `true`: the permissions of a symbolic link
|
|
2524
|
-
* are not meaningful, Unix systems store them as `0o777`.
|
|
2532
|
+
* are not meaningful, Unix systems store them as `0o777`. Always `false` when
|
|
2533
|
+
* {@link EntryMetaData#directory} is `true` too: the execute bits of a directory mean that it can be
|
|
2534
|
+
* searched, and every directory carries them; read {@link EntryMetaData#unixMode} for the bits themselves.
|
|
2525
2535
|
*/
|
|
2526
2536
|
executable: boolean;
|
|
2527
2537
|
/**
|
|
@@ -2560,17 +2570,20 @@ export interface EntryMetaData {
|
|
|
2560
2570
|
*/
|
|
2561
2571
|
lastModDate: Date;
|
|
2562
2572
|
/**
|
|
2563
|
-
* The last access date
|
|
2573
|
+
* The last access date, read from the extra fields of the central directory record or, when it holds none, from
|
|
2574
|
+
* the extra fields of the local file header once the data of the entry has been read.
|
|
2564
2575
|
*/
|
|
2565
2576
|
lastAccessDate?: Date;
|
|
2566
2577
|
/**
|
|
2567
|
-
* The creation date
|
|
2578
|
+
* The creation date, read from the extra fields of the central directory record or, when it holds none, from
|
|
2579
|
+
* the extra fields of the local file header once the data of the entry has been read.
|
|
2568
2580
|
*/
|
|
2569
2581
|
creationDate?: Date;
|
|
2570
2582
|
/**
|
|
2571
2583
|
* The last modification date (raw), as the MS-DOS date and time stored in the header. Unlike
|
|
2572
|
-
* {@link EntryMetaData#lastModDate}, it is not replaced by the value of the
|
|
2573
|
-
* is present
|
|
2584
|
+
* {@link EntryMetaData#lastModDate}, it is not replaced by the value of the extended timestamp or NTFS extra
|
|
2585
|
+
* field when one is present (the NTFS value wins over the extended timestamp one, being the finer of the two);
|
|
2586
|
+
* read {@link EntryMetaData#extraFieldNTFS} for the raw NTFS value.
|
|
2574
2587
|
*/
|
|
2575
2588
|
rawLastModDate: number | bigint;
|
|
2576
2589
|
/**
|
|
@@ -3066,20 +3079,32 @@ export class ZipWriter<Type> {
|
|
|
3066
3079
|
* @remarks
|
|
3067
3080
|
* The data of the zip file is copied, its central directory is rebuilt and its entries are relocated to
|
|
3068
3081
|
* the positions they get in the output. The disks of a split zip file passed as input are therefore unrelated to
|
|
3069
|
-
* the disks of the output, which is a single zip file unless the writer is a split zip file writer.
|
|
3082
|
+
* the disks of the output, which is a single zip file unless the writer is a split zip file writer. In that case,
|
|
3083
|
+
* the bytes before the first entry (e.g. a self-extracting stub) are copied after the split zip file signature of
|
|
3084
|
+
* the first disk, where no system runs them; use the {@link ZipWriterAppendZipOptions#filter} option to drop them. The data of
|
|
3070
3085
|
* the entries is copied as-is; in particular, the constraints set by {@link ZipWriterConstructorOptions#usdz}
|
|
3071
|
-
* are not applied to the copied entries.
|
|
3086
|
+
* are not applied to the copied entries. The comment and the digital signature of the zip file are not copied,
|
|
3087
|
+
* since its central directory is rebuilt: pass them to {@link ZipWriter#close}.
|
|
3072
3088
|
*
|
|
3073
3089
|
* Pending {@link ZipWriter#add} calls are completed before the data is copied, and add() calls made
|
|
3074
3090
|
* while the copy is in progress are written after it. If an entry of the zip file has the same
|
|
3075
3091
|
* filename as an entry of the current zip, the method throws with the `ERR_DUPLICATED_NAME` error
|
|
3076
3092
|
* message and leaves the current zip unchanged; call {@link ZipWriter#remove} beforehand to resolve
|
|
3077
|
-
* the conflicts.
|
|
3093
|
+
* the conflicts. An entry whose sizes or offset are unusable because its Zip64 extra field is missing (see
|
|
3094
|
+
* {@link WARNING_MISSING_ZIP64_EXTRA_FIELD}) cannot be copied: the method throws
|
|
3095
|
+
* {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND} and leaves the current zip unchanged, unless the
|
|
3096
|
+
* {@link ZipWriterAppendZipOptions#filter} option leaves the entry out.
|
|
3078
3097
|
*
|
|
3079
3098
|
* The returned promise can safely be left un-awaited: {@link ZipWriter#close} waits for the copy
|
|
3080
3099
|
* and throws its error if it was not caught.
|
|
3081
3100
|
*
|
|
3101
|
+
* With the {@link ZipWriterAppendZipOptions#filter} option, only the entries the function keeps are copied.
|
|
3102
|
+
* Combined with {@link ZipWriter#add}, this edits an existing zip file into a new one without decompressing
|
|
3103
|
+
* its data: the entries to keep are copied as-is, the entries to delete or replace are left out, and the
|
|
3104
|
+
* replacements and additions are added afterwards.
|
|
3105
|
+
*
|
|
3082
3106
|
* @param reader The {@link Reader} instance used to read the content of the zip file.
|
|
3107
|
+
* @param options The options.
|
|
3083
3108
|
* @returns A promise resolving when the zip file has been added.
|
|
3084
3109
|
*/
|
|
3085
3110
|
appendZip<ReaderType>(
|
|
@@ -3089,7 +3114,8 @@ export class ZipWriter<Type> {
|
|
|
3089
3114
|
| ReadableStream
|
|
3090
3115
|
| Reader<unknown>[]
|
|
3091
3116
|
| ReadableReader[]
|
|
3092
|
-
| ReadableStream[]
|
|
3117
|
+
| ReadableStream[],
|
|
3118
|
+
options?: ZipWriterAppendZipOptions
|
|
3093
3119
|
): Promise<void>;
|
|
3094
3120
|
|
|
3095
3121
|
/**
|
|
@@ -3307,6 +3333,38 @@ export interface ZipWriterAddDataOptions
|
|
|
3307
3333
|
/**
|
|
3308
3334
|
* Represents the options passed to {@link ZipWriter#close}.
|
|
3309
3335
|
*/
|
|
3336
|
+
/**
|
|
3337
|
+
* Represents the options passed to {@link ZipWriter#appendZip}.
|
|
3338
|
+
*/
|
|
3339
|
+
export interface ZipWriterAppendZipOptions {
|
|
3340
|
+
/**
|
|
3341
|
+
* Selects the entries of the zip file to copy: the function is called once per entry, in the order of the
|
|
3342
|
+
* central directory, and the entry is copied when it returns (or resolves to) `true`. The function can read
|
|
3343
|
+
* the data of the entry with {@link Entry#getData} to decide: every call completes before any data is copied.
|
|
3344
|
+
*
|
|
3345
|
+
* @remarks
|
|
3346
|
+
* When the option is set, the data of the zip file is copied entry by entry and the entries left out leave no
|
|
3347
|
+
* bytes behind in the output, unlike {@link ZipWriter#remove}, which drops an entry from the central directory
|
|
3348
|
+
* after its data has been written. The bytes of the zip file outside the entries kept are not copied either:
|
|
3349
|
+
* a self-extracting stub, the data of entries removed earlier and the padding between entries, so a zip file
|
|
3350
|
+
* aligned with {@link ZipWriterConstructorOptions#usdz} is not aligned any more once filtered. Without the
|
|
3351
|
+
* option, the data of the zip file is copied as a whole. The duplicate filename check applies to the entries
|
|
3352
|
+
* kept only, so an entry can be replaced by leaving it out and adding its replacement with {@link ZipWriter#add}.
|
|
3353
|
+
*
|
|
3354
|
+
* An entry is copied from its local file header to the end of its data or, when it has one, of its data
|
|
3355
|
+
* descriptor, whose layout is read back from the zip file; when no layout matches, the entry is copied up to
|
|
3356
|
+
* the next entry or to the central directory. Before anything is written, each kept entry is checked to start
|
|
3357
|
+
* with a local file header and to end before the next entry or the central directory; otherwise the method
|
|
3358
|
+
* throws {@link ERR_LOCAL_FILE_HEADER_NOT_FOUND} or {@link ERR_OVERLAPPING_ENTRY} and leaves the current zip
|
|
3359
|
+
* unchanged. The same checks apply when the output is a split zip file, whose entries are copied one by one
|
|
3360
|
+
* as well.
|
|
3361
|
+
*
|
|
3362
|
+
* @param entry The entry read from the zip file.
|
|
3363
|
+
* @returns `true` to copy the entry.
|
|
3364
|
+
*/
|
|
3365
|
+
filter?: (entry: Entry) => boolean | Promise<boolean>;
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3310
3368
|
export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
3311
3369
|
/**
|
|
3312
3370
|
* `true` to use Zip64 to write the entries directory.
|
|
@@ -4998,7 +5056,9 @@ export const ERR_BAD_FORMAT: string;
|
|
|
4998
5056
|
*/
|
|
4999
5057
|
export const ERR_EOCDR_NOT_FOUND: string;
|
|
5000
5058
|
/**
|
|
5001
|
-
* Zip64 End of Central Directory Locator not found error
|
|
5059
|
+
* Zip64 End of Central Directory Locator not found error: the end of central directory record holds a Zip64
|
|
5060
|
+
* sentinel in its offset, size or disk number field but no Zip64 locator precedes it, or the locator does not
|
|
5061
|
+
* point at a Zip64 end of central directory record
|
|
5002
5062
|
*/
|
|
5003
5063
|
export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
|
|
5004
5064
|
/**
|
|
@@ -5007,6 +5067,9 @@ export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
|
|
|
5007
5067
|
export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
|
|
5008
5068
|
/**
|
|
5009
5069
|
* Local file header not found error
|
|
5070
|
+
*
|
|
5071
|
+
* @remarks Also thrown by {@link ZipWriter#appendZip} when a copied entry does not point at a local file header
|
|
5072
|
+
* (see {@link ZipWriterAppendZipOptions#filter}).
|
|
5010
5073
|
*/
|
|
5011
5074
|
export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
|
|
5012
5075
|
/**
|
|
@@ -5020,7 +5083,8 @@ export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
|
|
|
5020
5083
|
* {@link WARNING_MALFORMED_EXTRA_FIELD} on {@link EntryMetaData#warnings}, and an entry without a data descriptor
|
|
5021
5084
|
* keeps the sentinels as its local sizes, which the local file header check reports as
|
|
5022
5085
|
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES}, an error or a warning depending on
|
|
5023
|
-
* {@link ZipReaderOptions#strictness}.
|
|
5086
|
+
* {@link ZipReaderOptions#strictness}. Also thrown by {@link ZipWriter#appendZip}, before anything is written,
|
|
5087
|
+
* when an entry to copy lacks the field (see {@link WARNING_MISSING_ZIP64_EXTRA_FIELD}).
|
|
5024
5088
|
*/
|
|
5025
5089
|
export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
|
|
5026
5090
|
/**
|
|
@@ -5242,13 +5306,16 @@ export const ERR_SPLIT_ZIP_FILE: string;
|
|
|
5242
5306
|
*
|
|
5243
5307
|
* @remarks Thrown by {@link FileEntry#getData} when {@link ZipReaderOptions#checkOverlappingEntry} is set and the
|
|
5244
5308
|
* data of the entry overlaps the data of an entry already read. The thrown error carries the other entry in its
|
|
5245
|
-
* `overlappingEntry` property.
|
|
5309
|
+
* `overlappingEntry` property. Also thrown by {@link ZipWriter#appendZip} when the data of a copied entry runs
|
|
5310
|
+
* into the next entry or into the central directory (see {@link ZipWriterAppendZipOptions#filter}).
|
|
5246
5311
|
*/
|
|
5247
5312
|
export const ERR_OVERLAPPING_ENTRY: string;
|
|
5248
5313
|
/**
|
|
5249
5314
|
* Entry data out of bounds error
|
|
5250
5315
|
*
|
|
5251
|
-
* @remarks Thrown by {@link FileEntry#getData} when the declared extent of the entry data (i.e. its offset plus
|
|
5316
|
+
* @remarks Thrown by {@link FileEntry#getData} when the declared extent of the entry data (i.e. its offset plus
|
|
5317
|
+
* its compressed size) ends past the central directory or past the end of the zip file, whatever
|
|
5318
|
+
* {@link ZipReaderOptions#strictness} and {@link ZipReaderOptions#checkOverlappingEntry} are set to.
|
|
5252
5319
|
*/
|
|
5253
5320
|
export const ERR_ENTRY_DATA_OUT_OF_BOUNDS: string;
|
|
5254
5321
|
/**
|
|
@@ -5256,7 +5323,8 @@ export const ERR_ENTRY_DATA_OUT_OF_BOUNDS: string;
|
|
|
5256
5323
|
*
|
|
5257
5324
|
* @remarks The thrown error carries a `reason` property describing the ambiguity: `"appended data"`,
|
|
5258
5325
|
* `"prepended data"`, `"trailing central directory data"`, `"multiple end of central directory records"`,
|
|
5259
|
-
* `"mismatched zip64 end of central directory record"`,
|
|
5326
|
+
* `"mismatched central directory offset"`, `"mismatched zip64 end of central directory record"`,
|
|
5327
|
+
* `"duplicate filename"`, or, when
|
|
5260
5328
|
* {@link ZipReaderOptions#checkLocalDirectory} compares the local header of an entry with its central
|
|
5261
5329
|
* directory record, `"mismatched local file header (filename)"`,
|
|
5262
5330
|
* `"mismatched local file header (general purpose bit flag)"`,
|
|
@@ -5597,6 +5665,29 @@ export const WARNING_PREPENDED_CENTRAL_DIRECTORY: string;
|
|
|
5597
5665
|
* the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
|
|
5598
5666
|
*/
|
|
5599
5667
|
export const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA: string;
|
|
5668
|
+
/**
|
|
5669
|
+
* Warning reason: the end of central directory record stores a central directory offset that does not point at
|
|
5670
|
+
* the central directory actually found before it, so the archive was read from the directory found rather than
|
|
5671
|
+
* from the stored offset (see {@link ZipReader#warnings}); the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under
|
|
5672
|
+
* `strictness: "strict"`
|
|
5673
|
+
*
|
|
5674
|
+
* @remarks
|
|
5675
|
+
* Such an archive is typically one written with absolute offsets for a prefix that is no longer there, e.g. a
|
|
5676
|
+
* self-extracting archive whose stub was removed, or one whose end of central directory record was damaged.
|
|
5677
|
+
* When the local file header of the first entry is found at the same shifted position only, the entries are
|
|
5678
|
+
* read from the shifted positions; otherwise the offsets stored in the central directory are used as they are.
|
|
5679
|
+
* A stored offset short of the directory whose entries are found at the shifted positions is diagnosed as
|
|
5680
|
+
* {@link WARNING_PREPENDED_DATA} instead.
|
|
5681
|
+
*/
|
|
5682
|
+
export const WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET: string;
|
|
5683
|
+
/**
|
|
5684
|
+
* Warning reason: a central directory record holds the Zip64 sentinel in a size, offset or disk number field
|
|
5685
|
+
* but carries no Zip64 extra field resolving it (see {@link ZipReader#warnings}). The entry is listed, its
|
|
5686
|
+
* sizes and offset are unusable, and reading its data or copying it with {@link ZipWriter#appendZip} throws
|
|
5687
|
+
* {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND}; the other entries are unaffected. Under `strictness: "strict"`,
|
|
5688
|
+
* {@link ZipReader#getEntries} throws {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND} instead.
|
|
5689
|
+
*/
|
|
5690
|
+
export const WARNING_MISSING_ZIP64_EXTRA_FIELD: string;
|
|
5600
5691
|
/**
|
|
5601
5692
|
* Warning reason: several entries share the same filename (see {@link ZipReader#warnings}); the reason of
|
|
5602
5693
|
* {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
|
|
@@ -5609,8 +5700,9 @@ export const WARNING_DUPLICATE_FILENAME: string;
|
|
|
5609
5700
|
export const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: string;
|
|
5610
5701
|
/**
|
|
5611
5702
|
* Warning reason: more than one end of central directory record reaches the end of the file, so another reader
|
|
5612
|
-
* may select a different one and list different entries; the reason of {@link ERR_AMBIGUOUS_ARCHIVE}
|
|
5613
|
-
*
|
|
5703
|
+
* may select a different one and list different entries; the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under
|
|
5704
|
+
* `strictness: "strict"` and `"balanced"`. It is never deposited as a warning: `"tolerant"` reads the last
|
|
5705
|
+
* record and reports the stale one as {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA}.
|
|
5614
5706
|
*/
|
|
5615
5707
|
export const WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY: string;
|
|
5616
5708
|
/**
|
|
@@ -5634,7 +5726,8 @@ export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG: string;
|
|
|
5634
5726
|
*/
|
|
5635
5727
|
export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: string;
|
|
5636
5728
|
/**
|
|
5637
|
-
* Warning reason: the crc32 or the sizes of the local file header
|
|
5729
|
+
* Warning reason: the crc32 or the sizes of the local file header, or of the data descriptor when it is read
|
|
5730
|
+
* (see {@link ZipReaderOptions#checkOverlappingEntry}), contradict the central directory
|
|
5638
5731
|
* (see {@link EntryMetaData#warnings}); the reason of {@link ERR_AMBIGUOUS_ARCHIVE} when
|
|
5639
5732
|
* {@link ZipReaderOptions#checkLocalDirectory} is enabled
|
|
5640
5733
|
*/
|
package/index.d.ts
CHANGED
|
@@ -1543,9 +1543,13 @@ export class ZipReader<Type> {
|
|
|
1543
1543
|
* `strictness: "strict"` rejects with {@link ERR_AMBIGUOUS_ARCHIVE}: when the effective strictness tolerates
|
|
1544
1544
|
* one of them and the evidence is already in hand, the same reason string is deposited as a warning instead —
|
|
1545
1545
|
* {@link WARNING_APPENDED_DATA}, {@link WARNING_PREPENDED_DATA}, {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA},
|
|
1546
|
-
* {@link
|
|
1547
|
-
* {@link
|
|
1548
|
-
*
|
|
1546
|
+
* {@link WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET}, {@link WARNING_DUPLICATE_FILENAME} and
|
|
1547
|
+
* {@link WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY}.
|
|
1548
|
+
* {@link WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY} is never deposited as a warning: `"balanced"` rejects it
|
|
1549
|
+
* like `"strict"`, and `"tolerant"` reads the last record and reports the stale one as
|
|
1550
|
+
* {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA}. {@link WARNING_MISSING_ZIP64_EXTRA_FIELD} is deposited when an
|
|
1551
|
+
* entry cannot be read because its central directory record lacks a Zip64 extra field, and `"strict"` throws
|
|
1552
|
+
* {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND} for it.
|
|
1549
1553
|
*
|
|
1550
1554
|
* The warnings related to the local file header of an entry are deposited on
|
|
1551
1555
|
* {@link EntryMetaData#warnings} when its data is read, not here.
|
|
@@ -1758,9 +1762,10 @@ export interface GetEntriesOptions {
|
|
|
1758
1762
|
* systems, and it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with
|
|
1759
1763
|
* another charset.
|
|
1760
1764
|
*
|
|
1761
|
-
* Names are validated, never rewritten
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1765
|
+
* Names are validated, never rewritten: the filename reported for an entry is the one its central directory
|
|
1766
|
+
* record stores, decoded, or the one of its Unicode Path extra field when the entry carries a valid one (see
|
|
1767
|
+
* {@link EntryMetaData#extraFieldUnicodePath}), and the bytes of the record stay available in
|
|
1768
|
+
* {@link EntryMetaData#rawFilename}. The name validated is that final name.
|
|
1764
1769
|
*
|
|
1765
1770
|
* @defaultValue The value of {@link GetEntriesOptions#strictness}.
|
|
1766
1771
|
*/
|
|
@@ -1885,7 +1890,10 @@ export interface ZipReaderOptions {
|
|
|
1885
1890
|
* (e.g. streaming readers based on local file headers) interpret the entry differently. This detects mismatched
|
|
1886
1891
|
* filenames, general purpose bit flags (encryption, data descriptor and language encoding flags), compression
|
|
1887
1892
|
* methods, CRC-32 checksums and sizes. The extra fields are not compared because the zip specification allows
|
|
1888
|
-
* them to differ.
|
|
1893
|
+
* them to differ. A local file header whose CRC-32 checksum and sizes are all zero without the data descriptor
|
|
1894
|
+
* flag is tolerated, because some streaming writers leave these fields blank. When the entry has a data
|
|
1895
|
+
* descriptor, its CRC-32 checksum and sizes are compared with the central directory record instead, provided
|
|
1896
|
+
* the descriptor is read, i.e. when {@link ZipReaderOptions#checkOverlappingEntry} is set.
|
|
1889
1897
|
*
|
|
1890
1898
|
* This is the boolean form of {@link ZipReaderOptions#strictness}: `true` means `"strict"` and `false` means
|
|
1891
1899
|
* any value but `"strict"`. When both options are set, the value passed to {@link FileEntry#getData} takes
|
|
@@ -2521,7 +2529,9 @@ export interface EntryMetaData {
|
|
|
2521
2529
|
* `true` if the entry is an executable file
|
|
2522
2530
|
*
|
|
2523
2531
|
* Always `false` when {@link EntryMetaData#symlink} is `true`: the permissions of a symbolic link
|
|
2524
|
-
* are not meaningful, Unix systems store them as `0o777`.
|
|
2532
|
+
* are not meaningful, Unix systems store them as `0o777`. Always `false` when
|
|
2533
|
+
* {@link EntryMetaData#directory} is `true` too: the execute bits of a directory mean that it can be
|
|
2534
|
+
* searched, and every directory carries them; read {@link EntryMetaData#unixMode} for the bits themselves.
|
|
2525
2535
|
*/
|
|
2526
2536
|
executable: boolean;
|
|
2527
2537
|
/**
|
|
@@ -2560,17 +2570,20 @@ export interface EntryMetaData {
|
|
|
2560
2570
|
*/
|
|
2561
2571
|
lastModDate: Date;
|
|
2562
2572
|
/**
|
|
2563
|
-
* The last access date
|
|
2573
|
+
* The last access date, read from the extra fields of the central directory record or, when it holds none, from
|
|
2574
|
+
* the extra fields of the local file header once the data of the entry has been read.
|
|
2564
2575
|
*/
|
|
2565
2576
|
lastAccessDate?: Date;
|
|
2566
2577
|
/**
|
|
2567
|
-
* The creation date
|
|
2578
|
+
* The creation date, read from the extra fields of the central directory record or, when it holds none, from
|
|
2579
|
+
* the extra fields of the local file header once the data of the entry has been read.
|
|
2568
2580
|
*/
|
|
2569
2581
|
creationDate?: Date;
|
|
2570
2582
|
/**
|
|
2571
2583
|
* The last modification date (raw), as the MS-DOS date and time stored in the header. Unlike
|
|
2572
|
-
* {@link EntryMetaData#lastModDate}, it is not replaced by the value of the
|
|
2573
|
-
* is present
|
|
2584
|
+
* {@link EntryMetaData#lastModDate}, it is not replaced by the value of the extended timestamp or NTFS extra
|
|
2585
|
+
* field when one is present (the NTFS value wins over the extended timestamp one, being the finer of the two);
|
|
2586
|
+
* read {@link EntryMetaData#extraFieldNTFS} for the raw NTFS value.
|
|
2574
2587
|
*/
|
|
2575
2588
|
rawLastModDate: number | bigint;
|
|
2576
2589
|
/**
|
|
@@ -3066,20 +3079,32 @@ export class ZipWriter<Type> {
|
|
|
3066
3079
|
* @remarks
|
|
3067
3080
|
* The data of the zip file is copied, its central directory is rebuilt and its entries are relocated to
|
|
3068
3081
|
* the positions they get in the output. The disks of a split zip file passed as input are therefore unrelated to
|
|
3069
|
-
* the disks of the output, which is a single zip file unless the writer is a split zip file writer.
|
|
3082
|
+
* the disks of the output, which is a single zip file unless the writer is a split zip file writer. In that case,
|
|
3083
|
+
* the bytes before the first entry (e.g. a self-extracting stub) are copied after the split zip file signature of
|
|
3084
|
+
* the first disk, where no system runs them; use the {@link ZipWriterAppendZipOptions#filter} option to drop them. The data of
|
|
3070
3085
|
* the entries is copied as-is; in particular, the constraints set by {@link ZipWriterConstructorOptions#usdz}
|
|
3071
|
-
* are not applied to the copied entries.
|
|
3086
|
+
* are not applied to the copied entries. The comment and the digital signature of the zip file are not copied,
|
|
3087
|
+
* since its central directory is rebuilt: pass them to {@link ZipWriter#close}.
|
|
3072
3088
|
*
|
|
3073
3089
|
* Pending {@link ZipWriter#add} calls are completed before the data is copied, and add() calls made
|
|
3074
3090
|
* while the copy is in progress are written after it. If an entry of the zip file has the same
|
|
3075
3091
|
* filename as an entry of the current zip, the method throws with the `ERR_DUPLICATED_NAME` error
|
|
3076
3092
|
* message and leaves the current zip unchanged; call {@link ZipWriter#remove} beforehand to resolve
|
|
3077
|
-
* the conflicts.
|
|
3093
|
+
* the conflicts. An entry whose sizes or offset are unusable because its Zip64 extra field is missing (see
|
|
3094
|
+
* {@link WARNING_MISSING_ZIP64_EXTRA_FIELD}) cannot be copied: the method throws
|
|
3095
|
+
* {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND} and leaves the current zip unchanged, unless the
|
|
3096
|
+
* {@link ZipWriterAppendZipOptions#filter} option leaves the entry out.
|
|
3078
3097
|
*
|
|
3079
3098
|
* The returned promise can safely be left un-awaited: {@link ZipWriter#close} waits for the copy
|
|
3080
3099
|
* and throws its error if it was not caught.
|
|
3081
3100
|
*
|
|
3101
|
+
* With the {@link ZipWriterAppendZipOptions#filter} option, only the entries the function keeps are copied.
|
|
3102
|
+
* Combined with {@link ZipWriter#add}, this edits an existing zip file into a new one without decompressing
|
|
3103
|
+
* its data: the entries to keep are copied as-is, the entries to delete or replace are left out, and the
|
|
3104
|
+
* replacements and additions are added afterwards.
|
|
3105
|
+
*
|
|
3082
3106
|
* @param reader The {@link Reader} instance used to read the content of the zip file.
|
|
3107
|
+
* @param options The options.
|
|
3083
3108
|
* @returns A promise resolving when the zip file has been added.
|
|
3084
3109
|
*/
|
|
3085
3110
|
appendZip<ReaderType>(
|
|
@@ -3089,7 +3114,8 @@ export class ZipWriter<Type> {
|
|
|
3089
3114
|
| ReadableStream
|
|
3090
3115
|
| Reader<unknown>[]
|
|
3091
3116
|
| ReadableReader[]
|
|
3092
|
-
| ReadableStream[]
|
|
3117
|
+
| ReadableStream[],
|
|
3118
|
+
options?: ZipWriterAppendZipOptions
|
|
3093
3119
|
): Promise<void>;
|
|
3094
3120
|
|
|
3095
3121
|
/**
|
|
@@ -3307,6 +3333,38 @@ export interface ZipWriterAddDataOptions
|
|
|
3307
3333
|
/**
|
|
3308
3334
|
* Represents the options passed to {@link ZipWriter#close}.
|
|
3309
3335
|
*/
|
|
3336
|
+
/**
|
|
3337
|
+
* Represents the options passed to {@link ZipWriter#appendZip}.
|
|
3338
|
+
*/
|
|
3339
|
+
export interface ZipWriterAppendZipOptions {
|
|
3340
|
+
/**
|
|
3341
|
+
* Selects the entries of the zip file to copy: the function is called once per entry, in the order of the
|
|
3342
|
+
* central directory, and the entry is copied when it returns (or resolves to) `true`. The function can read
|
|
3343
|
+
* the data of the entry with {@link Entry#getData} to decide: every call completes before any data is copied.
|
|
3344
|
+
*
|
|
3345
|
+
* @remarks
|
|
3346
|
+
* When the option is set, the data of the zip file is copied entry by entry and the entries left out leave no
|
|
3347
|
+
* bytes behind in the output, unlike {@link ZipWriter#remove}, which drops an entry from the central directory
|
|
3348
|
+
* after its data has been written. The bytes of the zip file outside the entries kept are not copied either:
|
|
3349
|
+
* a self-extracting stub, the data of entries removed earlier and the padding between entries, so a zip file
|
|
3350
|
+
* aligned with {@link ZipWriterConstructorOptions#usdz} is not aligned any more once filtered. Without the
|
|
3351
|
+
* option, the data of the zip file is copied as a whole. The duplicate filename check applies to the entries
|
|
3352
|
+
* kept only, so an entry can be replaced by leaving it out and adding its replacement with {@link ZipWriter#add}.
|
|
3353
|
+
*
|
|
3354
|
+
* An entry is copied from its local file header to the end of its data or, when it has one, of its data
|
|
3355
|
+
* descriptor, whose layout is read back from the zip file; when no layout matches, the entry is copied up to
|
|
3356
|
+
* the next entry or to the central directory. Before anything is written, each kept entry is checked to start
|
|
3357
|
+
* with a local file header and to end before the next entry or the central directory; otherwise the method
|
|
3358
|
+
* throws {@link ERR_LOCAL_FILE_HEADER_NOT_FOUND} or {@link ERR_OVERLAPPING_ENTRY} and leaves the current zip
|
|
3359
|
+
* unchanged. The same checks apply when the output is a split zip file, whose entries are copied one by one
|
|
3360
|
+
* as well.
|
|
3361
|
+
*
|
|
3362
|
+
* @param entry The entry read from the zip file.
|
|
3363
|
+
* @returns `true` to copy the entry.
|
|
3364
|
+
*/
|
|
3365
|
+
filter?: (entry: Entry) => boolean | Promise<boolean>;
|
|
3366
|
+
}
|
|
3367
|
+
|
|
3310
3368
|
export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
3311
3369
|
/**
|
|
3312
3370
|
* `true` to use Zip64 to write the entries directory.
|
|
@@ -4998,7 +5056,9 @@ export const ERR_BAD_FORMAT: string;
|
|
|
4998
5056
|
*/
|
|
4999
5057
|
export const ERR_EOCDR_NOT_FOUND: string;
|
|
5000
5058
|
/**
|
|
5001
|
-
* Zip64 End of Central Directory Locator not found error
|
|
5059
|
+
* Zip64 End of Central Directory Locator not found error: the end of central directory record holds a Zip64
|
|
5060
|
+
* sentinel in its offset, size or disk number field but no Zip64 locator precedes it, or the locator does not
|
|
5061
|
+
* point at a Zip64 end of central directory record
|
|
5002
5062
|
*/
|
|
5003
5063
|
export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
|
|
5004
5064
|
/**
|
|
@@ -5007,6 +5067,9 @@ export const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND: string;
|
|
|
5007
5067
|
export const ERR_CENTRAL_DIRECTORY_NOT_FOUND: string;
|
|
5008
5068
|
/**
|
|
5009
5069
|
* Local file header not found error
|
|
5070
|
+
*
|
|
5071
|
+
* @remarks Also thrown by {@link ZipWriter#appendZip} when a copied entry does not point at a local file header
|
|
5072
|
+
* (see {@link ZipWriterAppendZipOptions#filter}).
|
|
5010
5073
|
*/
|
|
5011
5074
|
export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
|
|
5012
5075
|
/**
|
|
@@ -5020,7 +5083,8 @@ export const ERR_LOCAL_FILE_HEADER_NOT_FOUND: string;
|
|
|
5020
5083
|
* {@link WARNING_MALFORMED_EXTRA_FIELD} on {@link EntryMetaData#warnings}, and an entry without a data descriptor
|
|
5021
5084
|
* keeps the sentinels as its local sizes, which the local file header check reports as
|
|
5022
5085
|
* {@link WARNING_MISMATCHED_LOCAL_FILE_HEADER_CRC32_OR_SIZES}, an error or a warning depending on
|
|
5023
|
-
* {@link ZipReaderOptions#strictness}.
|
|
5086
|
+
* {@link ZipReaderOptions#strictness}. Also thrown by {@link ZipWriter#appendZip}, before anything is written,
|
|
5087
|
+
* when an entry to copy lacks the field (see {@link WARNING_MISSING_ZIP64_EXTRA_FIELD}).
|
|
5024
5088
|
*/
|
|
5025
5089
|
export const ERR_EXTRAFIELD_ZIP64_NOT_FOUND: string;
|
|
5026
5090
|
/**
|
|
@@ -5242,13 +5306,16 @@ export const ERR_SPLIT_ZIP_FILE: string;
|
|
|
5242
5306
|
*
|
|
5243
5307
|
* @remarks Thrown by {@link FileEntry#getData} when {@link ZipReaderOptions#checkOverlappingEntry} is set and the
|
|
5244
5308
|
* data of the entry overlaps the data of an entry already read. The thrown error carries the other entry in its
|
|
5245
|
-
* `overlappingEntry` property.
|
|
5309
|
+
* `overlappingEntry` property. Also thrown by {@link ZipWriter#appendZip} when the data of a copied entry runs
|
|
5310
|
+
* into the next entry or into the central directory (see {@link ZipWriterAppendZipOptions#filter}).
|
|
5246
5311
|
*/
|
|
5247
5312
|
export const ERR_OVERLAPPING_ENTRY: string;
|
|
5248
5313
|
/**
|
|
5249
5314
|
* Entry data out of bounds error
|
|
5250
5315
|
*
|
|
5251
|
-
* @remarks Thrown by {@link FileEntry#getData} when the declared extent of the entry data (i.e. its offset plus
|
|
5316
|
+
* @remarks Thrown by {@link FileEntry#getData} when the declared extent of the entry data (i.e. its offset plus
|
|
5317
|
+
* its compressed size) ends past the central directory or past the end of the zip file, whatever
|
|
5318
|
+
* {@link ZipReaderOptions#strictness} and {@link ZipReaderOptions#checkOverlappingEntry} are set to.
|
|
5252
5319
|
*/
|
|
5253
5320
|
export const ERR_ENTRY_DATA_OUT_OF_BOUNDS: string;
|
|
5254
5321
|
/**
|
|
@@ -5256,7 +5323,8 @@ export const ERR_ENTRY_DATA_OUT_OF_BOUNDS: string;
|
|
|
5256
5323
|
*
|
|
5257
5324
|
* @remarks The thrown error carries a `reason` property describing the ambiguity: `"appended data"`,
|
|
5258
5325
|
* `"prepended data"`, `"trailing central directory data"`, `"multiple end of central directory records"`,
|
|
5259
|
-
* `"mismatched zip64 end of central directory record"`,
|
|
5326
|
+
* `"mismatched central directory offset"`, `"mismatched zip64 end of central directory record"`,
|
|
5327
|
+
* `"duplicate filename"`, or, when
|
|
5260
5328
|
* {@link ZipReaderOptions#checkLocalDirectory} compares the local header of an entry with its central
|
|
5261
5329
|
* directory record, `"mismatched local file header (filename)"`,
|
|
5262
5330
|
* `"mismatched local file header (general purpose bit flag)"`,
|
|
@@ -5597,6 +5665,29 @@ export const WARNING_PREPENDED_CENTRAL_DIRECTORY: string;
|
|
|
5597
5665
|
* the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
|
|
5598
5666
|
*/
|
|
5599
5667
|
export const WARNING_TRAILING_CENTRAL_DIRECTORY_DATA: string;
|
|
5668
|
+
/**
|
|
5669
|
+
* Warning reason: the end of central directory record stores a central directory offset that does not point at
|
|
5670
|
+
* the central directory actually found before it, so the archive was read from the directory found rather than
|
|
5671
|
+
* from the stored offset (see {@link ZipReader#warnings}); the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under
|
|
5672
|
+
* `strictness: "strict"`
|
|
5673
|
+
*
|
|
5674
|
+
* @remarks
|
|
5675
|
+
* Such an archive is typically one written with absolute offsets for a prefix that is no longer there, e.g. a
|
|
5676
|
+
* self-extracting archive whose stub was removed, or one whose end of central directory record was damaged.
|
|
5677
|
+
* When the local file header of the first entry is found at the same shifted position only, the entries are
|
|
5678
|
+
* read from the shifted positions; otherwise the offsets stored in the central directory are used as they are.
|
|
5679
|
+
* A stored offset short of the directory whose entries are found at the shifted positions is diagnosed as
|
|
5680
|
+
* {@link WARNING_PREPENDED_DATA} instead.
|
|
5681
|
+
*/
|
|
5682
|
+
export const WARNING_MISMATCHED_CENTRAL_DIRECTORY_OFFSET: string;
|
|
5683
|
+
/**
|
|
5684
|
+
* Warning reason: a central directory record holds the Zip64 sentinel in a size, offset or disk number field
|
|
5685
|
+
* but carries no Zip64 extra field resolving it (see {@link ZipReader#warnings}). The entry is listed, its
|
|
5686
|
+
* sizes and offset are unusable, and reading its data or copying it with {@link ZipWriter#appendZip} throws
|
|
5687
|
+
* {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND}; the other entries are unaffected. Under `strictness: "strict"`,
|
|
5688
|
+
* {@link ZipReader#getEntries} throws {@link ERR_EXTRAFIELD_ZIP64_NOT_FOUND} instead.
|
|
5689
|
+
*/
|
|
5690
|
+
export const WARNING_MISSING_ZIP64_EXTRA_FIELD: string;
|
|
5600
5691
|
/**
|
|
5601
5692
|
* Warning reason: several entries share the same filename (see {@link ZipReader#warnings}); the reason of
|
|
5602
5693
|
* {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
|
|
@@ -5609,8 +5700,9 @@ export const WARNING_DUPLICATE_FILENAME: string;
|
|
|
5609
5700
|
export const WARNING_MISMATCHED_ZIP64_END_OF_CENTRAL_DIRECTORY: string;
|
|
5610
5701
|
/**
|
|
5611
5702
|
* Warning reason: more than one end of central directory record reaches the end of the file, so another reader
|
|
5612
|
-
* may select a different one and list different entries; the reason of {@link ERR_AMBIGUOUS_ARCHIVE}
|
|
5613
|
-
*
|
|
5703
|
+
* may select a different one and list different entries; the reason of {@link ERR_AMBIGUOUS_ARCHIVE} under
|
|
5704
|
+
* `strictness: "strict"` and `"balanced"`. It is never deposited as a warning: `"tolerant"` reads the last
|
|
5705
|
+
* record and reports the stale one as {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA}.
|
|
5614
5706
|
*/
|
|
5615
5707
|
export const WARNING_MULTIPLE_END_OF_CENTRAL_DIRECTORY: string;
|
|
5616
5708
|
/**
|
|
@@ -5634,7 +5726,8 @@ export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_BIT_FLAG: string;
|
|
|
5634
5726
|
*/
|
|
5635
5727
|
export const WARNING_MISMATCHED_LOCAL_FILE_HEADER_COMPRESSION_METHOD: string;
|
|
5636
5728
|
/**
|
|
5637
|
-
* Warning reason: the crc32 or the sizes of the local file header
|
|
5729
|
+
* Warning reason: the crc32 or the sizes of the local file header, or of the data descriptor when it is read
|
|
5730
|
+
* (see {@link ZipReaderOptions#checkOverlappingEntry}), contradict the central directory
|
|
5638
5731
|
* (see {@link EntryMetaData#warnings}); the reason of {@link ERR_AMBIGUOUS_ARCHIVE} when
|
|
5639
5732
|
* {@link ZipReaderOptions#checkLocalDirectory} is enabled
|
|
5640
5733
|
*/
|