@zip.js/zip.js 2.8.61 → 2.10.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/index.d.cts CHANGED
@@ -1467,8 +1467,10 @@ export class ZipReader<Type> {
1467
1467
  * {@link WARNING_UNKNOWN_VERSION} (the low byte of the "version needed to extract" field exceeds the highest
1468
1468
  * known zip specification version; the high byte is ignored because some writers store a host identifier in it),
1469
1469
  * {@link WARNING_COMPRESSED_PATCHED_DATA} (bit 5 of the general purpose bit flag),
1470
- * {@link WARNING_MALFORMED_EXTRA_FIELD}, {@link WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA} and
1471
- * {@link WARNING_WRAPPED_ENTRIES_COUNT}. The other reasons are the checks that
1470
+ * {@link WARNING_MALFORMED_EXTRA_FIELD}, {@link WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA},
1471
+ * {@link WARNING_WRAPPED_ENTRIES_COUNT} and {@link WARNING_PREPENDED_CENTRAL_DIRECTORY} (the prepended data
1472
+ * holds a central directory of its own, i.e. another archive precedes this one and other readers may report
1473
+ * its entries instead). The other reasons are the checks that
1472
1474
  * `strictness: "strict"` rejects with {@link ERR_AMBIGUOUS_ARCHIVE}: when the effective strictness tolerates
1473
1475
  * one of them and the evidence is already in hand, the same reason string is deposited as a warning instead —
1474
1476
  * {@link WARNING_APPENDED_DATA}, {@link WARNING_PREPENDED_DATA}, {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA},
@@ -1592,10 +1594,17 @@ export interface ZipReaderGetEntriesOptions
1592
1594
  export interface GetEntriesOptions {
1593
1595
  /**
1594
1596
  * The encoding of the filename of the entry.
1597
+ *
1598
+ * The option is ignored when the general purpose bit 11 is set in the header of the entry: such a
1599
+ * filename is always decoded as UTF-8. It is only read when the bit is not set, and the filename is
1600
+ * then decoded as IBM Code Page 437 when the option is not set either.
1595
1601
  */
1596
1602
  filenameEncoding?: string;
1597
1603
  /**
1598
1604
  * The encoding of the comment of the entry.
1605
+ *
1606
+ * The option is ignored when the general purpose bit 11 is set in the header of the entry, see
1607
+ * {@link GetEntriesOptions#filenameEncoding}.
1599
1608
  */
1600
1609
  commentEncoding?: string;
1601
1610
  /**
@@ -3242,6 +3251,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3242
3251
  * Note that this option only sets the flag, it does not ensure that the file names are in the correct
3243
3252
  * encoding: when it is set to `false`, the names are still encoded in UTF-8 unless the
3244
3253
  * {@link ZipWriterConstructorOptions#encodeText} option is also set to encode them in the intended code page.
3254
+ * Setting it to `false` alone therefore produces an archive whose file names are mislabeled, holding UTF-8
3255
+ * bytes announced as Code Page 437: the names holding characters outside of ASCII are decoded incorrectly
3256
+ * by the readers honoring the flag, including {@link ZipReader} unless
3257
+ * {@link GetEntriesOptions#filenameEncoding} is set to `"utf-8"`.
3245
3258
  *
3246
3259
  * @defaultValue true
3247
3260
  */
@@ -3456,6 +3469,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3456
3469
  /**
3457
3470
  * The function called for encoding the filename and the comment of the entry.
3458
3471
  *
3472
+ * zip.js encodes them in UTF-8 when the option is not set, so it must be set to write them in another
3473
+ * code page, together with {@link ZipWriterConstructorOptions#useUnicodeFileNames} set to `false` to
3474
+ * announce them as Code Page 437 instead of UTF-8.
3475
+ *
3459
3476
  * @param text The text to encode.
3460
3477
  * @param type The type of the encoded text, `"filename"` or `"comment"`.
3461
3478
  * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
@@ -3543,6 +3560,9 @@ export class ZipEntry {
3543
3560
  * @remarks It is the size of the raw compressed content when the entry has been imported with the
3544
3561
  * `passThrough` option set to `true`, since the entry holds the compressed data in that case. The
3545
3562
  * uncompressed size of the original entry remains available in {@link ZipEntry#data}.
3563
+ *
3564
+ * It is updated by the `{@link ZipFileEntry}#replace*()` methods, and it is `0` for an entry holding
3565
+ * a `ReadableStream` instance, whose size is only known once the entry has been read.
3546
3566
  */
3547
3567
  uncompressedSize: number;
3548
3568
  /**
@@ -3592,6 +3612,12 @@ export class ZipEntry {
3592
3612
  /**
3593
3613
  * Set the name of the entry
3594
3614
  *
3615
+ * @remarks A name holding `"/"` is split into path components, like the name passed to a
3616
+ * `{@link ZipDirectoryEntry}#add*()` method, so it moves the entry into the directories it names,
3617
+ * creating them when they do not exist. Renaming an entry to the name it already has does nothing.
3618
+ * Renaming it onto an existing sibling throws an {@link ERR_ENTRY_EXISTS} error, and renaming it
3619
+ * into itself or into one of its descendants throws.
3620
+ *
3595
3621
  * @param name The new name of the entry.
3596
3622
  */
3597
3623
  rename(name: string): void;
@@ -3617,6 +3643,11 @@ export class ZipEntry {
3617
3643
 
3618
3644
  /**
3619
3645
  * Represents a file entry in the zip (Filesystem API).
3646
+ *
3647
+ * @remarks A `{@link ZipFileEntry}#replace*()` method describes the entry with the content it is
3648
+ * given: it updates {@link ZipEntry#uncompressedSize} and clears the pass-through state of an entry
3649
+ * imported with the {@link ZipReaderOptions#passThrough} option, since the bytes copied verbatim are
3650
+ * gone. Replacing the content of an entry therefore keeps {@link ZipFS#getExportedSize} exact.
3620
3651
  */
3621
3652
  export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
3622
3653
  /**
@@ -3735,6 +3766,10 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
3735
3766
  /**
3736
3767
  * Replaces the content of the entry with a `ReadableStream` instance
3737
3768
  *
3769
+ * @remarks The size of a `ReadableStream` instance is unknown, so the entry reports an undetermined
3770
+ * size, like an entry added with {@link ZipDirectoryEntry#addReadable}. {@link ZipFS#getExportedSize}
3771
+ * then throws an {@link ERR_UNDETERMINED_SIZE} error instead of returning a size it cannot predict.
3772
+ *
3738
3773
  * @param readable The `ReadableStream` instance.
3739
3774
  */
3740
3775
  replaceReadable(readable: ReadableStream): void;
@@ -3742,6 +3777,13 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
3742
3777
 
3743
3778
  /**
3744
3779
  * Represents a directory entry in the zip (Filesystem API).
3780
+ *
3781
+ * @remarks The `name` passed to an `{@link ZipDirectoryEntry}#add*()` method is split into path
3782
+ * components, exactly like the filename of an imported entry, so `addText("a/b.txt", text)` adds
3783
+ * `"b.txt"` to the `"a"` directory and creates that directory when it does not exist. Empty
3784
+ * components and `"."` components are ignored. The directories created that way are navigable like
3785
+ * any other entry but are not written when the tree is exported, so the zip file holds the same
3786
+ * entries whichever way the path was built.
3745
3787
  */
3746
3788
  export class ZipDirectoryEntry extends ZipEntry {
3747
3789
  /**
@@ -3914,7 +3956,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3914
3956
  */
3915
3957
  importBlob(
3916
3958
  blob: Blob,
3917
- options?: ZipReaderConstructorOptions
3959
+ options?: ZipDirectoryEntryImportOptions
3918
3960
  ): Promise<[ZipEntry]>;
3919
3961
  /**
3920
3962
  * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
@@ -3927,7 +3969,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3927
3969
  */
3928
3970
  importData64URI(
3929
3971
  dataURI: string,
3930
- options?: ZipReaderConstructorOptions
3972
+ options?: ZipDirectoryEntryImportOptions
3931
3973
  ): Promise<[ZipEntry]>;
3932
3974
  /**
3933
3975
  * Extracts a zip file provided as a `Uint8Array` instance into the entry
@@ -3940,7 +3982,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3940
3982
  */
3941
3983
  importUint8Array(
3942
3984
  array: Uint8Array,
3943
- options?: ZipReaderConstructorOptions
3985
+ options?: ZipDirectoryEntryImportOptions
3944
3986
  ): Promise<[ZipEntry]>;
3945
3987
  /**
3946
3988
  * Extracts a zip file fetched from a URL into the entry
@@ -3970,7 +4012,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3970
4012
  */
3971
4013
  importReadable(
3972
4014
  readable: ReadableStream,
3973
- options?: ZipReaderConstructorOptions
4015
+ options?: ZipDirectoryEntryImportOptions
3974
4016
  ): Promise<[ZipEntry]>;
3975
4017
  /**
3976
4018
  * Extracts a zip file provided via a custom {@link Reader} instance or a {@link ZipReader} instance into
@@ -4006,7 +4048,7 @@ export class ZipDirectoryEntry extends ZipEntry {
4006
4048
  | ReadableReader[]
4007
4049
  | ReadableStream[]
4008
4050
  | ZipReader<unknown>,
4009
- options?: ZipReaderConstructorOptions
4051
+ options?: ZipDirectoryEntryImportOptions
4010
4052
  ): Promise<[ZipEntry]>;
4011
4053
  /**
4012
4054
  * Returns a `Blob` instance containing a zip file of the entry and its descendants
@@ -4110,7 +4152,9 @@ export class ZipDirectoryEntry extends ZipEntry {
4110
4152
  * This happens when `usdz` is set, since the alignment padding depends on the offset of each
4111
4153
  * entry, and when the archive exceeds 4GB, since the offsets recorded in the central directory
4112
4154
  * are then extended to 64 bits. Passing `bufferedWrite: false` makes both determinable again,
4113
- * as does exporting a directory whose children are all files. It is thrown as well when
4155
+ * as does exporting a directory whose children are all files. A name holding `"/"` creates the
4156
+ * directories it names, so `addText("a/b.txt", text)` builds a tree whose children are not all
4157
+ * files, even though the directories created that way are not written. It is thrown as well when
4114
4158
  * `signCentralDirectory` is set, the length of the signature being unknown until it is computed.
4115
4159
  *
4116
4160
  * @param options The options.
@@ -4120,11 +4164,39 @@ export class ZipDirectoryEntry extends ZipEntry {
4120
4164
  getExportedSize(options?: ZipDirectoryEntryExportOptions): Promise<number>;
4121
4165
  }
4122
4166
 
4167
+ /**
4168
+ * Represents the options passed to `{@link ZipDirectoryEntry}#import*()`.
4169
+ */
4170
+ export interface ZipDirectoryEntryImportOptions
4171
+ extends ZipReaderConstructorOptions {
4172
+ /**
4173
+ * The policy applied when two entries of the imported zip file claim the same node of the tree
4174
+ *
4175
+ * @remarks
4176
+ * The tree indexes the entries by path, whereas a zip file stores a flat list of filenames, so two
4177
+ * entries can claim one node: they can hold the same filename, hold filenames differing only by the
4178
+ * path components ignored when building the tree (e.g. `"a/b.txt"` and `"./a/b.txt"`), or one can be
4179
+ * a file and the other a directory holding it (e.g. `"a"` and `"a/b.txt"`).
4180
+ *
4181
+ * `"throw"` refuses the zip file with an {@link ERR_DUPLICATE_IMPORTED_ENTRY} error, whose `cause`
4182
+ * property holds the {@link EntryMetaData} instance of the entry that could not be imported. The
4183
+ * filesystem is left unchanged, i.e. the entries imported before the error are removed and the
4184
+ * content held before the import is restored.
4185
+ *
4186
+ * `"keep-first"` ignores the entry claiming a node already taken, and `"keep-last"` replaces the
4187
+ * entry holding the node, which is the behavior of most zip tools. The entries that do not collide
4188
+ * are imported in both cases.
4189
+ *
4190
+ * @defaultValue "throw"
4191
+ */
4192
+ duplicates?: "throw" | "keep-first" | "keep-last";
4193
+ }
4194
+
4123
4195
  /**
4124
4196
  * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
4125
4197
  */
4126
4198
  export interface ZipDirectoryEntryImportHttpOptions
4127
- extends ZipReaderConstructorOptions,
4199
+ extends ZipDirectoryEntryImportOptions,
4128
4200
  HttpOptions {}
4129
4201
 
4130
4202
  /**
@@ -4777,6 +4849,16 @@ export const ERR_ZIP_CRYPTO_LAST_MOD_DATE: string;
4777
4849
  * Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
4778
4850
  */
4779
4851
  export const ERR_ENTRY_EXISTS: string;
4852
+ /**
4853
+ * Duplicate imported entry error (thrown by `{@link ZipDirectoryEntry}#import*()` when two entries of the
4854
+ * zip file claim the same node of the tree and the {@link ZipDirectoryEntryImportOptions#duplicates} option
4855
+ * is set to `"throw"`)
4856
+ */
4857
+ export const ERR_DUPLICATE_IMPORTED_ENTRY: string;
4858
+ /**
4859
+ * Invalid duplicates option error
4860
+ */
4861
+ export const ERR_INVALID_DUPLICATES: string;
4780
4862
  /**
4781
4863
  * Readable stream already consumed error (thrown by the filesystem API when a readable stream is read more than once)
4782
4864
  */
@@ -4842,6 +4924,19 @@ export const WARNING_APPENDED_DATA: string;
4842
4924
  * {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
4843
4925
  */
4844
4926
  export const WARNING_PREPENDED_DATA: string;
4927
+ /**
4928
+ * Warning reason: the data prepended before the zip file holds a central directory of its own, i.e. the zip file
4929
+ * is preceded by another archive rather than by an arbitrary prefix such as a self-extracting stub
4930
+ * (see {@link ZipReader#warnings})
4931
+ *
4932
+ * @remarks
4933
+ * Readers disagree on such files: zip.js reads the last archive, as Info-ZIP `unzip` and Python's `zipfile` do,
4934
+ * whereas 7-Zip reads the first one and reports the rest as data after the end of the archive. The archive is
4935
+ * therefore ambiguous, and the entries reported here may not be the entries another tool reports. It is always
4936
+ * accompanied by {@link WARNING_PREPENDED_DATA}, which alone does not distinguish this case from a benign prefix.
4937
+ * Use `strictness: "strict"` to reject these archives instead, at the cost of also rejecting benign prefixes.
4938
+ */
4939
+ export const WARNING_PREPENDED_CENTRAL_DIRECTORY: string;
4845
4940
  /**
4846
4941
  * Warning reason: data lies between the end of the central directory records and the end of central directory
4847
4942
  * record, either inside the declared central directory length or beyond it (see {@link ZipReader#warnings});
package/index.d.ts CHANGED
@@ -1467,8 +1467,10 @@ export class ZipReader<Type> {
1467
1467
  * {@link WARNING_UNKNOWN_VERSION} (the low byte of the "version needed to extract" field exceeds the highest
1468
1468
  * known zip specification version; the high byte is ignored because some writers store a host identifier in it),
1469
1469
  * {@link WARNING_COMPRESSED_PATCHED_DATA} (bit 5 of the general purpose bit flag),
1470
- * {@link WARNING_MALFORMED_EXTRA_FIELD}, {@link WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA} and
1471
- * {@link WARNING_WRAPPED_ENTRIES_COUNT}. The other reasons are the checks that
1470
+ * {@link WARNING_MALFORMED_EXTRA_FIELD}, {@link WARNING_UNKNOWN_ZIP64_EXTENSIBLE_DATA},
1471
+ * {@link WARNING_WRAPPED_ENTRIES_COUNT} and {@link WARNING_PREPENDED_CENTRAL_DIRECTORY} (the prepended data
1472
+ * holds a central directory of its own, i.e. another archive precedes this one and other readers may report
1473
+ * its entries instead). The other reasons are the checks that
1472
1474
  * `strictness: "strict"` rejects with {@link ERR_AMBIGUOUS_ARCHIVE}: when the effective strictness tolerates
1473
1475
  * one of them and the evidence is already in hand, the same reason string is deposited as a warning instead —
1474
1476
  * {@link WARNING_APPENDED_DATA}, {@link WARNING_PREPENDED_DATA}, {@link WARNING_TRAILING_CENTRAL_DIRECTORY_DATA},
@@ -1592,10 +1594,17 @@ export interface ZipReaderGetEntriesOptions
1592
1594
  export interface GetEntriesOptions {
1593
1595
  /**
1594
1596
  * The encoding of the filename of the entry.
1597
+ *
1598
+ * The option is ignored when the general purpose bit 11 is set in the header of the entry: such a
1599
+ * filename is always decoded as UTF-8. It is only read when the bit is not set, and the filename is
1600
+ * then decoded as IBM Code Page 437 when the option is not set either.
1595
1601
  */
1596
1602
  filenameEncoding?: string;
1597
1603
  /**
1598
1604
  * The encoding of the comment of the entry.
1605
+ *
1606
+ * The option is ignored when the general purpose bit 11 is set in the header of the entry, see
1607
+ * {@link GetEntriesOptions#filenameEncoding}.
1599
1608
  */
1600
1609
  commentEncoding?: string;
1601
1610
  /**
@@ -3242,6 +3251,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3242
3251
  * Note that this option only sets the flag, it does not ensure that the file names are in the correct
3243
3252
  * encoding: when it is set to `false`, the names are still encoded in UTF-8 unless the
3244
3253
  * {@link ZipWriterConstructorOptions#encodeText} option is also set to encode them in the intended code page.
3254
+ * Setting it to `false` alone therefore produces an archive whose file names are mislabeled, holding UTF-8
3255
+ * bytes announced as Code Page 437: the names holding characters outside of ASCII are decoded incorrectly
3256
+ * by the readers honoring the flag, including {@link ZipReader} unless
3257
+ * {@link GetEntriesOptions#filenameEncoding} is set to `"utf-8"`.
3245
3258
  *
3246
3259
  * @defaultValue true
3247
3260
  */
@@ -3456,6 +3469,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
3456
3469
  /**
3457
3470
  * The function called for encoding the filename and the comment of the entry.
3458
3471
  *
3472
+ * zip.js encodes them in UTF-8 when the option is not set, so it must be set to write them in another
3473
+ * code page, together with {@link ZipWriterConstructorOptions#useUnicodeFileNames} set to `false` to
3474
+ * announce them as Code Page 437 instead of UTF-8.
3475
+ *
3459
3476
  * @param text The text to encode.
3460
3477
  * @param type The type of the encoded text, `"filename"` or `"comment"`.
3461
3478
  * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
@@ -3543,6 +3560,9 @@ export class ZipEntry {
3543
3560
  * @remarks It is the size of the raw compressed content when the entry has been imported with the
3544
3561
  * `passThrough` option set to `true`, since the entry holds the compressed data in that case. The
3545
3562
  * uncompressed size of the original entry remains available in {@link ZipEntry#data}.
3563
+ *
3564
+ * It is updated by the `{@link ZipFileEntry}#replace*()` methods, and it is `0` for an entry holding
3565
+ * a `ReadableStream` instance, whose size is only known once the entry has been read.
3546
3566
  */
3547
3567
  uncompressedSize: number;
3548
3568
  /**
@@ -3592,6 +3612,12 @@ export class ZipEntry {
3592
3612
  /**
3593
3613
  * Set the name of the entry
3594
3614
  *
3615
+ * @remarks A name holding `"/"` is split into path components, like the name passed to a
3616
+ * `{@link ZipDirectoryEntry}#add*()` method, so it moves the entry into the directories it names,
3617
+ * creating them when they do not exist. Renaming an entry to the name it already has does nothing.
3618
+ * Renaming it onto an existing sibling throws an {@link ERR_ENTRY_EXISTS} error, and renaming it
3619
+ * into itself or into one of its descendants throws.
3620
+ *
3595
3621
  * @param name The new name of the entry.
3596
3622
  */
3597
3623
  rename(name: string): void;
@@ -3617,6 +3643,11 @@ export class ZipEntry {
3617
3643
 
3618
3644
  /**
3619
3645
  * Represents a file entry in the zip (Filesystem API).
3646
+ *
3647
+ * @remarks A `{@link ZipFileEntry}#replace*()` method describes the entry with the content it is
3648
+ * given: it updates {@link ZipEntry#uncompressedSize} and clears the pass-through state of an entry
3649
+ * imported with the {@link ZipReaderOptions#passThrough} option, since the bytes copied verbatim are
3650
+ * gone. Replacing the content of an entry therefore keeps {@link ZipFS#getExportedSize} exact.
3620
3651
  */
3621
3652
  export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
3622
3653
  /**
@@ -3735,6 +3766,10 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
3735
3766
  /**
3736
3767
  * Replaces the content of the entry with a `ReadableStream` instance
3737
3768
  *
3769
+ * @remarks The size of a `ReadableStream` instance is unknown, so the entry reports an undetermined
3770
+ * size, like an entry added with {@link ZipDirectoryEntry#addReadable}. {@link ZipFS#getExportedSize}
3771
+ * then throws an {@link ERR_UNDETERMINED_SIZE} error instead of returning a size it cannot predict.
3772
+ *
3738
3773
  * @param readable The `ReadableStream` instance.
3739
3774
  */
3740
3775
  replaceReadable(readable: ReadableStream): void;
@@ -3742,6 +3777,13 @@ export class ZipFileEntry<ReaderType, WriterType> extends ZipEntry {
3742
3777
 
3743
3778
  /**
3744
3779
  * Represents a directory entry in the zip (Filesystem API).
3780
+ *
3781
+ * @remarks The `name` passed to an `{@link ZipDirectoryEntry}#add*()` method is split into path
3782
+ * components, exactly like the filename of an imported entry, so `addText("a/b.txt", text)` adds
3783
+ * `"b.txt"` to the `"a"` directory and creates that directory when it does not exist. Empty
3784
+ * components and `"."` components are ignored. The directories created that way are navigable like
3785
+ * any other entry but are not written when the tree is exported, so the zip file holds the same
3786
+ * entries whichever way the path was built.
3745
3787
  */
3746
3788
  export class ZipDirectoryEntry extends ZipEntry {
3747
3789
  /**
@@ -3914,7 +3956,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3914
3956
  */
3915
3957
  importBlob(
3916
3958
  blob: Blob,
3917
- options?: ZipReaderConstructorOptions
3959
+ options?: ZipDirectoryEntryImportOptions
3918
3960
  ): Promise<[ZipEntry]>;
3919
3961
  /**
3920
3962
  * Extracts a zip file provided as a Data URI `string` encoded in Base64 into the entry
@@ -3927,7 +3969,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3927
3969
  */
3928
3970
  importData64URI(
3929
3971
  dataURI: string,
3930
- options?: ZipReaderConstructorOptions
3972
+ options?: ZipDirectoryEntryImportOptions
3931
3973
  ): Promise<[ZipEntry]>;
3932
3974
  /**
3933
3975
  * Extracts a zip file provided as a `Uint8Array` instance into the entry
@@ -3940,7 +3982,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3940
3982
  */
3941
3983
  importUint8Array(
3942
3984
  array: Uint8Array,
3943
- options?: ZipReaderConstructorOptions
3985
+ options?: ZipDirectoryEntryImportOptions
3944
3986
  ): Promise<[ZipEntry]>;
3945
3987
  /**
3946
3988
  * Extracts a zip file fetched from a URL into the entry
@@ -3970,7 +4012,7 @@ export class ZipDirectoryEntry extends ZipEntry {
3970
4012
  */
3971
4013
  importReadable(
3972
4014
  readable: ReadableStream,
3973
- options?: ZipReaderConstructorOptions
4015
+ options?: ZipDirectoryEntryImportOptions
3974
4016
  ): Promise<[ZipEntry]>;
3975
4017
  /**
3976
4018
  * Extracts a zip file provided via a custom {@link Reader} instance or a {@link ZipReader} instance into
@@ -4006,7 +4048,7 @@ export class ZipDirectoryEntry extends ZipEntry {
4006
4048
  | ReadableReader[]
4007
4049
  | ReadableStream[]
4008
4050
  | ZipReader<unknown>,
4009
- options?: ZipReaderConstructorOptions
4051
+ options?: ZipDirectoryEntryImportOptions
4010
4052
  ): Promise<[ZipEntry]>;
4011
4053
  /**
4012
4054
  * Returns a `Blob` instance containing a zip file of the entry and its descendants
@@ -4110,7 +4152,9 @@ export class ZipDirectoryEntry extends ZipEntry {
4110
4152
  * This happens when `usdz` is set, since the alignment padding depends on the offset of each
4111
4153
  * entry, and when the archive exceeds 4GB, since the offsets recorded in the central directory
4112
4154
  * are then extended to 64 bits. Passing `bufferedWrite: false` makes both determinable again,
4113
- * as does exporting a directory whose children are all files. It is thrown as well when
4155
+ * as does exporting a directory whose children are all files. A name holding `"/"` creates the
4156
+ * directories it names, so `addText("a/b.txt", text)` builds a tree whose children are not all
4157
+ * files, even though the directories created that way are not written. It is thrown as well when
4114
4158
  * `signCentralDirectory` is set, the length of the signature being unknown until it is computed.
4115
4159
  *
4116
4160
  * @param options The options.
@@ -4120,11 +4164,39 @@ export class ZipDirectoryEntry extends ZipEntry {
4120
4164
  getExportedSize(options?: ZipDirectoryEntryExportOptions): Promise<number>;
4121
4165
  }
4122
4166
 
4167
+ /**
4168
+ * Represents the options passed to `{@link ZipDirectoryEntry}#import*()`.
4169
+ */
4170
+ export interface ZipDirectoryEntryImportOptions
4171
+ extends ZipReaderConstructorOptions {
4172
+ /**
4173
+ * The policy applied when two entries of the imported zip file claim the same node of the tree
4174
+ *
4175
+ * @remarks
4176
+ * The tree indexes the entries by path, whereas a zip file stores a flat list of filenames, so two
4177
+ * entries can claim one node: they can hold the same filename, hold filenames differing only by the
4178
+ * path components ignored when building the tree (e.g. `"a/b.txt"` and `"./a/b.txt"`), or one can be
4179
+ * a file and the other a directory holding it (e.g. `"a"` and `"a/b.txt"`).
4180
+ *
4181
+ * `"throw"` refuses the zip file with an {@link ERR_DUPLICATE_IMPORTED_ENTRY} error, whose `cause`
4182
+ * property holds the {@link EntryMetaData} instance of the entry that could not be imported. The
4183
+ * filesystem is left unchanged, i.e. the entries imported before the error are removed and the
4184
+ * content held before the import is restored.
4185
+ *
4186
+ * `"keep-first"` ignores the entry claiming a node already taken, and `"keep-last"` replaces the
4187
+ * entry holding the node, which is the behavior of most zip tools. The entries that do not collide
4188
+ * are imported in both cases.
4189
+ *
4190
+ * @defaultValue "throw"
4191
+ */
4192
+ duplicates?: "throw" | "keep-first" | "keep-last";
4193
+ }
4194
+
4123
4195
  /**
4124
4196
  * Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
4125
4197
  */
4126
4198
  export interface ZipDirectoryEntryImportHttpOptions
4127
- extends ZipReaderConstructorOptions,
4199
+ extends ZipDirectoryEntryImportOptions,
4128
4200
  HttpOptions {}
4129
4201
 
4130
4202
  /**
@@ -4777,6 +4849,16 @@ export const ERR_ZIP_CRYPTO_LAST_MOD_DATE: string;
4777
4849
  * Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
4778
4850
  */
4779
4851
  export const ERR_ENTRY_EXISTS: string;
4852
+ /**
4853
+ * Duplicate imported entry error (thrown by `{@link ZipDirectoryEntry}#import*()` when two entries of the
4854
+ * zip file claim the same node of the tree and the {@link ZipDirectoryEntryImportOptions#duplicates} option
4855
+ * is set to `"throw"`)
4856
+ */
4857
+ export const ERR_DUPLICATE_IMPORTED_ENTRY: string;
4858
+ /**
4859
+ * Invalid duplicates option error
4860
+ */
4861
+ export const ERR_INVALID_DUPLICATES: string;
4780
4862
  /**
4781
4863
  * Readable stream already consumed error (thrown by the filesystem API when a readable stream is read more than once)
4782
4864
  */
@@ -4842,6 +4924,19 @@ export const WARNING_APPENDED_DATA: string;
4842
4924
  * {@link ERR_AMBIGUOUS_ARCHIVE} under `strictness: "strict"`
4843
4925
  */
4844
4926
  export const WARNING_PREPENDED_DATA: string;
4927
+ /**
4928
+ * Warning reason: the data prepended before the zip file holds a central directory of its own, i.e. the zip file
4929
+ * is preceded by another archive rather than by an arbitrary prefix such as a self-extracting stub
4930
+ * (see {@link ZipReader#warnings})
4931
+ *
4932
+ * @remarks
4933
+ * Readers disagree on such files: zip.js reads the last archive, as Info-ZIP `unzip` and Python's `zipfile` do,
4934
+ * whereas 7-Zip reads the first one and reports the rest as data after the end of the archive. The archive is
4935
+ * therefore ambiguous, and the entries reported here may not be the entries another tool reports. It is always
4936
+ * accompanied by {@link WARNING_PREPENDED_DATA}, which alone does not distinguish this case from a benign prefix.
4937
+ * Use `strictness: "strict"` to reject these archives instead, at the cost of also rejecting benign prefixes.
4938
+ */
4939
+ export const WARNING_PREPENDED_CENTRAL_DIRECTORY: string;
4845
4940
  /**
4846
4941
  * Warning reason: data lies between the end of the central directory records and the end of central directory
4847
4942
  * record, either inside the declared central directory length or beyond it (see {@link ZipReader#warnings});