@preventive/archive 1.4.0 → 1.5.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/tar.d.ts CHANGED
@@ -1,9 +1,29 @@
1
- // The typed contract for archive/tar.js, hand-written: keep it name for name
2
- // with tar.js, and change it in the same commit as the signature.
1
+ /**
2
+ * Strict in-memory tar, as GNU tar 1.35 writes it
3
+ *
4
+ * ```js
5
+ * import { pack, unpack } from '@preventive/archive/tar.js'
6
+ * import { packStream, unpackStream } from '@preventive/archive/tar.js'
7
+ * ```
8
+ *
9
+ * Writing and reading refuse alike:
10
+ * - a name that is not a clean relative path: absolute, with an empty or `..` segment, a drive letter,
11
+ * a backslash, a control or bidi character, or over 4096 bytes (255 a segment)
12
+ * - a name that repeats as anything but the same fields and data again
13
+ * - an entry inside a non-directory
14
+ * - a symlink whose target climbs above the root, past `symlinksAbove`, or passes through a non-directory
15
+ * - a hard link to no earlier entry; a hard link to a symlink is held to that symlink's rules at its own name
16
+ *
17
+ * @module @preventive/archive/tar.js
18
+ */
3
19
 
4
- // tar's entry types under tar-stream's names, but for a 'hardlink', which
5
- // tar-stream calls a 'link': a hard link to an earlier entry. A
6
- // 'contiguous-file' is a file for every purpose here.
20
+ export { ArchiveError } from './src/error.js';
21
+
22
+ /**
23
+ * An entry's type, under tar-stream's names but for `'hardlink'` (its `'link'`)
24
+ *
25
+ * A `'contiguous-file'` is a file for every purpose here.
26
+ */
7
27
  export type EntryType =
8
28
  | 'file'
9
29
  | 'directory'
@@ -12,156 +32,165 @@ export type EntryType =
12
32
  | 'fifo'
13
33
  | 'character-device'
14
34
  | 'block-device'
15
- | 'contiguous-file'
35
+ | 'contiguous-file';
16
36
 
17
- // An entry read out of an archive. `name` is a relative path with `.`
18
- // segments and a directory's trailing slash dropped, or `.` for the
19
- // archive root itself, which only a directory names; `mtime` is whole
20
- // seconds since the epoch; `linkname` is '' and the device numbers 0
21
- // where they do not apply; `data` is empty for anything but a file, and
22
- // a view over the archive bytes where they arrived in one piece.
23
- //
24
- // Beside those, what the archive itself says. `storedName` and
25
- // `storedLinkname` are the name and link target as stored, before any
26
- // cleaning -- `./a` where `name` is `a`, `dir/` where it is `dir`, a ustar
27
- // prefix joined on -- and passed every check the cleaned ones did; only a
28
- // hard link's target is ever cleaned, so a symlink's is its `linkname`.
29
- // `pax` is the records of the entry's own pax header and `globalPax` those
30
- // of the global header it is under, each in the order stored, those read
31
- // into the fields above among them; the fields take an entry's own record
32
- // over the global one. A Map is shared -- every entry under one global
33
- // header has its, every entry without a header the one empty Map -- so it
34
- // cannot be changed. A value this package does not read is as stored,
35
- // unchecked, and may hold any character, a control one included.
36
- // `extended` is the extended headers read since the entry before it, in
37
- // the order stored, each its kind -- its own pax header, a global one,
38
- // GNU's long name and long link -- and its magic; the one empty list where
39
- // none was, and frozen, as a Map is. An extended header with no entry after
40
- // it is refused, a global one too unless `trailingGlobal` takes it. `magic`
41
- // is the entry's own header's: POSIX's 'ustar', or 'gnu', under which the
42
- // bytes ustar holds a name's prefix in are GNU's own and not read as one.
43
- // `typeflag` and `storedMode` are its header's type flag and mode as
44
- // stored: '\0' where `type` is a 'file' as '0' is, and the file type bits
45
- // among the permission bits `mode` keeps. `octal` is whether every numeric
46
- // field of its header -- an extended one's too -- holds octal digits, as
47
- // POSIX writes them, rather than nothing or GNU's base 256, both of which
48
- // are read too.
37
+ /**
38
+ * An entry read from an archive: the fields of `EntryInput`, then what the archive stored
39
+ */
49
40
  export interface Entry {
50
- name: string
51
- type: EntryType
52
- mode: number
53
- uid: number
54
- gid: number
55
- mtime: number
56
- uname: string
57
- gname: string
58
- linkname: string
59
- devmajor: number
60
- devminor: number
61
- data: Uint8Array
62
- storedName: string
63
- storedLinkname: string
64
- pax: ReadonlyMap<string, string>
65
- globalPax: ReadonlyMap<string, string>
66
- extended: readonly ExtendedHeader[]
67
- magic: 'ustar' | 'gnu'
68
- typeflag: string
69
- storedMode: number
70
- octal: boolean
41
+ /** Relative path with `.` segments and a trailing slash dropped, or `.` for the root directory */
42
+ name: string;
43
+ type: EntryType;
44
+ /** Permission bits */
45
+ mode: number;
46
+ uid: number;
47
+ gid: number;
48
+ /** Whole seconds since the epoch */
49
+ mtime: number;
50
+ uname: string;
51
+ gname: string;
52
+ /** The target of a symlink, as stored, or of a hard link, cleaned as `name` is; else `''` */
53
+ linkname: string;
54
+ /** A device's numbers, else 0 */
55
+ devmajor: number;
56
+ devminor: number;
57
+ /** A file's contents, else empty; a view of the input where one chunk held it whole */
58
+ data: Uint8Array;
59
+ /** `name` before cleaning, with any ustar prefix joined on */
60
+ storedName: string;
61
+ /** `linkname` before cleaning */
62
+ storedLinkname: string;
63
+ /**
64
+ * The entry's own pax records, in stored order, read-only and shared by every entry without any.
65
+ * A value no field is read from is unchecked and may hold any character.
66
+ */
67
+ pax: ReadonlyMap<string, string>;
68
+ /** The global pax records in effect, shared by every entry under them; `pax` wins over these */
69
+ globalPax: ReadonlyMap<string, string>;
70
+ /** The extended headers since the previous entry, in stored order; frozen */
71
+ extended: readonly ExtendedHeader[];
72
+ /** The header's magic; under `'gnu'` there is no ustar name prefix */
73
+ magic: 'ustar' | 'gnu';
74
+ /** The header's type flag, such as `'\0'` or `'0'` for a `'file'` */
75
+ typeflag: string;
76
+ /** The header's mode, file type bits included */
77
+ storedMode: number;
78
+ /** Whether every number in the header is octal digits, as POSIX writes, rather than blank or GNU's base 256 */
79
+ octal: boolean;
71
80
  }
72
81
 
73
- // An extended header, as `extended` lists them.
82
+ /**
83
+ * A pax header of an entry's own, a global one, or GNU's long name or long link
84
+ */
74
85
  export interface ExtendedHeader {
75
- kind: 'pax' | 'global' | 'longname' | 'longlink'
76
- magic: 'ustar' | 'gnu'
77
- octal: boolean
86
+ kind: 'pax' | 'global' | 'longname' | 'longlink';
87
+ magic: 'ustar' | 'gnu';
88
+ octal: boolean;
78
89
  }
79
90
 
80
- // An entry to write. `name` is cleaned as above, so `./a`, `a/./b` and
81
- // `dir/` are taken; only a directory may end in a slash or name the root.
82
- // `type` defaults to 'file'; `mode` to 0o644, 0o755 for a directory, 0o777
83
- // for a symlink; owners to 0 with empty names; `mtime` to 0. `linkname` is
84
- // the target of a symlink or hard link. An entry read out is one to write
85
- // as it is; what it stored is not written again, only these fields.
91
+ /**
92
+ * An entry to write; an `Entry` read is one to write as is, what it stored aside
93
+ *
94
+ * `mode` defaults to 0o644 (0o755 for a directory, 0o777 for a symlink), owners to 0 with no names,
95
+ * `mtime` to 0.
96
+ */
86
97
  export interface EntryInput {
87
- name: string
88
- type?: EntryType
89
- data?: Uint8Array
90
- mode?: number
91
- uid?: number
92
- gid?: number
93
- mtime?: number
94
- uname?: string
95
- gname?: string
96
- linkname?: string
97
- devmajor?: number
98
- devminor?: number
98
+ /** Cleaned as `Entry.name`, so `./a` and `dir/` are taken; only a directory may end in a slash or be `.` */
99
+ name: string;
100
+ /** Default: `'file'` */
101
+ type?: EntryType;
102
+ data?: Uint8Array;
103
+ mode?: number;
104
+ uid?: number;
105
+ gid?: number;
106
+ mtime?: number;
107
+ uname?: string;
108
+ gname?: string;
109
+ /** The target of a symlink or a hard link */
110
+ linkname?: string;
111
+ devmajor?: number;
112
+ devminor?: number;
99
113
  }
100
114
 
101
- // GNU tar's names: 'gnu' is what plain `tar` writes and the default here,
102
- // 'ustar' refuses what it cannot hold, 'pax' holds everything.
103
- export type Format = 'gnu' | 'ustar' | 'pax'
104
-
105
- // `symlinksAbove` lets a relative symlink target climb up to that many
106
- // levels above the archive's root, none by default: for a directory
107
- // archived on its own, as GitHub archives a tree, that links to the files
108
- // of the tree it was cut from -- `LICENSE -> ../../LICENSE` in a tree's
109
- // `packages/a/`, archived under one top directory, climbs one. Past the root
110
- // the archive cannot tell where a target leads, not even back into itself
111
- // by the name it is extracted under, so what it passes through there is
112
- // the caller's to know. An absolute target is refused regardless, and what
113
- // one call reads with it, another writes with it.
114
115
  export interface SymlinkOptions {
115
- symlinksAbove?: number
116
+ /**
117
+ * How many levels above the root a relative symlink target may climb (default: 0)
118
+ *
119
+ * 1 lets `LICENSE -> ../../LICENSE` out of `packages/a/` archived under one top directory, as GitHub
120
+ * archives a subtree. What a target passes through past the root is for the caller to trust.
121
+ */
122
+ symlinksAbove?: number;
116
123
  }
117
124
 
118
- // `blocking` is tar's -b: zero padding to a multiple of that many 512-byte
119
- // blocks, 20 by default; 1 pads nothing past the two zero end blocks.
125
+ /**
126
+ * GNU tar's formats: `'gnu'`, as plain `tar` writes; `'ustar'`, refusing what it cannot hold; `'pax'`
127
+ */
128
+ export type Format = 'gnu' | 'ustar' | 'pax';
129
+
120
130
  export interface PackOptions extends SymlinkOptions {
121
- format?: Format
122
- blocking?: number
131
+ /** Default: `'gnu'` */
132
+ format?: Format;
133
+ /** tar's `-b`: zeros to a multiple of this many 512-byte blocks (default: 20) */
134
+ blocking?: number;
123
135
  }
124
136
 
125
- // `maxEntries` bounds how many entries the archive may hold, every kind
126
- // counted and a repeat again, its extended headers not: past it the call
127
- // throws with `limited` set, at the header that crosses it, before that
128
- // entry is read. No bound by default.
129
- // `trailingGlobal` takes a global header with no entry after it, as GNU tar
130
- // lists one: as nothing, carried in no entry's `extended`. By default it is
131
- // refused, as any extended header with no entry to describe is. A pax or
132
- // long name header with nothing after it is refused either way.
133
137
  export interface UnpackOptions extends SymlinkOptions {
134
- maxEntries?: number
135
- trailingGlobal?: boolean
138
+ /**
139
+ * How many entries to read, each kind and repeat counted, extended headers not (default: no limit)
140
+ *
141
+ * Past it, throws with `limited` set at that entry's header.
142
+ */
143
+ maxEntries?: number;
144
+ /** Take a global header with no entry after it as nothing, as GNU tar does (default: refused) */
145
+ trailingGlobal?: boolean;
136
146
  }
137
147
 
138
- // Both refuse a name that repeats as a different entry -- anything but the
139
- // same fields and the same bytes again, however either was stored -- an
140
- // entry inside something that is not a directory, a symlink whose target
141
- // climbs out of the archive, further than `symlinksAbove` lets it, or
142
- // passes through anything in it but a directory, and a hard link to no
143
- // earlier entry. A hard link to a symlink, directly or down a chain of hard
144
- // links, is a second name for it, and its target is walked again from that
145
- // name, which a target safe where the symlink sits need not survive.
146
- export function pack(entries: Iterable<EntryInput>, options?: PackOptions): Uint8Array
147
- export function unpack(bytes: Uint8Array, options?: UnpackOptions): Entry[]
148
+ /**
149
+ * Write a tar archive
150
+ *
151
+ * Byte for byte what GNU tar writes with `--owner=0 --group=0 --numeric-owner` and, for pax,
152
+ * `--pax-option=delete=atime,delete=ctime`; where it would cut or substitute, this refuses.
153
+ *
154
+ * @param entries - The entries, in order
155
+ * @param options - Packing options
156
+ * @returns The archive
157
+ */
158
+ export function pack(entries: Iterable<EntryInput>, options?: PackOptions): Uint8Array;
148
159
 
149
- // The same a piece at a time, as async generators over a plain or an
150
- // async iterable. unpackStream yields each entry as it is read, however
151
- // many a chunk holds, its `data` a view of the chunk wherever one holds it
152
- // whole: an archive whole in memory, given as one chunk, is read an entry
153
- // at a time and nothing of it copied. A stream keeps no entry's data, so a
154
- // name that repeats with the same fields is refused there, and such an
155
- // archive is for the in-memory call. packStream yields each entry's `data`
156
- // as the very array it was given.
157
- export function packStream(entries: Iterable<EntryInput> | AsyncIterable<EntryInput>, options?: PackOptions): AsyncGenerator<Uint8Array, void, undefined>
158
- export function unpackStream(chunks: Iterable<Uint8Array> | AsyncIterable<Uint8Array>, options?: UnpackOptions): AsyncGenerator<Entry, void, undefined>
160
+ /**
161
+ * Read a tar archive
162
+ *
163
+ * Takes the extended headers GNU tar writes and refuses sparse entries.
164
+ *
165
+ * @param bytes - The archive
166
+ * @param options - Unpacking options
167
+ * @returns The entries, in order
168
+ */
169
+ export function unpack(bytes: Uint8Array, options?: UnpackOptions): Entry[];
159
170
 
160
- // `offset` is where in the archive the reader gave up; unset from the writer.
161
- // `limited` is true where a bound the caller set stopped it, rather than
162
- // anything wrong with the archive.
163
- export class ArchiveError extends Error {
164
- constructor(detail: string, offset?: number, options?: { limited?: boolean })
165
- offset: number | undefined
166
- limited: boolean
167
- }
171
+ /**
172
+ * `pack()` a chunk at a time, each entry's `data` yielded as the same array
173
+ *
174
+ * @param entries - The entries, in order
175
+ * @param options - Packing options
176
+ * @returns The archive's chunks
177
+ */
178
+ export function packStream(
179
+ entries: Iterable<EntryInput> | AsyncIterable<EntryInput>,
180
+ options?: PackOptions
181
+ ): AsyncGenerator<Uint8Array, void, undefined>;
182
+
183
+ /**
184
+ * `unpack()` an entry at a time, each yielded as it is read
185
+ *
186
+ * `data` is a view of a chunk wherever one holds it whole, so an archive in one chunk is not copied.
187
+ * No entry's data is kept, so a name that repeats is refused: such an archive is for `unpack()`.
188
+ *
189
+ * @param chunks - The archive's chunks
190
+ * @param options - Unpacking options
191
+ * @returns The entries, in order
192
+ */
193
+ export function unpackStream(
194
+ chunks: Iterable<Uint8Array> | AsyncIterable<Uint8Array>,
195
+ options?: UnpackOptions
196
+ ): AsyncGenerator<Entry, void, undefined>;
package/tar.js CHANGED
@@ -1,19 +1,3 @@
1
- // The tar half of @preventive/archive, reached as
2
- // `@preventive/archive/tar.js`; the zip half is beside it, and the two
3
- // share only the modules at the top of src/: the name rules, the entry
4
- // shape, and the byte and text helpers. Inside, archive/ runs on browser
5
- // APIs alone, plus @exodus/bytes for hardened UTF-8 and CRC-32
6
- // (self-contained.test.js enforces both).
7
-
8
- // Entries in, one Uint8Array out: byte for byte what GNU tar writes.
9
- export { pack } from './src/tar/pack.js'
10
-
11
- // An archive in, its entries out, under the same rules pack() writes by.
12
- export { unpack } from './src/tar/unpack.js'
13
-
14
- // The same a chunk or an entry at a time, as async generators over a
15
- // plain or an async iterable.
16
- export { packStream } from './src/tar/pack.js'
17
- export { unpackStream } from './src/tar/unpack.js'
18
-
1
+ export { pack, packStream } from './src/tar/pack.js'
2
+ export { unpack, unpackStream } from './src/tar/unpack.js'
19
3
  export { ArchiveError } from './src/error.js'
package/zip.d.ts CHANGED
@@ -1,120 +1,132 @@
1
- // The typed contract for archive/zip.js, hand-written: keep it name for name
2
- // with zip.js, and change it in the same commit as the signature.
1
+ /**
2
+ * Strict in-memory zip, as Info-ZIP lays it out, deflated by the platform's `CompressionStream`
3
+ *
4
+ * ```js
5
+ * import { unzip, unzipStream, zip } from '@preventive/archive/zip.js'
6
+ * ```
7
+ *
8
+ * Names and symlinks are held to the rules of `@preventive/archive/tar.js`, but for `UnzipOptions.symlinkChains`.
9
+ * Neither writing nor reading takes zip64, so an archive holds at most 65534 entries and stays under 4 GiB.
10
+ *
11
+ * @module @preventive/archive/zip.js
12
+ */
3
13
 
4
- // A 'symlink' is stored the way Info-ZIP stores one: its target as the
5
- // entry's data, its type in the Unix mode.
6
- export type EntryType = 'file' | 'directory' | 'symlink'
14
+ export { ArchiveError } from './src/error.js';
7
15
 
8
- // An entry read out of an archive. `name` is a relative path with `.`
9
- // segments and a directory's trailing slash dropped, or `.` for the
10
- // archive root itself, which only a directory names; `mode` is the Unix
11
- // permission bits, or the usual default where the maker recorded none;
12
- // `mtime` is whole seconds since the epoch, exact where the archive
13
- // carries an extended timestamp and DOS time read as UTC otherwise;
14
- // `linkname` is '' for anything but a symlink; `data` is empty for
15
- // anything but a file, and a view over the archive bytes where the entry
16
- // was stored and the archive is in memory rather than a Blob.
17
- // `storedName` is the name as the archive stores it, before any cleaning --
18
- // `./a` where `name` is `a`, `dir/` where it is `dir` -- and passed every
19
- // check the cleaned one did. A symlink's target is never rewritten, only
20
- // checked, so `linkname` is as stored.
21
- //
22
- // Beside those, what the central directory stores of the entry, for a
23
- // reader that follows another program's reading of it: `system` is the
24
- // maker's, the upper byte of the version made by, 3 for Unix, whose
25
- // attributes alone `mode` is read from; `version` the one needed to
26
- // extract, `flags` the general purpose bits, `internalAttributes` and
27
- // `attributes` the internal and external ones, each as stored; `extra` the
28
- // extra fields, each its id and data, in the order stored.
16
+ /**
17
+ * A `'symlink'` is stored as Info-ZIP stores one: its target as data, its type in the Unix mode
18
+ */
19
+ export type EntryType = 'file' | 'directory' | 'symlink';
20
+
21
+ /**
22
+ * An entry read from an archive: the fields of `EntryInput`, then what the central directory stored
23
+ */
29
24
  export interface Entry {
30
- name: string
31
- type: EntryType
32
- mode: number
33
- mtime: number
34
- linkname: string
35
- data: Uint8Array
36
- storedName: string
37
- system: number
38
- version: number
39
- flags: number
40
- internalAttributes: number
41
- attributes: number
42
- extra: ExtraField[]
25
+ /** Relative path with `.` segments and a trailing slash dropped, or `.` for the root directory */
26
+ name: string;
27
+ type: EntryType;
28
+ /** Permission bits, or the default where the maker recorded none */
29
+ mode: number;
30
+ /** Whole seconds since the epoch: exact from an extended timestamp, else DOS time read as UTC */
31
+ mtime: number;
32
+ /** A symlink's target, as stored, else `''` */
33
+ linkname: string;
34
+ /** A file's contents, else empty; a view of the archive where stored and given as a `Uint8Array` */
35
+ data: Uint8Array;
36
+ /** `name` before cleaning */
37
+ storedName: string;
38
+ /** The maker's system, the upper byte of "version made by": 3 for Unix, whose alone `mode` is read */
39
+ system: number;
40
+ /** The version needed to extract */
41
+ version: number;
42
+ /** The general purpose bits */
43
+ flags: number;
44
+ internalAttributes: number;
45
+ /** The external attributes */
46
+ attributes: number;
47
+ /** The extra fields, in stored order */
48
+ extra: ExtraField[];
43
49
  }
44
50
 
45
51
  export interface ExtraField {
46
- id: number
47
- data: Uint8Array
52
+ id: number;
53
+ data: Uint8Array;
48
54
  }
49
55
 
50
- // An entry to write. `name` is cleaned as above, so `./a`, `a/./b` and
51
- // `dir/` are taken; only a directory may end in a slash or name the root.
52
- // `type` defaults to 'file'; `mode` to 0o644, 0o755 for a directory, 0o777
53
- // for a symlink; `mtime` to 1980-01-01T00:00:00Z, the earliest DOS time,
54
- // and must lie between that and 2038-01-19, which the exact timestamp
55
- // holds. `linkname` is the target of a symlink. An entry read out is one
56
- // to write as it is; its stored name is not written again, its name is.
56
+ /**
57
+ * An entry to write; an `Entry` read is one to write as is, what it stored aside
58
+ */
57
59
  export interface EntryInput {
58
- name: string
59
- type?: EntryType
60
- data?: Uint8Array
61
- mode?: number
62
- mtime?: number
63
- linkname?: string
60
+ /** Cleaned as `Entry.name`, so `./a` and `dir/` are taken; only a directory may end in a slash or be `.` */
61
+ name: string;
62
+ /** Default: `'file'` */
63
+ type?: EntryType;
64
+ data?: Uint8Array;
65
+ /** Default: 0o644, or 0o755 for a directory and 0o777 for a symlink */
66
+ mode?: number;
67
+ /** From 1980-01-01, the earliest DOS time and the default, to 2038-01-19, the latest extended timestamp */
68
+ mtime?: number;
69
+ /** A symlink's target */
70
+ linkname?: string;
64
71
  }
65
72
 
66
- // `symlinksAbove` lets a relative symlink target climb up to that many
67
- // levels above the archive's root, none by default, as tar.d.ts tells: past
68
- // the root, what a target passes through is the caller's to know. An
69
- // absolute target is refused regardless, and what one call reads with it,
70
- // another writes with it.
71
73
  export interface SymlinkOptions {
72
- symlinksAbove?: number
74
+ /** How many levels above the root a relative symlink target may climb, as in `tar.js` (default: 0) */
75
+ symlinksAbove?: number;
73
76
  }
74
77
 
75
- // 'deflate' (the default) deflates each file and keeps the result only
76
- // where it is smaller, as Info-ZIP does; 'store' compresses nothing.
77
78
  export interface ZipOptions extends SymlinkOptions {
78
- method?: 'deflate' | 'store'
79
+ /** `'deflate'` keeps a file deflated only where that is smaller, as Info-ZIP does (default); `'store'` does not */
80
+ method?: 'deflate' | 'store';
79
81
  }
80
82
 
81
- // `limit` bounds the entries' sizes, all of them together, in bytes --
82
- // stored and deflated alike, a symlink's target included. Each entry has to
83
- // come out at exactly the size it declares, so the sum is checked against
84
- // the central directory before anything is inflated, and past the limit
85
- // the call rejects, with `limited` set. No limit by default.
86
83
  export interface UnzipOptions extends SymlinkOptions {
87
- limit?: number
84
+ /**
85
+ * How many bytes the entries may come to together, a symlink's target counted (default: no limit)
86
+ *
87
+ * Each has to inflate to exactly its declared size, so this is checked before anything is inflated;
88
+ * past it, rejects with `limited` set.
89
+ */
90
+ limit?: number;
91
+ /**
92
+ * Whether a symlink's target may pass through other symlinks, as a macOS framework's do (default: false)
93
+ *
94
+ * Each is then followed once every entry is read, and refused where it climbs past `symlinksAbove`, passes
95
+ * through a non-directory, loops or passes more than 40 symlinks. `unzipStream()` refuses it.
96
+ */
97
+ symlinkChains?: boolean;
88
98
  }
89
99
 
90
- // Both refuse a name that repeats as a different entry -- anything but the
91
- // same fields and the same bytes again, however either was stored -- an
92
- // entry inside something that is not a directory, and a symlink whose
93
- // target climbs out of the archive, further than `symlinksAbove` lets it,
94
- // or passes through anything in it but a directory. unzip() also refuses
95
- // an entry carrying a Unicode path extra field, a second name that other
96
- // readers take over the one in the header. Neither takes or makes zip64,
97
- // so an archive holds at most 65534 entries and stays under 4 GiB.
98
- export function zip(entries: Iterable<EntryInput>, options?: ZipOptions): Promise<Uint8Array>
99
- export function unzip(bytes: Uint8Array, options?: UnzipOptions): Promise<Entry[]>
100
+ /**
101
+ * Write a zip archive
102
+ *
103
+ * @param entries - The entries, in order
104
+ * @param options - Zip options
105
+ * @returns The archive
106
+ */
107
+ export function zip(entries: Iterable<EntryInput>, options?: ZipOptions): Promise<Uint8Array>;
100
108
 
101
- // The same one entry at a time, as an async generator: over the archive in
102
- // memory, or over a Blob -- a File, or a file opened with fs.openAsBlob --
103
- // read a range at a time, so that no more of it is held than the entries'
104
- // names and the entry it is on, whose data is then its own rather than a
105
- // view of the archive.
106
- // The layout is checked whole before the first entry comes out; what an
107
- // entry holds is checked as it is reached, so a bad one ends the stream
108
- // after the ones before it. A stream keeps no entry's data, so a name that
109
- // repeats with the same fields is refused there, and such an archive is
110
- // for the in-memory call.
111
- export function unzipStream(archive: Uint8Array | Blob, options?: UnzipOptions): AsyncGenerator<Entry, void, undefined>
109
+ /**
110
+ * Read a zip archive
111
+ *
112
+ * Every header, size and checksum is checked against every other, and the entries have to tile the archive.
113
+ * An entry with a Unicode path extra field, a second name other readers take over its own, is refused.
114
+ *
115
+ * @param bytes - The archive
116
+ * @param options - Unzip options
117
+ * @returns The entries, in central directory order
118
+ */
119
+ export function unzip(bytes: Uint8Array, options?: UnzipOptions): Promise<Entry[]>;
112
120
 
113
- // `offset` is where in the archive the reader gave up; unset from the writer.
114
- // `limited` is true where a bound the caller set stopped it, rather than
115
- // anything wrong with the archive.
116
- export class ArchiveError extends Error {
117
- constructor(detail: string, offset?: number, options?: { limited?: boolean })
118
- offset: number | undefined
119
- limited: boolean
120
- }
121
+ /**
122
+ * `unzip()` an entry at a time, over the archive in memory or a `Blob` read a range at a time
123
+ *
124
+ * From a `Blob`, such as a `File` or `fs.openAsBlob()`, no more is held than the names and the entry at hand.
125
+ * The layout is checked before the first entry, each entry's contents as it is reached. No entry's data is
126
+ * kept, so a name that repeats is refused: such an archive is for `unzip()`.
127
+ *
128
+ * @param archive - The archive
129
+ * @param options - Unzip options
130
+ * @returns The entries, in central directory order
131
+ */
132
+ export function unzipStream(archive: Uint8Array | Blob, options?: UnzipOptions): AsyncGenerator<Entry, void, undefined>;
package/zip.js CHANGED
@@ -1,21 +1,3 @@
1
- // The zip half of @preventive/archive, reached as
2
- // `@preventive/archive/zip.js`. Deflate is the platform's
3
- // CompressionStream and DecompressionStream, raw; the rest is shared with
4
- // the tar half or browser APIs alone.
5
-
6
- // Entries in, one Uint8Array out. Strict: a duplicate name, a name that
7
- // could reach outside the archive, or a value the format cannot hold is
8
- // refused rather than written down wrong.
9
1
  export { zip } from './src/zip/zip.js'
10
-
11
- // An archive in, its entries out, under the same rules -- and with every
12
- // header, size and checksum in it checked against every other, and the
13
- // sizes all together held to a limit where one is given.
14
- export { unzip } from './src/zip/unzip.js'
15
-
16
- // The same an entry at a time, as an async generator over the archive in
17
- // memory or over a Blob -- a File, or a file opened with fs.openAsBlob --
18
- // read a range at a time, so no more of it is held than the entry it is on.
19
- export { unzipStream } from './src/zip/unzip.js'
20
-
2
+ export { unzip, unzipStream } from './src/zip/unzip.js'
21
3
  export { ArchiveError } from './src/error.js'