@zip.js/zip.js 2.8.49 → 2.8.51

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
@@ -1201,9 +1201,10 @@ export interface GetEntriesOptions {
1201
1201
  *
1202
1202
  * @param value The raw text value.
1203
1203
  * @param encoding The encoding of the text.
1204
+ * @param type The type of the decoded text, `"filename"` or `"comment"`.
1204
1205
  * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
1205
1206
  */
1206
- decodeText?(value: Uint8Array, encoding: string): string | undefined;
1207
+ decodeText?(value: Uint8Array, encoding: string, type: "filename" | "comment"): string | undefined;
1207
1208
  /**
1208
1209
  * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
1209
1210
  * tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
@@ -1237,6 +1238,42 @@ export interface GetEntriesOptions {
1237
1238
  * @defaultValue "balanced"
1238
1239
  */
1239
1240
  strictness?: "strict" | "balanced" | "tolerant";
1241
+ /**
1242
+ * How strictly the filename of each entry should be validated. A rejected name throws an
1243
+ * {@link ERR_UNSAFE_FILENAME} error carrying the offending name in its `filename` property.
1244
+ *
1245
+ * - `"strict"`: reject the names rejected by `"balanced"`, plus the names that do not map cleanly to a file
1246
+ * path, i.e. empty names and names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`).
1247
+ * - `"balanced"`: reject names that would escape the directory they are extracted into, i.e. names containing
1248
+ * a `".."` path component, and absolute names, i.e. names starting with `"/"`, with a drive letter (e.g.
1249
+ * `"C:/file.txt"`) or with two backslashes (UNC paths).
1250
+ * - `"tolerant"`: never reject a name.
1251
+ *
1252
+ * A backslash is never interpreted as a path separator: it is a valid filename character on UNIX systems, and
1253
+ * it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with another
1254
+ * charset.
1255
+ *
1256
+ * Names are validated, never rewritten, so the filename reported for an entry always matches its central
1257
+ * directory record.
1258
+ *
1259
+ * @defaultValue The value of {@link GetEntriesOptions#strictness}.
1260
+ */
1261
+ filenameValidation?: "strict" | "balanced" | "tolerant";
1262
+ /**
1263
+ * The function called for normalizing the filename of each entry, e.g. to repair the names rejected by
1264
+ * {@link GetEntriesOptions#filenameValidation}.
1265
+ *
1266
+ * It is called with the decoded filename, after {@link GetEntriesOptions#decodeText} and before the name is
1267
+ * validated, so a name it fails to repair is still rejected. The returned name becomes the name of the entry:
1268
+ * it is used to detect directory entries by their trailing `"/"`, and to detect duplicate filenames when
1269
+ * {@link GetEntriesOptions#checkAmbiguity} is set, so two names normalized into the same name are reported as
1270
+ * an {@link ERR_AMBIGUOUS_ARCHIVE} error instead of silently shadowing each other. The raw filename remains
1271
+ * available in {@link EntryMetaData#rawFilename}.
1272
+ *
1273
+ * @param filename The decoded filename.
1274
+ * @returns The normalized filename or `undefined` to keep the decoded filename.
1275
+ */
1276
+ normalizeFilename?(filename: string): string | undefined;
1240
1277
  /**
1241
1278
  * The maximum number of bytes tolerated after the zip structure before the archive is rejected. Defaults to
1242
1279
  * `0` when {@link GetEntriesOptions#strictness} is `"strict"`, `65535` when it is `"balanced"`, and `Infinity`
@@ -1613,6 +1650,27 @@ export interface EntryError extends Error {
1613
1650
  * The id of the related {@link ZipEntry} (filesystem API).
1614
1651
  */
1615
1652
  entryId?: number;
1653
+ /**
1654
+ * The name of the related {@link ZipEntry}, or of the related `FileSystemHandle` when importing
1655
+ * one (filesystem API). Set by {@link ZipDirectoryEntry#addFileSystemHandle} and
1656
+ * {@link ZipDirectoryEntry#exportFileSystemHandle}, which rethrow the original error rather than
1657
+ * wrapping it, so its `message` stays comparable to the exported `ERR_*` constants.
1658
+ */
1659
+ entryName?: string;
1660
+ /**
1661
+ * The other entries that also failed, when {@link ZipDirectoryEntry#exportFileSystemHandle} runs
1662
+ * with `concurrent` set to `true` and more than one entry fails (filesystem API). The error it is
1663
+ * set on is not repeated in the list, and failures raised deeper in the tree are flattened into
1664
+ * it, so the list holds every failure of the export except this one.
1665
+ */
1666
+ entryErrors?: EntryError[];
1667
+ /**
1668
+ * The names of the files {@link ZipDirectoryEntry#exportFileSystemHandle} finished writing before
1669
+ * it failed, relative to the exported entry (filesystem API). Directories are not listed. Every
1670
+ * other file of the export is either missing or empty, so this is the only way to tell a file the
1671
+ * export completed from one it created but never filled.
1672
+ */
1673
+ exportedEntryNames?: string[];
1616
1674
  }
1617
1675
  /**
1618
1676
  * Represents the metadata of an entry in a zip file (Core API).
@@ -2497,9 +2555,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
2497
2555
  * The function called for encoding the filename and the comment of the entry.
2498
2556
  *
2499
2557
  * @param text The text to encode.
2558
+ * @param type The type of the encoded text, `"filename"` or `"comment"`.
2500
2559
  * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
2501
2560
  */
2502
- encodeText?(text: string): Uint8Array | undefined;
2561
+ encodeText?(text: string, type: "filename" | "comment"): Uint8Array | undefined;
2503
2562
  }
2504
2563
 
2505
2564
  /**
@@ -2756,6 +2815,23 @@ export class ZipDirectoryEntry extends ZipEntry {
2756
2815
  * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
2757
2816
  */
2758
2817
  getChildByName(name: string): ZipEntry | undefined;
2818
+ /**
2819
+ * Gets the children of the directory
2820
+ *
2821
+ * @remarks The returned array is a snapshot taken when the method is called: entries added or removed
2822
+ * afterwards are not reflected, and an entry removed while the array is being iterated is still present
2823
+ * but detached from the filesystem.
2824
+ *
2825
+ * With `recursive`, the descendants are ordered level by level, i.e. the children of a directory come
2826
+ * before the children of its subdirectories, like the result of `readdir(path, { recursive: true })` in
2827
+ * Node.js. This is also the order in which `{@link ZipDirectoryEntry}#export*()` writes them.
2828
+ *
2829
+ * Unlike {@link FS#entries}, the directory itself is not included and removed entries leave no empty slot.
2830
+ *
2831
+ * @param options The options.
2832
+ * @returns The array of {@link ZipEntry} instances.
2833
+ */
2834
+ getChildren(options?: ZipDirectoryEntryGetChildrenOptions): ZipEntry[];
2759
2835
  /**
2760
2836
  * Adds a directory
2761
2837
  *
@@ -2867,6 +2943,10 @@ export class ZipDirectoryEntry extends ZipEntry {
2867
2943
  /**
2868
2944
  * Adds an entry with content provided via a `FileSystemHandle` instance
2869
2945
  *
2946
+ * If a handle cannot be read, the original error is rethrown unmodified as an {@link EntryError},
2947
+ * whose {@link EntryError#entryName} is the path of the handle that failed, relative to the parent
2948
+ * of `fileSystemHandle`.
2949
+ *
2870
2950
  * @param fileSystemHandle The `fileSystemHandle` instance.
2871
2951
  * @param options The options.
2872
2952
  * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
@@ -2930,6 +3010,11 @@ export class ZipDirectoryEntry extends ZipEntry {
2930
3010
  *
2931
3011
  * @param reader The {@link Reader} instance.
2932
3012
  * @param options The options.
3013
+ *
3014
+ * @remarks The filename of each entry is split into path components to build the tree of entries. Empty
3015
+ * components and `"."` components are ignored, so `"a//b.txt"`, `"./a/b.txt"` and `"a/./b.txt"` all produce
3016
+ * the same `"a/b.txt"` entry. Filenames are normalized and validated beforehand, see
3017
+ * {@link GetEntriesOptions#normalizeFilename} and {@link GetEntriesOptions#filenameValidation}.
2933
3018
  */
2934
3019
  importZip(
2935
3020
  reader:
@@ -2978,6 +3063,28 @@ export class ZipDirectoryEntry extends ZipEntry {
2978
3063
  /**
2979
3064
  * Writes the entry and its descendants into a directory as files and sub-directories via the File System Access API (e.g. the Origin Private File System). Files are streamed and directories are merged into the target; colliding files are overwritten. This is the inverse of {@link ZipDirectoryEntry#addFileSystemHandle}.
2980
3065
  *
3066
+ * If an entry cannot be written, the original error is rethrown unmodified as an {@link EntryError},
3067
+ * whose {@link EntryError#entryName} is the name of the entry that failed, relative to this entry.
3068
+ *
3069
+ * The export is not atomic and nothing is rolled back, because the target is merged into rather
3070
+ * than replaced: a file that already existed cannot be restored once overwritten. On failure the
3071
+ * target is left as follows, and {@link EntryError#exportedEntryNames} lists the files that
3072
+ * completed:
3073
+ * - files written before the failure are left in place, complete and valid;
3074
+ * - a file whose write started but did not finish is left empty, because it is created before its
3075
+ * content is streamed; this includes the entry that failed and, with `concurrent`, every entry
3076
+ * cancelled alongside it;
3077
+ * - files that already existed in the target keep their previous content unless they were
3078
+ * overwritten in full;
3079
+ * - entries not started yet are missing, as are the directories that would have held them.
3080
+ *
3081
+ * Running the same export again is the supported way to recover, since directories are merged and
3082
+ * files are overwritten.
3083
+ *
3084
+ * @remarks An entry flagged as a symbolic link by its {@link EntryMetaData#externalFileAttributes} is written
3085
+ * as a regular file whose content is the path of the link target, because the File System Access API cannot
3086
+ * create symbolic links.
3087
+ *
2981
3088
  * @param directoryHandle The target `FileSystemDirectoryHandle` instance.
2982
3089
  * @param options The options.
2983
3090
  * @returns A promise resolving to the target `FileSystemDirectoryHandle` instance.
@@ -3010,6 +3117,18 @@ export interface ZipDirectoryEntryImportHttpOptions
3010
3117
  extends ZipReaderConstructorOptions,
3011
3118
  HttpOptions {}
3012
3119
 
3120
+ /**
3121
+ * Represents the options passed to {@link ZipDirectoryEntry#getChildren} and {@link FS#getChildren}.
3122
+ */
3123
+ export interface ZipDirectoryEntryGetChildrenOptions {
3124
+ /**
3125
+ * `true` to return all the descendants of the directory instead of its direct children only.
3126
+ *
3127
+ * @defaultValue false
3128
+ */
3129
+ recursive?: boolean;
3130
+ }
3131
+
3013
3132
  /**
3014
3133
  * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
3015
3134
  */
@@ -3038,6 +3157,11 @@ export interface ZipDirectoryEntryExportFileSystemHandleOptions
3038
3157
  /**
3039
3158
  * `true` to write independent files concurrently instead of one after another.
3040
3159
  *
3160
+ * When an entry fails, the entries still in flight are cancelled and the ones not started yet are
3161
+ * skipped, so a failed export stops as early as it does when writing one file after another. An
3162
+ * entry whose write has already been requested may still be created, because the File System
3163
+ * Access API cannot cancel a pending `getFileHandle` or `getDirectoryHandle` call.
3164
+ *
3041
3165
  * @defaultValue false
3042
3166
  */
3043
3167
  concurrent?: boolean;
@@ -3065,6 +3189,7 @@ export interface FS
3065
3189
  extends Pick<
3066
3190
  ZipDirectoryEntry,
3067
3191
  | "getChildByName"
3192
+ | "getChildren"
3068
3193
  | "addDirectory"
3069
3194
  | "addText"
3070
3195
  | "addBlob"
@@ -3322,6 +3447,26 @@ export const ERR_AMBIGUOUS_ARCHIVE: string;
3322
3447
  * Encryption Specification, which is not supported.
3323
3448
  */
3324
3449
  export const ERR_ENCRYPTED_CENTRAL_DIRECTORY: string;
3450
+ /**
3451
+ * Unsafe filename error
3452
+ *
3453
+ * @remarks Thrown when reading an archive containing an entry whose filename is rejected by
3454
+ * {@link GetEntriesOptions#filenameValidation}. The thrown error carries the offending name in its `filename`
3455
+ * property.
3456
+ */
3457
+ export const ERR_UNSAFE_FILENAME: string;
3458
+ /**
3459
+ * Invalid strictness error (thrown when the `strictness` option is not `"strict"`, `"balanced"` or `"tolerant"`)
3460
+ */
3461
+ export const ERR_INVALID_STRICTNESS: string;
3462
+ /**
3463
+ * Invalid filenameValidation error (thrown when the `filenameValidation` option is not `"strict"`, `"balanced"` or `"tolerant"`)
3464
+ */
3465
+ export const ERR_INVALID_FILENAME_VALIDATION: string;
3466
+ /**
3467
+ * Invalid maxAppendedDataSize error (thrown when the `maxAppendedDataSize` option is not a number greater than or equal to 0)
3468
+ */
3469
+ export const ERR_INVALID_MAX_APPENDED_DATA_SIZE: string;
3325
3470
  /**
3326
3471
  * Iteration completed too soon error
3327
3472
  */
@@ -3374,6 +3519,17 @@ export const ERR_INVALID_MSDOS_ATTRIBUTES: string;
3374
3519
  * Invalid msdosAttributes error (thrown when the `msdosAttributes` option is not an object with boolean flags)
3375
3520
  */
3376
3521
  export const ERR_INVALID_MSDOS_DATA: string;
3522
+ /**
3523
+ * Invalid level error (thrown when the `level` option is not an integer in the range 0..9)
3524
+ */
3525
+ export const ERR_INVALID_LEVEL: string;
3526
+ /**
3527
+ * Invalid password error (thrown when the `password` option is not a string, or the `rawPassword` option is not a `Uint8Array`)
3528
+ *
3529
+ * @remarks A value of another type would silently produce an unencrypted archive, and a `rawPassword` passed as a string
3530
+ * would produce an archive that cannot be opened with the equivalent {@link ZipWriterConstructorOptions#password}.
3531
+ */
3532
+ export const ERR_INVALID_PASSWORD_TYPE: string;
3377
3533
  /**
3378
3534
  * Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
3379
3535
  */
@@ -3382,6 +3538,15 @@ export const ERR_ENTRY_EXISTS: string;
3382
3538
  * Readable stream already consumed error (thrown by the filesystem API when a readable stream is read more than once)
3383
3539
  */
3384
3540
  export const ERR_READABLE_CONSUMED: string;
3541
+ /**
3542
+ * Aborted operation error (thrown by {@link ZipDirectoryEntry#exportFileSystemHandle} when it is aborted via
3543
+ * {@link ZipReaderOptions#signal} on platforms which do not support the `reason` argument of
3544
+ * `AbortController#abort()`)
3545
+ *
3546
+ * @remarks The reason passed by the caller is discarded by these platforms and cannot be recovered, so a
3547
+ * `DOMException` named `AbortError` carrying this message is thrown in its place.
3548
+ */
3549
+ export const ERR_ABORTED: string;
3385
3550
  /**
3386
3551
  * Unsupported context error (thrown when {@link createSyncAccessHandleTempStream} is used outside a dedicated worker)
3387
3552
  */
package/index.d.ts CHANGED
@@ -1201,9 +1201,10 @@ export interface GetEntriesOptions {
1201
1201
  *
1202
1202
  * @param value The raw text value.
1203
1203
  * @param encoding The encoding of the text.
1204
+ * @param type The type of the decoded text, `"filename"` or `"comment"`.
1204
1205
  * @returns The decoded text value or `undefined` if the raw text value should be decoded by zip.js.
1205
1206
  */
1206
- decodeText?(value: Uint8Array, encoding: string): string | undefined;
1207
+ decodeText?(value: Uint8Array, encoding: string, type: "filename" | "comment"): string | undefined;
1207
1208
  /**
1208
1209
  * `true` to throw an {@link ERR_AMBIGUOUS_ARCHIVE} error when the archive could be parsed differently by other
1209
1210
  * tools. This detects data before or after the zip structure (e.g. a self-extracting archive stub or a
@@ -1237,6 +1238,42 @@ export interface GetEntriesOptions {
1237
1238
  * @defaultValue "balanced"
1238
1239
  */
1239
1240
  strictness?: "strict" | "balanced" | "tolerant";
1241
+ /**
1242
+ * How strictly the filename of each entry should be validated. A rejected name throws an
1243
+ * {@link ERR_UNSAFE_FILENAME} error carrying the offending name in its `filename` property.
1244
+ *
1245
+ * - `"strict"`: reject the names rejected by `"balanced"`, plus the names that do not map cleanly to a file
1246
+ * path, i.e. empty names and names containing a `"."` path component or an empty one (e.g. `"a//b.txt"`).
1247
+ * - `"balanced"`: reject names that would escape the directory they are extracted into, i.e. names containing
1248
+ * a `".."` path component, and absolute names, i.e. names starting with `"/"`, with a drive letter (e.g.
1249
+ * `"C:/file.txt"`) or with two backslashes (UNC paths).
1250
+ * - `"tolerant"`: never reject a name.
1251
+ *
1252
+ * A backslash is never interpreted as a path separator: it is a valid filename character on UNIX systems, and
1253
+ * it also occurs as the trail byte of legitimate double-byte filenames (e.g. CP932) decoded with another
1254
+ * charset.
1255
+ *
1256
+ * Names are validated, never rewritten, so the filename reported for an entry always matches its central
1257
+ * directory record.
1258
+ *
1259
+ * @defaultValue The value of {@link GetEntriesOptions#strictness}.
1260
+ */
1261
+ filenameValidation?: "strict" | "balanced" | "tolerant";
1262
+ /**
1263
+ * The function called for normalizing the filename of each entry, e.g. to repair the names rejected by
1264
+ * {@link GetEntriesOptions#filenameValidation}.
1265
+ *
1266
+ * It is called with the decoded filename, after {@link GetEntriesOptions#decodeText} and before the name is
1267
+ * validated, so a name it fails to repair is still rejected. The returned name becomes the name of the entry:
1268
+ * it is used to detect directory entries by their trailing `"/"`, and to detect duplicate filenames when
1269
+ * {@link GetEntriesOptions#checkAmbiguity} is set, so two names normalized into the same name are reported as
1270
+ * an {@link ERR_AMBIGUOUS_ARCHIVE} error instead of silently shadowing each other. The raw filename remains
1271
+ * available in {@link EntryMetaData#rawFilename}.
1272
+ *
1273
+ * @param filename The decoded filename.
1274
+ * @returns The normalized filename or `undefined` to keep the decoded filename.
1275
+ */
1276
+ normalizeFilename?(filename: string): string | undefined;
1240
1277
  /**
1241
1278
  * The maximum number of bytes tolerated after the zip structure before the archive is rejected. Defaults to
1242
1279
  * `0` when {@link GetEntriesOptions#strictness} is `"strict"`, `65535` when it is `"balanced"`, and `Infinity`
@@ -1613,6 +1650,27 @@ export interface EntryError extends Error {
1613
1650
  * The id of the related {@link ZipEntry} (filesystem API).
1614
1651
  */
1615
1652
  entryId?: number;
1653
+ /**
1654
+ * The name of the related {@link ZipEntry}, or of the related `FileSystemHandle` when importing
1655
+ * one (filesystem API). Set by {@link ZipDirectoryEntry#addFileSystemHandle} and
1656
+ * {@link ZipDirectoryEntry#exportFileSystemHandle}, which rethrow the original error rather than
1657
+ * wrapping it, so its `message` stays comparable to the exported `ERR_*` constants.
1658
+ */
1659
+ entryName?: string;
1660
+ /**
1661
+ * The other entries that also failed, when {@link ZipDirectoryEntry#exportFileSystemHandle} runs
1662
+ * with `concurrent` set to `true` and more than one entry fails (filesystem API). The error it is
1663
+ * set on is not repeated in the list, and failures raised deeper in the tree are flattened into
1664
+ * it, so the list holds every failure of the export except this one.
1665
+ */
1666
+ entryErrors?: EntryError[];
1667
+ /**
1668
+ * The names of the files {@link ZipDirectoryEntry#exportFileSystemHandle} finished writing before
1669
+ * it failed, relative to the exported entry (filesystem API). Directories are not listed. Every
1670
+ * other file of the export is either missing or empty, so this is the only way to tell a file the
1671
+ * export completed from one it created but never filled.
1672
+ */
1673
+ exportedEntryNames?: string[];
1616
1674
  }
1617
1675
  /**
1618
1676
  * Represents the metadata of an entry in a zip file (Core API).
@@ -2497,9 +2555,10 @@ export interface ZipWriterConstructorOptions extends WorkerConfiguration {
2497
2555
  * The function called for encoding the filename and the comment of the entry.
2498
2556
  *
2499
2557
  * @param text The text to encode.
2558
+ * @param type The type of the encoded text, `"filename"` or `"comment"`.
2500
2559
  * @returns The encoded text or `undefined` if the text should be encoded by zip.js.
2501
2560
  */
2502
- encodeText?(text: string): Uint8Array | undefined;
2561
+ encodeText?(text: string, type: "filename" | "comment"): Uint8Array | undefined;
2503
2562
  }
2504
2563
 
2505
2564
  /**
@@ -2756,6 +2815,23 @@ export class ZipDirectoryEntry extends ZipEntry {
2756
2815
  * @returns A {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance (use the {@link ZipFileEntry#directory} and {@link ZipDirectoryEntry#directory} properties to differentiate entries).
2757
2816
  */
2758
2817
  getChildByName(name: string): ZipEntry | undefined;
2818
+ /**
2819
+ * Gets the children of the directory
2820
+ *
2821
+ * @remarks The returned array is a snapshot taken when the method is called: entries added or removed
2822
+ * afterwards are not reflected, and an entry removed while the array is being iterated is still present
2823
+ * but detached from the filesystem.
2824
+ *
2825
+ * With `recursive`, the descendants are ordered level by level, i.e. the children of a directory come
2826
+ * before the children of its subdirectories, like the result of `readdir(path, { recursive: true })` in
2827
+ * Node.js. This is also the order in which `{@link ZipDirectoryEntry}#export*()` writes them.
2828
+ *
2829
+ * Unlike {@link FS#entries}, the directory itself is not included and removed entries leave no empty slot.
2830
+ *
2831
+ * @param options The options.
2832
+ * @returns The array of {@link ZipEntry} instances.
2833
+ */
2834
+ getChildren(options?: ZipDirectoryEntryGetChildrenOptions): ZipEntry[];
2759
2835
  /**
2760
2836
  * Adds a directory
2761
2837
  *
@@ -2867,6 +2943,10 @@ export class ZipDirectoryEntry extends ZipEntry {
2867
2943
  /**
2868
2944
  * Adds an entry with content provided via a `FileSystemHandle` instance
2869
2945
  *
2946
+ * If a handle cannot be read, the original error is rethrown unmodified as an {@link EntryError},
2947
+ * whose {@link EntryError#entryName} is the path of the handle that failed, relative to the parent
2948
+ * of `fileSystemHandle`.
2949
+ *
2870
2950
  * @param fileSystemHandle The `fileSystemHandle` instance.
2871
2951
  * @param options The options.
2872
2952
  * @returns A promise resolving to an array of {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instances.
@@ -2930,6 +3010,11 @@ export class ZipDirectoryEntry extends ZipEntry {
2930
3010
  *
2931
3011
  * @param reader The {@link Reader} instance.
2932
3012
  * @param options The options.
3013
+ *
3014
+ * @remarks The filename of each entry is split into path components to build the tree of entries. Empty
3015
+ * components and `"."` components are ignored, so `"a//b.txt"`, `"./a/b.txt"` and `"a/./b.txt"` all produce
3016
+ * the same `"a/b.txt"` entry. Filenames are normalized and validated beforehand, see
3017
+ * {@link GetEntriesOptions#normalizeFilename} and {@link GetEntriesOptions#filenameValidation}.
2933
3018
  */
2934
3019
  importZip(
2935
3020
  reader:
@@ -2978,6 +3063,28 @@ export class ZipDirectoryEntry extends ZipEntry {
2978
3063
  /**
2979
3064
  * Writes the entry and its descendants into a directory as files and sub-directories via the File System Access API (e.g. the Origin Private File System). Files are streamed and directories are merged into the target; colliding files are overwritten. This is the inverse of {@link ZipDirectoryEntry#addFileSystemHandle}.
2980
3065
  *
3066
+ * If an entry cannot be written, the original error is rethrown unmodified as an {@link EntryError},
3067
+ * whose {@link EntryError#entryName} is the name of the entry that failed, relative to this entry.
3068
+ *
3069
+ * The export is not atomic and nothing is rolled back, because the target is merged into rather
3070
+ * than replaced: a file that already existed cannot be restored once overwritten. On failure the
3071
+ * target is left as follows, and {@link EntryError#exportedEntryNames} lists the files that
3072
+ * completed:
3073
+ * - files written before the failure are left in place, complete and valid;
3074
+ * - a file whose write started but did not finish is left empty, because it is created before its
3075
+ * content is streamed; this includes the entry that failed and, with `concurrent`, every entry
3076
+ * cancelled alongside it;
3077
+ * - files that already existed in the target keep their previous content unless they were
3078
+ * overwritten in full;
3079
+ * - entries not started yet are missing, as are the directories that would have held them.
3080
+ *
3081
+ * Running the same export again is the supported way to recover, since directories are merged and
3082
+ * files are overwritten.
3083
+ *
3084
+ * @remarks An entry flagged as a symbolic link by its {@link EntryMetaData#externalFileAttributes} is written
3085
+ * as a regular file whose content is the path of the link target, because the File System Access API cannot
3086
+ * create symbolic links.
3087
+ *
2981
3088
  * @param directoryHandle The target `FileSystemDirectoryHandle` instance.
2982
3089
  * @param options The options.
2983
3090
  * @returns A promise resolving to the target `FileSystemDirectoryHandle` instance.
@@ -3010,6 +3117,18 @@ export interface ZipDirectoryEntryImportHttpOptions
3010
3117
  extends ZipReaderConstructorOptions,
3011
3118
  HttpOptions {}
3012
3119
 
3120
+ /**
3121
+ * Represents the options passed to {@link ZipDirectoryEntry#getChildren} and {@link FS#getChildren}.
3122
+ */
3123
+ export interface ZipDirectoryEntryGetChildrenOptions {
3124
+ /**
3125
+ * `true` to return all the descendants of the directory instead of its direct children only.
3126
+ *
3127
+ * @defaultValue false
3128
+ */
3129
+ recursive?: boolean;
3130
+ }
3131
+
3013
3132
  /**
3014
3133
  * Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
3015
3134
  */
@@ -3038,6 +3157,11 @@ export interface ZipDirectoryEntryExportFileSystemHandleOptions
3038
3157
  /**
3039
3158
  * `true` to write independent files concurrently instead of one after another.
3040
3159
  *
3160
+ * When an entry fails, the entries still in flight are cancelled and the ones not started yet are
3161
+ * skipped, so a failed export stops as early as it does when writing one file after another. An
3162
+ * entry whose write has already been requested may still be created, because the File System
3163
+ * Access API cannot cancel a pending `getFileHandle` or `getDirectoryHandle` call.
3164
+ *
3041
3165
  * @defaultValue false
3042
3166
  */
3043
3167
  concurrent?: boolean;
@@ -3065,6 +3189,7 @@ export interface FS
3065
3189
  extends Pick<
3066
3190
  ZipDirectoryEntry,
3067
3191
  | "getChildByName"
3192
+ | "getChildren"
3068
3193
  | "addDirectory"
3069
3194
  | "addText"
3070
3195
  | "addBlob"
@@ -3322,6 +3447,26 @@ export const ERR_AMBIGUOUS_ARCHIVE: string;
3322
3447
  * Encryption Specification, which is not supported.
3323
3448
  */
3324
3449
  export const ERR_ENCRYPTED_CENTRAL_DIRECTORY: string;
3450
+ /**
3451
+ * Unsafe filename error
3452
+ *
3453
+ * @remarks Thrown when reading an archive containing an entry whose filename is rejected by
3454
+ * {@link GetEntriesOptions#filenameValidation}. The thrown error carries the offending name in its `filename`
3455
+ * property.
3456
+ */
3457
+ export const ERR_UNSAFE_FILENAME: string;
3458
+ /**
3459
+ * Invalid strictness error (thrown when the `strictness` option is not `"strict"`, `"balanced"` or `"tolerant"`)
3460
+ */
3461
+ export const ERR_INVALID_STRICTNESS: string;
3462
+ /**
3463
+ * Invalid filenameValidation error (thrown when the `filenameValidation` option is not `"strict"`, `"balanced"` or `"tolerant"`)
3464
+ */
3465
+ export const ERR_INVALID_FILENAME_VALIDATION: string;
3466
+ /**
3467
+ * Invalid maxAppendedDataSize error (thrown when the `maxAppendedDataSize` option is not a number greater than or equal to 0)
3468
+ */
3469
+ export const ERR_INVALID_MAX_APPENDED_DATA_SIZE: string;
3325
3470
  /**
3326
3471
  * Iteration completed too soon error
3327
3472
  */
@@ -3374,6 +3519,17 @@ export const ERR_INVALID_MSDOS_ATTRIBUTES: string;
3374
3519
  * Invalid msdosAttributes error (thrown when the `msdosAttributes` option is not an object with boolean flags)
3375
3520
  */
3376
3521
  export const ERR_INVALID_MSDOS_DATA: string;
3522
+ /**
3523
+ * Invalid level error (thrown when the `level` option is not an integer in the range 0..9)
3524
+ */
3525
+ export const ERR_INVALID_LEVEL: string;
3526
+ /**
3527
+ * Invalid password error (thrown when the `password` option is not a string, or the `rawPassword` option is not a `Uint8Array`)
3528
+ *
3529
+ * @remarks A value of another type would silently produce an unencrypted archive, and a `rawPassword` passed as a string
3530
+ * would produce an archive that cannot be opened with the equivalent {@link ZipWriterConstructorOptions#password}.
3531
+ */
3532
+ export const ERR_INVALID_PASSWORD_TYPE: string;
3377
3533
  /**
3378
3534
  * Entry already exists error (thrown by the filesystem API when adding an entry whose filename already exists)
3379
3535
  */
@@ -3382,6 +3538,15 @@ export const ERR_ENTRY_EXISTS: string;
3382
3538
  * Readable stream already consumed error (thrown by the filesystem API when a readable stream is read more than once)
3383
3539
  */
3384
3540
  export const ERR_READABLE_CONSUMED: string;
3541
+ /**
3542
+ * Aborted operation error (thrown by {@link ZipDirectoryEntry#exportFileSystemHandle} when it is aborted via
3543
+ * {@link ZipReaderOptions#signal} on platforms which do not support the `reason` argument of
3544
+ * `AbortController#abort()`)
3545
+ *
3546
+ * @remarks The reason passed by the caller is discarded by these platforms and cannot be recovered, so a
3547
+ * `DOMException` named `AbortError` carrying this message is thrown in its place.
3548
+ */
3549
+ export const ERR_ABORTED: string;
3385
3550
  /**
3386
3551
  * Unsupported context error (thrown when {@link createSyncAccessHandleTempStream} is used outside a dedicated worker)
3387
3552
  */