@preventive/archive 1.0.0-beta.3 → 1.0.0-beta.4
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/package.json +5 -3
- package/src/names.js +4 -4
- package/src/tar/header.js +19 -16
- package/src/tar/pack.js +6 -20
- package/src/tar/unpack.js +5 -7
- package/src/text.js +5 -0
- package/src/zip/unzip.js +1 -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/archive",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
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/names.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
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
|
|
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
|
|
@@ -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
|
@@ -6,25 +6,11 @@
|
|
|
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
|
@@ -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/unzip.js
CHANGED
|
@@ -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/{LICENSE → LICENSE-MIT}
RENAMED
|
File without changes
|