@preventive/archive 1.0.0-beta.3 → 1.0.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/LICENSE-APACHE +202 -0
- package/compression.d.ts +4 -1
- package/compression.js +2 -2
- package/package.json +5 -3
- package/src/compression.js +31 -1
- package/src/error.js +1 -1
- package/src/names.js +9 -9
- package/src/tar/header.js +22 -19
- package/src/tar/pack.js +8 -22
- package/src/tar/unpack.js +5 -7
- package/src/text.js +8 -3
- package/src/zip/format.js +1 -1
- package/src/zip/unzip.js +10 -11
- package/tar.d.ts +6 -6
- package/zip.d.ts +6 -6
- package/zip.js +2 -2
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/compression.d.ts
CHANGED
|
@@ -13,7 +13,10 @@ export interface Options {
|
|
|
13
13
|
limit?: number
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// The whole input through one stream, the whole output back.
|
|
16
|
+
// The whole input through one stream, the whole output back. gzip is
|
|
17
|
+
// decompressed past zero bytes after its last member, as gzip(1) and zlib
|
|
18
|
+
// take them for padding, where the platform's stream refuses them; nothing
|
|
19
|
+
// else after the end is passed over.
|
|
17
20
|
export function compress(bytes: Uint8Array, format: string, options?: Options): Promise<Uint8Array>
|
|
18
21
|
export function decompress(bytes: Uint8Array, format: string, options?: Options): Promise<Uint8Array>
|
|
19
22
|
|
package/compression.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The compression front door of @preventive/archive, reached as
|
|
2
2
|
// `@preventive/archive/compression.js`: bytes through the platform's
|
|
3
3
|
// CompressionStream and DecompressionStream, whole, with an output bound,
|
|
4
|
-
// and with what came out before a failure
|
|
5
|
-
// deflates through the same code.
|
|
4
|
+
// gzip's zero padding passed over, and with what came out before a failure
|
|
5
|
+
// kept on the error. The zip half deflates through the same code.
|
|
6
6
|
export { CompressionError, compress, decompress, supports } from './src/compression.js'
|
|
7
7
|
export { ArchiveError } from './src/error.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/archive",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Strict in-memory tar and zip on browser APIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
|
+
"LICENSE-APACHE",
|
|
22
|
+
"LICENSE-MIT",
|
|
21
23
|
"compression.d.ts",
|
|
22
24
|
"compression.js",
|
|
23
25
|
"src/bytes.js",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"scripts": {
|
|
45
47
|
"test": "node --test ./tests/*.test.js ./tests/tar/*.test.js ./tests/zip/*.test.js"
|
|
46
48
|
},
|
|
47
|
-
"license": "MIT",
|
|
49
|
+
"license": "MIT OR Apache-2.0",
|
|
48
50
|
"author": {
|
|
49
51
|
"name": "Nikita Skovoroda",
|
|
50
52
|
"email": "chalkerx@gmail.com",
|
|
@@ -52,7 +54,7 @@
|
|
|
52
54
|
},
|
|
53
55
|
"repository": {
|
|
54
56
|
"type": "git",
|
|
55
|
-
"url": "https://github.com/PreventiveMeasures/libraries.git",
|
|
57
|
+
"url": "git+https://github.com/PreventiveMeasures/libraries.git",
|
|
56
58
|
"directory": "archive"
|
|
57
59
|
},
|
|
58
60
|
"bugs": {
|
package/src/compression.js
CHANGED
|
@@ -79,7 +79,37 @@ async function through(bytes, Stream, format, limit, verb, into) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export const compress = (bytes, format, { limit = Infinity } = {}) => through(bytes, CompressionStream, format, limit, 'compress')
|
|
82
|
-
|
|
82
|
+
|
|
83
|
+
const inflate = (bytes, format, limit) => through(bytes, DecompressionStream, format, limit, 'decompress')
|
|
84
|
+
|
|
85
|
+
// gzip(1) and zlib take zero bytes after the last member as padding, as old
|
|
86
|
+
// tarballs run on in zeros to a whole 10240-byte record, the way npm 1.0
|
|
87
|
+
// packed them through the system's tar; the platform's stream refuses
|
|
88
|
+
// anything there. So gzip that ends in a zero and does not decompress is
|
|
89
|
+
// tried again ending sooner, at the one place it decompresses whole: its
|
|
90
|
+
// last member's last four bytes are the length it inflates to, mod 2^32,
|
|
91
|
+
// so where that is not 0 it ends within three zeros past the last byte that
|
|
92
|
+
// is not; where the member is empty, as zlib writes one, `03 00` and eight
|
|
93
|
+
// zeros, within nine. Only zeros are passed over, where zlib passes over
|
|
94
|
+
// whatever follows one; and each place tried inflates it all again, which
|
|
95
|
+
// only padded data pays for.
|
|
96
|
+
export async function decompress(bytes, format, { limit = Infinity } = {}) {
|
|
97
|
+
try {
|
|
98
|
+
return await inflate(bytes, format, limit)
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (format !== 'gzip' || !(error instanceof CompressionError) || error.limited || bytes.at(-1) !== 0) throw error
|
|
101
|
+
const last = bytes.findLastIndex((byte) => byte !== 0)
|
|
102
|
+
for (let end = last + 1; end <= Math.min(last + 10, bytes.length - 1); end++) {
|
|
103
|
+
try {
|
|
104
|
+
return await inflate(bytes.subarray(0, end), format, limit)
|
|
105
|
+
} catch (retry) {
|
|
106
|
+
// Output past the bound before the end is past it wherever the end is.
|
|
107
|
+
if (!(retry instanceof CompressionError) || retry.limited) throw retry
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw error
|
|
111
|
+
}
|
|
112
|
+
}
|
|
83
113
|
|
|
84
114
|
// Into `into`, which bounds the output, and handed back as much of it as
|
|
85
115
|
// was filled. Not in the front door: the zip half's, whose entries each
|
package/src/error.js
CHANGED
|
@@ -9,7 +9,7 @@ export class ArchiveError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// The same error, placed: for a check that does not know where in the
|
|
12
|
-
// archive it is running. Anything but such a refusal
|
|
12
|
+
// archive it is running. Anything but such a refusal -- a bug above all --
|
|
13
13
|
// goes on as it was, rather than dressed up as bad input.
|
|
14
14
|
export function located(fn, at) {
|
|
15
15
|
try {
|
package/src/names.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Name safety, applied before writing an entry and before handing one out
|
|
2
2
|
// of an archive. A name is a relative path: `.` segments and a directory's
|
|
3
3
|
// trailing slash are dropped, and what is left has no empty or `..`
|
|
4
|
-
// segment, no control character and no backslash
|
|
5
|
-
// Windows, where `..\` would get past the check on `..`
|
|
4
|
+
// segment, no control character and no backslash -- a separator on
|
|
5
|
+
// Windows, where `..\` would get past the check on `..` -- and does not
|
|
6
6
|
// start with a drive letter and colon, which Windows resolves from that
|
|
7
7
|
// drive rather than from the archive. A symlink target may use `..`, but
|
|
8
8
|
// is followed from where the link sits and refused if it climbs above the
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
// A name may repeat only as the same entry again, field for field and byte
|
|
18
18
|
// for byte (some npm packagers write `d/f` and `d/./f` both): two different
|
|
19
19
|
// entries under one name would leave the winner to extraction order.
|
|
20
|
-
// Collisions a filesystem might add
|
|
20
|
+
// Collisions a filesystem might add -- case, Unicode normalisation -- are
|
|
21
21
|
// the filesystem's, not the archive's, and are not looked for.
|
|
22
22
|
|
|
23
23
|
import { sameBytes } from './bytes.js'
|
|
24
24
|
import { ArchiveError } from './error.js'
|
|
25
|
-
import { checkString, hasUnsafe, quote,
|
|
25
|
+
import { checkString, hasUnsafe, quote, tooLong } from './text.js'
|
|
26
26
|
|
|
27
27
|
const PATH_MAX = 4096
|
|
28
28
|
const NAME_MAX = 255
|
|
@@ -38,9 +38,9 @@ function checkText(path, what) {
|
|
|
38
38
|
// Once `.` segments are dropped, `./C:x` is `C:x`, so the first segment
|
|
39
39
|
// that is not one is what a drive letter is looked for on.
|
|
40
40
|
if (/^[a-zA-Z]:/u.test(segments.find((segment) => segment !== '.') ?? '')) throw new ArchiveError(`${what} ${quote(path)} starts with a drive letter`)
|
|
41
|
-
if (
|
|
41
|
+
if (tooLong(path, PATH_MAX)) throw new ArchiveError(`${what} ${quote(path)} is longer than ${PATH_MAX} bytes`)
|
|
42
42
|
for (const segment of segments) {
|
|
43
|
-
if (
|
|
43
|
+
if (tooLong(segment, NAME_MAX)) throw new ArchiveError(`${what} ${quote(path)} has a segment longer than ${NAME_MAX} bytes`)
|
|
44
44
|
}
|
|
45
45
|
return segments
|
|
46
46
|
}
|
|
@@ -68,7 +68,7 @@ export function cleanPath(path, what, directory = false) {
|
|
|
68
68
|
const name = slash || kept.length < segments.length ? kept.join('/') : path
|
|
69
69
|
// As the archive stores it, a directory's name carries its slash: what
|
|
70
70
|
// pack takes, unpack then reads.
|
|
71
|
-
if (
|
|
71
|
+
if (tooLong(name, PATH_MAX - (directory ? 1 : 0))) throw new ArchiveError(`${what} ${quote(path)} is longer than ${PATH_MAX} bytes`)
|
|
72
72
|
return name
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -121,7 +121,7 @@ const FIELDS = ['type', 'mode', 'uid', 'gid', 'mtime', 'uname', 'gname', 'linkna
|
|
|
121
121
|
// Each name seen is an entry, a directory entry, or a directory implied by
|
|
122
122
|
// an entry inside it or by a symlink target walking through it; an implied
|
|
123
123
|
// directory may still be named as one. An entry inside a non-directory is
|
|
124
|
-
// refused
|
|
124
|
+
// refused -- that is the shape of a path through a symlink -- and so is a
|
|
125
125
|
// symlink target that walks through one, in either order, so no chain of
|
|
126
126
|
// links leads out of the archive. Whether entries are kept with their data
|
|
127
127
|
// decides what a repeat can be compared with: the in-memory calls keep
|
|
@@ -184,7 +184,7 @@ export class Names {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// A target followed from `at`: it has to stay inside the archive, and every
|
|
187
|
-
// path it walks through has to be a directory
|
|
187
|
+
// path it walks through has to be a directory -- each one it stands on short
|
|
188
188
|
// of the last step, the archive root aside. `what` names it in a refusal.
|
|
189
189
|
#symlink(at, target, what) {
|
|
190
190
|
const steps = checkSymlinkTarget(at, target)
|
package/src/tar/header.js
CHANGED
|
@@ -10,17 +10,28 @@ export const BLOCK = 512
|
|
|
10
10
|
|
|
11
11
|
export const isDevice = (type) => type === 'character-device' || type === 'block-device'
|
|
12
12
|
|
|
13
|
+
// Each entry type's type flag, and each extended header's: those GNU
|
|
14
|
+
// writes, under the names unpack reads them by.
|
|
15
|
+
export const TYPEFLAGS = {
|
|
16
|
+
file: 0x30,
|
|
17
|
+
hardlink: 0x31,
|
|
18
|
+
symlink: 0x32,
|
|
19
|
+
'character-device': 0x33,
|
|
20
|
+
'block-device': 0x34,
|
|
21
|
+
directory: 0x35,
|
|
22
|
+
fifo: 0x36,
|
|
23
|
+
'contiguous-file': 0x37,
|
|
24
|
+
}
|
|
25
|
+
export const EXTENDED_TYPEFLAGS = { pax: 0x78, global: 0x67, longname: 0x4c, longlink: 0x4b }
|
|
26
|
+
|
|
13
27
|
export const NAME_SIZE = 100
|
|
14
28
|
export const PREFIX_SIZE = 155
|
|
15
29
|
// 32 bytes, and GNU always ends them with a NUL, so 31 is the most.
|
|
16
30
|
export const OWNER_SIZE = 32
|
|
17
31
|
|
|
18
32
|
const NAME = 0
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const GID = 116
|
|
22
|
-
const SIZE = 124
|
|
23
|
-
const MTIME = 136
|
|
33
|
+
// The numbers from mode to mtime, [key, offset, size], in the block's order.
|
|
34
|
+
const NUMBERS = [['mode', 100, 8], ['uid', 108, 8], ['gid', 116, 8], ['size', 124, 12], ['mtime', 136, 12]]
|
|
24
35
|
const CHKSUM = 148
|
|
25
36
|
const TYPEFLAG = 156
|
|
26
37
|
const LINKNAME = 157
|
|
@@ -31,9 +42,9 @@ const DEVMAJOR = 329
|
|
|
31
42
|
const DEVMINOR = 337
|
|
32
43
|
const PREFIX = 345
|
|
33
44
|
// Under the gnu magic: the old GNU sparse map, its isextended flag and the
|
|
34
|
-
// file's real size. libarchive reads them whatever the type flag says
|
|
45
|
+
// file's real size. libarchive reads them whatever the type flag says --
|
|
35
46
|
// taking the real size as the file's, and the map and any extension blocks
|
|
36
|
-
// after the header as its layout
|
|
47
|
+
// after the header as its layout -- where GNU tar and the rest read them for
|
|
37
48
|
// a sparse entry alone.
|
|
38
49
|
const OLD_SPARSE = 386
|
|
39
50
|
const OLD_SPARSE_END = 495
|
|
@@ -69,7 +80,7 @@ export function writeNumber(block, offset, size, value, gnu) {
|
|
|
69
80
|
// Older tars wrote leading spaces, and either spaces or NULs after; a field
|
|
70
81
|
// left blank (npm's packer wrote uid and gid so for years) is 0, as GNU tar,
|
|
71
82
|
// libarchive and the rest read it. A NUL ends the number wherever it sits, so
|
|
72
|
-
// a field that opens with one is 0 however it goes on
|
|
83
|
+
// a field that opens with one is 0 however it goes on -- GNU stops there, and
|
|
73
84
|
// reading the digits past it instead would give a size, and so an archive,
|
|
74
85
|
// that only this package sees. Only a time may be negative.
|
|
75
86
|
export function readNumber(block, offset, size, what, at, signed = false) {
|
|
@@ -110,11 +121,7 @@ export const isZeroBlock = (block) => block.every((byte) => byte === 0)
|
|
|
110
121
|
export function encodeHeader(f) {
|
|
111
122
|
const block = new Uint8Array(BLOCK)
|
|
112
123
|
put(block, NAME, NAME_SIZE, f.name)
|
|
113
|
-
writeNumber(block,
|
|
114
|
-
writeNumber(block, UID, 8, f.uid, f.gnu)
|
|
115
|
-
writeNumber(block, GID, 8, f.gid, f.gnu)
|
|
116
|
-
writeNumber(block, SIZE, 12, f.size, f.gnu)
|
|
117
|
-
writeNumber(block, MTIME, 12, f.mtime, f.gnu)
|
|
124
|
+
for (const [key, offset, size] of NUMBERS) writeNumber(block, offset, size, f[key], f.gnu)
|
|
118
125
|
block[TYPEFLAG] = f.typeflag
|
|
119
126
|
put(block, LINKNAME, NAME_SIZE, f.linkname)
|
|
120
127
|
put(block, MAGIC, 8, latin1(f.gnu ? GNU_MAGIC : USTAR_MAGIC))
|
|
@@ -135,7 +142,7 @@ export function decodeHeader(block, at) {
|
|
|
135
142
|
if (!gnu && magic !== USTAR_MAGIC) throw new ArchiveError('header is not in the ustar, pax or gnu format', at)
|
|
136
143
|
if (gnu && !isZeroBlock(block.subarray(OLD_SPARSE, OLD_SPARSE_END))) throw new ArchiveError('header carries an old GNU sparse map or real size', at)
|
|
137
144
|
const typeflag = block[TYPEFLAG]
|
|
138
|
-
const device = typeflag ===
|
|
145
|
+
const device = typeflag === TYPEFLAGS['character-device'] || typeflag === TYPEFLAGS['block-device']
|
|
139
146
|
return {
|
|
140
147
|
gnu,
|
|
141
148
|
typeflag,
|
|
@@ -145,11 +152,7 @@ export function decodeHeader(block, at) {
|
|
|
145
152
|
linkname: field(block, LINKNAME, NAME_SIZE),
|
|
146
153
|
uname: field(block, UNAME, OWNER_SIZE),
|
|
147
154
|
gname: field(block, GNAME, OWNER_SIZE),
|
|
148
|
-
|
|
149
|
-
uid: readNumber(block, UID, 8, 'uid', at),
|
|
150
|
-
gid: readNumber(block, GID, 8, 'gid', at),
|
|
151
|
-
size: readNumber(block, SIZE, 12, 'size', at),
|
|
152
|
-
mtime: readNumber(block, MTIME, 12, 'mtime', at, true),
|
|
155
|
+
...Object.fromEntries(NUMBERS.map(([key, offset, size]) => [key, readNumber(block, offset, size, key, at, key === 'mtime')])),
|
|
153
156
|
devmajor: device ? readNumber(block, DEVMAJOR, 8, 'devmajor', at) : 0,
|
|
154
157
|
devminor: device ? readNumber(block, DEVMINOR, 8, 'devminor', at) : 0,
|
|
155
158
|
}
|
package/src/tar/pack.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
1
|
// Writes what GNU tar 1.35 writes for the same entries under `--owner=0
|
|
2
2
|
// --group=0 --numeric-owner` and, for pax, `--pax-option=delete=atime,
|
|
3
|
-
// delete=ctime`. Where GNU would cut or substitute
|
|
4
|
-
// ustar, a number out of range
|
|
3
|
+
// delete=ctime`. Where GNU would cut or substitute -- a name too long for
|
|
4
|
+
// ustar, a number out of range -- this refuses instead.
|
|
5
5
|
|
|
6
6
|
import { EMPTY, concat, isAscii } from '../bytes.js'
|
|
7
7
|
import { DEFAULT_MODE, checkEntry, wireName } from '../entry.js'
|
|
8
8
|
import { ArchiveError } from '../error.js'
|
|
9
|
-
import { BLOCK, NAME_SIZE, OWNER_SIZE, PREFIX_SIZE, encodeHeader, fitsOctal, isDevice, octalMax } from './header.js'
|
|
9
|
+
import { BLOCK, EXTENDED_TYPEFLAGS, NAME_SIZE, OWNER_SIZE, PREFIX_SIZE, TYPEFLAGS, encodeHeader, fitsOctal, isDevice, octalMax } from './header.js'
|
|
10
10
|
import { Names, cleanNames } from '../names.js'
|
|
11
11
|
import { encodePax } from './pax.js'
|
|
12
12
|
import { checkString, encodeUtf8, hasUnsafe, quote } from '../text.js'
|
|
13
13
|
|
|
14
|
-
const TYPEFLAG = {
|
|
15
|
-
file: 0x30,
|
|
16
|
-
hardlink: 0x31,
|
|
17
|
-
symlink: 0x32,
|
|
18
|
-
'character-device': 0x33,
|
|
19
|
-
'block-device': 0x34,
|
|
20
|
-
directory: 0x35,
|
|
21
|
-
fifo: 0x36,
|
|
22
|
-
'contiguous-file': 0x37,
|
|
23
|
-
}
|
|
24
|
-
const LONGNAME = 0x4c
|
|
25
|
-
const LONGLINK = 0x4b
|
|
26
|
-
const PAX = 0x78
|
|
27
|
-
|
|
28
14
|
const FORMATS = new Set(['gnu', 'ustar', 'pax'])
|
|
29
15
|
const SLASH = 0x2f
|
|
30
16
|
|
|
@@ -40,7 +26,7 @@ function ownerName(value, what) {
|
|
|
40
26
|
}
|
|
41
27
|
|
|
42
28
|
function normalize(entry) {
|
|
43
|
-
const checked = checkEntry(entry,
|
|
29
|
+
const checked = checkEntry(entry, TYPEFLAGS)
|
|
44
30
|
const { name, type } = checked
|
|
45
31
|
const devmajor = integer(entry.devmajor ?? 0, 'devmajor')
|
|
46
32
|
const devminor = integer(entry.devminor ?? 0, 'devminor')
|
|
@@ -82,7 +68,7 @@ function paxHeader(e, records) {
|
|
|
82
68
|
const body = encodePax(records)
|
|
83
69
|
const slash = e.name.lastIndexOf('/')
|
|
84
70
|
const label = slash === -1 ? `./PaxHeaders/${e.name}` : `${e.name.slice(0, slash)}/PaxHeaders/${e.name.slice(slash + 1)}`
|
|
85
|
-
return [privateHeader(label, body.length, Math.max(0, Math.min(e.mtime, octalMax(12))),
|
|
71
|
+
return [privateHeader(label, body.length, Math.max(0, Math.min(e.mtime, octalMax(12))), EXTENDED_TYPEFLAGS.pax, false), padded(body)]
|
|
86
72
|
}
|
|
87
73
|
|
|
88
74
|
// GNU's split_long_name: the last slash within 155 bytes of prefix (a
|
|
@@ -112,14 +98,14 @@ function encodeEntry(e, format) {
|
|
|
112
98
|
let prefix = EMPTY
|
|
113
99
|
let link = encodeUtf8(e.linkname, `link target of ${quote(e.name)}`)
|
|
114
100
|
if (link.length > NAME_SIZE) {
|
|
115
|
-
if (gnu) chunks.push(...longLink(link,
|
|
101
|
+
if (gnu) chunks.push(...longLink(link, EXTENDED_TYPEFLAGS.longlink))
|
|
116
102
|
else if (format === 'pax') pax.push(['linkpath', e.linkname])
|
|
117
103
|
else throw new ArchiveError(`link target of ${quote(e.name)} is longer than 100 bytes, which ustar cannot hold`)
|
|
118
104
|
link = link.subarray(0, NAME_SIZE)
|
|
119
105
|
}
|
|
120
106
|
if (format === 'pax' && (name.length > NAME_SIZE || !isAscii(name))) pax.push(['path', wire])
|
|
121
107
|
if (name.length > NAME_SIZE) {
|
|
122
|
-
if (gnu) chunks.push(...longLink(name,
|
|
108
|
+
if (gnu) chunks.push(...longLink(name, EXTENDED_TYPEFLAGS.longname))
|
|
123
109
|
else if (format === 'ustar') ({ prefix, name } = splitName(name, e.name))
|
|
124
110
|
if (name.length > NAME_SIZE) name = name.subarray(0, NAME_SIZE)
|
|
125
111
|
}
|
|
@@ -142,7 +128,7 @@ function encodeEntry(e, format) {
|
|
|
142
128
|
}
|
|
143
129
|
const device = isDevice(e.type)
|
|
144
130
|
const fields = {
|
|
145
|
-
gnu, name, prefix, linkname: link, typeflag:
|
|
131
|
+
gnu, name, prefix, linkname: link, typeflag: TYPEFLAGS[e.type], mode: e.mode,
|
|
146
132
|
uid: number('uid', e.uid, 8),
|
|
147
133
|
gid: number('gid', e.gid, 8),
|
|
148
134
|
size: number('size', e.data.length, 12),
|
package/src/tar/unpack.js
CHANGED
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
import { EMPTY } from '../bytes.js'
|
|
8
8
|
import { isFile } from '../entry.js'
|
|
9
9
|
import { ArchiveError, located } from '../error.js'
|
|
10
|
-
import { BLOCK, decodeHeader, isDevice, isZeroBlock, untilNul } from './header.js'
|
|
10
|
+
import { BLOCK, EXTENDED_TYPEFLAGS, TYPEFLAGS, decodeHeader, isDevice, isZeroBlock, untilNul } from './header.js'
|
|
11
11
|
import { Names, cleanNames } from '../names.js'
|
|
12
12
|
import { Records, decodePax } from './pax.js'
|
|
13
13
|
import { decodeUtf8, hasUnsafe, quote } from '../text.js'
|
|
14
14
|
|
|
15
|
-
// NUL is the pre-POSIX regular file.
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
])
|
|
20
|
-
const EXTENDED = new Map([[0x78, 'pax'], [0x67, 'global'], [0x4c, 'longname'], [0x4b, 'longlink']])
|
|
15
|
+
// Type flag -> name. NUL is the pre-POSIX regular file.
|
|
16
|
+
const byFlag = (flags) => Object.entries(flags).map(([name, flag]) => [flag, name])
|
|
17
|
+
const TYPES = new Map([...byFlag(TYPEFLAGS), [0, 'file']])
|
|
18
|
+
const EXTENDED = new Map(byFlag(EXTENDED_TYPEFLAGS))
|
|
21
19
|
const MAX_EXTENDED = 1 << 20
|
|
22
20
|
|
|
23
21
|
// A sparse file is stored as a map and a body that is not the file, so
|
package/src/text.js
CHANGED
|
@@ -5,13 +5,13 @@ import { ArchiveError } from './error.js'
|
|
|
5
5
|
// short of a surrogate pair, so a long one cannot flood it.
|
|
6
6
|
export function quote(text) {
|
|
7
7
|
if (text.length <= 200) return JSON.stringify(text)
|
|
8
|
-
return JSON.stringify(`${text.slice(0, text.codePointAt(199) > 0xffff ? 199 : 200)}
|
|
8
|
+
return JSON.stringify(`${text.slice(0, text.codePointAt(199) > 0xffff ? 199 : 200)}\u2026`)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// A C0, DEL or C1 control (Cc is those three and nothing else); a line or
|
|
12
12
|
// paragraph separator (Zl, Zp: one each); and every bidirectional control
|
|
13
|
-
// Unicode names
|
|
14
|
-
// that shift neutral characters about them unseen
|
|
13
|
+
// Unicode names -- embeddings, overrides and isolates, and the three marks
|
|
14
|
+
// that shift neutral characters about them unseen -- since each breaks or
|
|
15
15
|
// reorders a name as shown. A backslash too, if asked.
|
|
16
16
|
const UNSAFE = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}]/u
|
|
17
17
|
const UNSAFE_OR_BACKSLASH = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}\\]/u
|
|
@@ -35,6 +35,11 @@ export function utf8Length(text) {
|
|
|
35
35
|
return length
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// Whether text is more than `max` bytes of UTF-8. A code unit is at least
|
|
39
|
+
// a byte and at most three, so text of more units than `max` is over, and
|
|
40
|
+
// of a third as many is not, without being counted.
|
|
41
|
+
export const tooLong = (text, max) => text.length > max || (text.length * 3 > max && utf8Length(text) > max)
|
|
42
|
+
|
|
38
43
|
export function encodeUtf8(text, what) {
|
|
39
44
|
try {
|
|
40
45
|
return utf8fromString(text)
|
package/src/zip/format.js
CHANGED
|
@@ -53,7 +53,7 @@ export async function inflate(bytes, size, at) {
|
|
|
53
53
|
return out
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// DOS time is two seconds and a year from 1980, in the maker's local time
|
|
56
|
+
// DOS time is two seconds and a year from 1980, in the maker's local time --
|
|
57
57
|
// read and written here as UTC.
|
|
58
58
|
function dos(seconds) {
|
|
59
59
|
const date = new Date(seconds * 1000)
|
package/src/zip/unzip.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// A zip archive in, its entries out, in the order of the central directory,
|
|
2
2
|
// which is what a zip is read from. Strict throughout: the end record has to
|
|
3
3
|
// sit at the very end, the central directory right before it, and the
|
|
4
|
-
// entries have to tile everything before that from byte 0
|
|
4
|
+
// entries have to tile everything before that from byte 0 -- no bytes belong
|
|
5
5
|
// to nothing, no two entries share any. Each local header has to agree with
|
|
6
6
|
// the central directory, the data has to inflate to exactly the declared
|
|
7
|
-
// size and match its CRC-32, and what this package does not model
|
|
8
|
-
// encryption, any method but stored and deflate, several disks
|
|
7
|
+
// size and match its CRC-32, and what this package does not model -- zip64,
|
|
8
|
+
// encryption, any method but stored and deflate, several disks -- is refused.
|
|
9
9
|
// Given a limit, the sizes the entries declare may not add up to more than
|
|
10
10
|
// it; since each has to come out at exactly its own, that bounds everything
|
|
11
11
|
// unzip() puts out, and it is known from the central directory alone,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
//
|
|
14
14
|
// One reader serves both calls. It asks for the archive a range at a time:
|
|
15
15
|
// views of it when it is in memory, and reads of just those bytes when it
|
|
16
|
-
// is a Blob
|
|
16
|
+
// is a Blob -- a File, or a file opened with fs.openAsBlob -- so a stream
|
|
17
17
|
// over one holds no more of it than the entries' names and the entry it is
|
|
18
18
|
// on. Everything about the layout is checked before the first entry is
|
|
19
19
|
// handed over; what an entry's own data holds is checked as it is reached.
|
|
@@ -71,7 +71,7 @@ function sourceOf(archive) {
|
|
|
71
71
|
|
|
72
72
|
// A walk forward through records too small to be worth a read each: a
|
|
73
73
|
// window over [at, at + width), cut short only where the archive ends,
|
|
74
|
-
// and over what else the read it came from holds
|
|
74
|
+
// and over what else the read it came from holds -- up to CHUNK bytes past
|
|
75
75
|
// `at`, and short of `stop`, so that the records after it come in the same
|
|
76
76
|
// read and nothing past them is read to no purpose.
|
|
77
77
|
const CHUNK = 1 << 16
|
|
@@ -116,7 +116,7 @@ function extras(raw, at) {
|
|
|
116
116
|
if (pos + 4 + size > raw.length) throw new ArchiveError('an extra field runs past its room', at)
|
|
117
117
|
if (id === ZIP64_EXTRA) throw new ArchiveError('zip64 is not supported', at)
|
|
118
118
|
// Every name here is UTF-8 already, so this field can only disagree with
|
|
119
|
-
// the name checked above
|
|
119
|
+
// the name checked above -- and unzip would extract the name it carries.
|
|
120
120
|
if (id === UNICODE_PATH_EXTRA) throw new ArchiveError('an entry carries a second name in a Unicode path extra field', at)
|
|
121
121
|
if (!fields.has(id)) fields.set(id, raw.subarray(pos + 4, pos + 4 + size))
|
|
122
122
|
pos += 4 + size
|
|
@@ -165,8 +165,8 @@ async function readCentral(read, at) {
|
|
|
165
165
|
// The local header checked against the central entry; returns where the
|
|
166
166
|
// entry's bytes end, which has to be `boundary`, the next record's start,
|
|
167
167
|
// and notes where its data starts. The two records have to agree on
|
|
168
|
-
// everything both carry
|
|
169
|
-
// one and not the other is read two ways by two readers
|
|
168
|
+
// everything both carry -- flags included, since a descriptor bit set in
|
|
169
|
+
// one and not the other is read two ways by two readers -- and the local
|
|
170
170
|
// sizes and CRC may be 0 only where a descriptor carries them. `stop` is
|
|
171
171
|
// as far as the header is read ahead of itself.
|
|
172
172
|
async function readLocal(read, entry, boundary, stop) {
|
|
@@ -201,7 +201,7 @@ async function readLocal(read, entry, boundary, stop) {
|
|
|
201
201
|
return end
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
// A directory marker anywhere
|
|
204
|
+
// A directory marker anywhere -- the Unix type bits, the DOS bit -- needs
|
|
205
205
|
// the slash; the slash needs no marker, since Java writes no attributes at
|
|
206
206
|
// all and every JAR has directories.
|
|
207
207
|
function typeOf(entry, rawName, mode) {
|
|
@@ -288,8 +288,7 @@ async function* entries(source, { limit = Infinity } = {}, keep = false) {
|
|
|
288
288
|
|
|
289
289
|
export async function unzip(bytes, options) {
|
|
290
290
|
if (!(bytes instanceof Uint8Array)) throw new ArchiveError('the archive is not a Uint8Array')
|
|
291
|
-
|
|
292
|
-
return out
|
|
291
|
+
return await Array.fromAsync(entries(sourceOf(bytes), options, true))
|
|
293
292
|
}
|
|
294
293
|
|
|
295
294
|
export async function* unzipStream(archive, options) {
|
package/tar.d.ts
CHANGED
|
@@ -23,14 +23,14 @@ export type EntryType =
|
|
|
23
23
|
//
|
|
24
24
|
// Beside those, what the archive itself says. `storedName` and
|
|
25
25
|
// `storedLinkname` are the name and link target as stored, before any
|
|
26
|
-
// cleaning
|
|
27
|
-
// prefix joined on
|
|
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
28
|
// hard link's target is ever cleaned, so a symlink's is its `linkname`.
|
|
29
29
|
// `pax` is the records of the entry's own pax header and `globalPax` those
|
|
30
30
|
// of the global header it is under, each in the order stored, those read
|
|
31
31
|
// into the fields above among them; the fields take an entry's own record
|
|
32
|
-
// over the global one. A Map is shared
|
|
33
|
-
// header has its, every entry without a header the one empty Map
|
|
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
34
|
// cannot be changed. A value this package does not read is as stored,
|
|
35
35
|
// unchecked, and may hold any character, a control one included.
|
|
36
36
|
export interface Entry {
|
|
@@ -84,8 +84,8 @@ export interface PackOptions {
|
|
|
84
84
|
blocking?: number
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
// Both refuse a name that repeats as a different entry
|
|
88
|
-
// same fields and the same bytes again, however either was stored
|
|
87
|
+
// Both refuse a name that repeats as a different entry -- anything but the
|
|
88
|
+
// same fields and the same bytes again, however either was stored -- an
|
|
89
89
|
// entry inside something that is not a directory, a symlink whose target
|
|
90
90
|
// climbs out of the archive or passes through anything but a directory, and
|
|
91
91
|
// a hard link to no earlier entry. A hard link to a symlink, directly or
|
package/zip.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export type EntryType = 'file' | 'directory' | 'symlink'
|
|
|
14
14
|
// `linkname` is '' for anything but a symlink; `data` is empty for
|
|
15
15
|
// anything but a file, and a view over the archive bytes where the entry
|
|
16
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`
|
|
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
19
|
// check the cleaned one did. A symlink's target is never rewritten, only
|
|
20
20
|
// checked, so `linkname` is as stored.
|
|
21
21
|
export interface Entry {
|
|
@@ -50,7 +50,7 @@ export interface ZipOptions {
|
|
|
50
50
|
method?: 'deflate' | 'store'
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// `limit` bounds the entries' sizes, all of them together, in bytes
|
|
53
|
+
// `limit` bounds the entries' sizes, all of them together, in bytes --
|
|
54
54
|
// stored and deflated alike, a symlink's target included. Each entry has to
|
|
55
55
|
// come out at exactly the size it declares, so the sum is checked against
|
|
56
56
|
// the central directory before anything is inflated, and past the limit
|
|
@@ -59,8 +59,8 @@ export interface UnzipOptions {
|
|
|
59
59
|
limit?: number
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
// Both refuse a name that repeats as a different entry
|
|
63
|
-
// same fields and the same bytes again, however either was stored
|
|
62
|
+
// Both refuse a name that repeats as a different entry -- anything but the
|
|
63
|
+
// same fields and the same bytes again, however either was stored -- an
|
|
64
64
|
// entry inside something that is not a directory, and a symlink whose
|
|
65
65
|
// target climbs out of the archive or passes through anything but a
|
|
66
66
|
// directory. unzip() also refuses an entry carrying a Unicode path extra
|
|
@@ -71,7 +71,7 @@ export function zip(entries: Iterable<EntryInput>, options?: ZipOptions): Promis
|
|
|
71
71
|
export function unzip(bytes: Uint8Array, options?: UnzipOptions): Promise<Entry[]>
|
|
72
72
|
|
|
73
73
|
// The same one entry at a time, as an async generator: over the archive in
|
|
74
|
-
// memory, or over a Blob
|
|
74
|
+
// memory, or over a Blob -- a File, or a file opened with fs.openAsBlob --
|
|
75
75
|
// read a range at a time, so that no more of it is held than the entries'
|
|
76
76
|
// names and the entry it is on, whose data is then its own rather than a
|
|
77
77
|
// view of the archive.
|
package/zip.js
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
// refused rather than written down wrong.
|
|
9
9
|
export { zip } from './src/zip/zip.js'
|
|
10
10
|
|
|
11
|
-
// An archive in, its entries out, under the same rules
|
|
11
|
+
// An archive in, its entries out, under the same rules -- and with every
|
|
12
12
|
// header, size and checksum in it checked against every other, and the
|
|
13
13
|
// sizes all together held to a limit where one is given.
|
|
14
14
|
export { unzip } from './src/zip/unzip.js'
|
|
15
15
|
|
|
16
16
|
// The same an entry at a time, as an async generator over the archive in
|
|
17
|
-
// memory or over a Blob
|
|
17
|
+
// memory or over a Blob -- a File, or a file opened with fs.openAsBlob --
|
|
18
18
|
// read a range at a time, so no more of it is held than the entry it is on.
|
|
19
19
|
export { unzipStream } from './src/zip/unzip.js'
|
|
20
20
|
|
/package/{LICENSE → LICENSE-MIT}
RENAMED
|
File without changes
|