@preventive/archive 1.3.0 → 1.4.1
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/compression.d.ts +50 -30
- package/compression.js +0 -5
- package/package.json +2 -1
- package/src/bytes.js +0 -2
- package/src/compression.js +36 -93
- package/src/entry.js +3 -9
- package/src/error.d.ts +10 -0
- package/src/error.js +4 -8
- package/src/names.js +30 -120
- package/src/tar/header.js +17 -43
- package/src/tar/pack.js +33 -48
- package/src/tar/pax.js +6 -11
- package/src/tar/unpack.js +75 -132
- package/src/text.js +6 -32
- package/src/zip/format.js +10 -29
- package/src/zip/unzip.js +47 -93
- package/src/zip/zip.js +24 -32
- package/tar.d.ts +166 -137
- package/tar.js +2 -18
- package/zip.d.ts +106 -82
- package/zip.js +1 -19
package/tar.d.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
export function
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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,101 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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`. Neither writing nor reading
|
|
9
|
+
* 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
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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.
|
|
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
|
+
*/
|
|
21
24
|
export interface Entry {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ExtraField {
|
|
52
|
+
id: number;
|
|
53
|
+
data: Uint8Array;
|
|
29
54
|
}
|
|
30
55
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
// for a symlink; `mtime` to 1980-01-01T00:00:00Z, the earliest DOS time,
|
|
35
|
-
// and must lie between that and 2038-01-19, which the exact timestamp
|
|
36
|
-
// holds. `linkname` is the target of a symlink. An entry read out is one
|
|
37
|
-
// 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
|
+
*/
|
|
38
59
|
export interface EntryInput {
|
|
39
|
-
name
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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;
|
|
45
71
|
}
|
|
46
72
|
|
|
47
|
-
// `symlinksAbove` lets a relative symlink target climb up to that many
|
|
48
|
-
// levels above the archive's root, none by default, as tar.d.ts tells: past
|
|
49
|
-
// the root, what a target passes through is the caller's to know. An
|
|
50
|
-
// absolute target is refused regardless, and what one call reads with it,
|
|
51
|
-
// another writes with it.
|
|
52
73
|
export interface SymlinkOptions {
|
|
53
|
-
|
|
74
|
+
/** How many levels above the root a relative symlink target may climb, as in `tar.js` (default: 0) */
|
|
75
|
+
symlinksAbove?: number;
|
|
54
76
|
}
|
|
55
77
|
|
|
56
|
-
// 'deflate' (the default) deflates each file and keeps the result only
|
|
57
|
-
// where it is smaller, as Info-ZIP does; 'store' compresses nothing.
|
|
58
78
|
export interface ZipOptions extends SymlinkOptions {
|
|
59
|
-
|
|
79
|
+
/** `'deflate'` keeps a file deflated only where that is smaller, as Info-ZIP does (default); `'store'` does not */
|
|
80
|
+
method?: 'deflate' | 'store';
|
|
60
81
|
}
|
|
61
82
|
|
|
62
|
-
// `limit` bounds the entries' sizes, all of them together, in bytes --
|
|
63
|
-
// stored and deflated alike, a symlink's target included. Each entry has to
|
|
64
|
-
// come out at exactly the size it declares, so the sum is checked against
|
|
65
|
-
// the central directory before anything is inflated, and past the limit
|
|
66
|
-
// the call rejects, with `limited` set. No limit by default.
|
|
67
83
|
export interface UnzipOptions extends SymlinkOptions {
|
|
68
|
-
|
|
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;
|
|
69
91
|
}
|
|
70
92
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export function zip(entries: Iterable<EntryInput>, options?: ZipOptions): Promise<Uint8Array>
|
|
80
|
-
export function unzip(bytes: Uint8Array, options?: UnzipOptions): Promise<Entry[]>
|
|
93
|
+
/**
|
|
94
|
+
* Write a zip archive
|
|
95
|
+
*
|
|
96
|
+
* @param entries - The entries, in order
|
|
97
|
+
* @param options - Zip options
|
|
98
|
+
* @returns The archive
|
|
99
|
+
*/
|
|
100
|
+
export function zip(entries: Iterable<EntryInput>, options?: ZipOptions): Promise<Uint8Array>;
|
|
81
101
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
export function
|
|
102
|
+
/**
|
|
103
|
+
* Read a zip archive
|
|
104
|
+
*
|
|
105
|
+
* Every header, size and checksum is checked against every other, and the entries have to tile the archive.
|
|
106
|
+
* An entry with a Unicode path extra field, a second name other readers take over its own, is refused.
|
|
107
|
+
*
|
|
108
|
+
* @param bytes - The archive
|
|
109
|
+
* @param options - Unzip options
|
|
110
|
+
* @returns The entries, in central directory order
|
|
111
|
+
*/
|
|
112
|
+
export function unzip(bytes: Uint8Array, options?: UnzipOptions): Promise<Entry[]>;
|
|
93
113
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
114
|
+
/**
|
|
115
|
+
* `unzip()` an entry at a time, over the archive in memory or a `Blob` read a range at a time
|
|
116
|
+
*
|
|
117
|
+
* From a `Blob`, such as a `File` or `fs.openAsBlob()`, no more is held than the names and the entry at hand.
|
|
118
|
+
* The layout is checked before the first entry, each entry's contents as it is reached. No entry's data is
|
|
119
|
+
* kept, so a name that repeats is refused: such an archive is for `unzip()`.
|
|
120
|
+
*
|
|
121
|
+
* @param archive - The archive
|
|
122
|
+
* @param options - Unzip options
|
|
123
|
+
* @returns The entries, in central directory order
|
|
124
|
+
*/
|
|
125
|
+
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'
|