tar 7.5.23 → 8.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/README.md +1705 -1147
- package/dist/commonjs/bytes.d.ts +21 -0
- package/dist/commonjs/bytes.d.ts.map +1 -0
- package/dist/commonjs/bytes.js +83 -0
- package/dist/commonjs/bytes.js.map +1 -0
- package/dist/commonjs/codec.d.ts +53 -0
- package/dist/commonjs/codec.d.ts.map +1 -0
- package/dist/commonjs/codec.js +35 -0
- package/dist/commonjs/codec.js.map +1 -0
- package/dist/commonjs/concat.d.ts +3 -0
- package/dist/commonjs/concat.d.ts.map +1 -0
- package/dist/commonjs/concat.js +20 -0
- package/dist/commonjs/concat.js.map +1 -0
- package/dist/commonjs/create.d.ts +39 -2
- package/dist/commonjs/create.d.ts.map +1 -1
- package/dist/commonjs/create.js +150 -64
- package/dist/commonjs/create.js.map +1 -1
- package/dist/commonjs/dealias.d.ts +79 -0
- package/dist/commonjs/dealias.d.ts.map +1 -0
- package/dist/commonjs/dealias.js +50 -0
- package/dist/commonjs/dealias.js.map +1 -0
- package/dist/commonjs/delete.d.ts +19 -0
- package/dist/commonjs/delete.d.ts.map +1 -0
- package/dist/commonjs/delete.js +121 -0
- package/dist/commonjs/delete.js.map +1 -0
- package/dist/commonjs/entries.d.ts +82 -0
- package/dist/commonjs/entries.d.ts.map +1 -0
- package/dist/commonjs/entries.js +398 -0
- package/dist/commonjs/entries.js.map +1 -0
- package/dist/commonjs/extract.d.ts +14 -2
- package/dist/commonjs/extract.d.ts.map +1 -1
- package/dist/commonjs/extract.js +40 -81
- package/dist/commonjs/extract.js.map +1 -1
- package/dist/commonjs/fs.d.ts +201 -0
- package/dist/commonjs/fs.d.ts.map +1 -0
- package/dist/commonjs/fs.js +5 -0
- package/dist/commonjs/fs.js.map +1 -0
- package/dist/commonjs/header.d.ts +4 -4
- package/dist/commonjs/header.d.ts.map +1 -1
- package/dist/commonjs/header.js +38 -42
- package/dist/commonjs/header.js.map +1 -1
- package/dist/commonjs/index.d.ts +25 -18
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +46 -18
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/index.min.js +2 -3
- package/dist/commonjs/index.min.js.map +4 -4
- package/dist/commonjs/large-numbers.d.ts +2 -2
- package/dist/commonjs/large-numbers.d.ts.map +1 -1
- package/dist/commonjs/large-numbers.js +4 -4
- package/dist/commonjs/large-numbers.js.map +1 -1
- package/dist/commonjs/list.d.ts +23 -6
- package/dist/commonjs/list.d.ts.map +1 -1
- package/dist/commonjs/list.js +99 -138
- package/dist/commonjs/list.js.map +1 -1
- package/dist/commonjs/mkdir.d.ts +16 -11
- package/dist/commonjs/mkdir.d.ts.map +1 -1
- package/dist/commonjs/mkdir.js +121 -159
- package/dist/commonjs/mkdir.js.map +1 -1
- package/dist/commonjs/options.d.ts +284 -513
- package/dist/commonjs/options.d.ts.map +1 -1
- package/dist/commonjs/options.js +20 -61
- package/dist/commonjs/options.js.map +1 -1
- package/dist/commonjs/pack.d.ts +150 -96
- package/dist/commonjs/pack.d.ts.map +1 -1
- package/dist/commonjs/pack.js +752 -445
- package/dist/commonjs/pack.js.map +1 -1
- package/dist/commonjs/parser.d.ts +94 -0
- package/dist/commonjs/parser.d.ts.map +1 -0
- package/dist/commonjs/parser.js +381 -0
- package/dist/commonjs/parser.js.map +1 -0
- package/dist/commonjs/path-reservations.d.ts +17 -7
- package/dist/commonjs/path-reservations.d.ts.map +1 -1
- package/dist/commonjs/path-reservations.js +96 -119
- package/dist/commonjs/path-reservations.js.map +1 -1
- package/dist/commonjs/path.d.ts +19 -0
- package/dist/commonjs/path.d.ts.map +1 -0
- package/dist/commonjs/path.js +90 -0
- package/dist/commonjs/path.js.map +1 -0
- package/dist/commonjs/pax.d.ts +3 -1
- package/dist/commonjs/pax.d.ts.map +1 -1
- package/dist/commonjs/pax.js +53 -37
- package/dist/commonjs/pax.js.map +1 -1
- package/dist/commonjs/read-entry.d.ts +97 -11
- package/dist/commonjs/read-entry.d.ts.map +1 -1
- package/dist/commonjs/read-entry.js +248 -97
- package/dist/commonjs/read-entry.js.map +1 -1
- package/dist/commonjs/read-file.d.ts +22 -0
- package/dist/commonjs/read-file.d.ts.map +1 -0
- package/dist/commonjs/read-file.js +104 -0
- package/dist/commonjs/read-file.js.map +1 -0
- package/dist/commonjs/replace.d.ts +45 -1
- package/dist/commonjs/replace.d.ts.map +1 -1
- package/dist/commonjs/replace.js +165 -211
- package/dist/commonjs/replace.js.map +1 -1
- package/dist/commonjs/server/codecs.d.ts +38 -0
- package/dist/commonjs/server/codecs.d.ts.map +1 -0
- package/dist/commonjs/server/codecs.js +252 -0
- package/dist/commonjs/server/codecs.js.map +1 -0
- package/dist/commonjs/server/index.d.ts +115 -0
- package/dist/commonjs/server/index.d.ts.map +1 -0
- package/dist/commonjs/server/index.js +166 -0
- package/dist/commonjs/server/index.js.map +1 -0
- package/dist/commonjs/server/index.min.js +3 -0
- package/dist/commonjs/server/index.min.js.map +7 -0
- package/dist/commonjs/strip-absolute-path.d.ts +8 -0
- package/dist/commonjs/strip-absolute-path.d.ts.map +1 -1
- package/dist/commonjs/strip-absolute-path.js +17 -20
- package/dist/commonjs/strip-absolute-path.js.map +1 -1
- package/dist/commonjs/to-stream.d.ts +7 -0
- package/dist/commonjs/to-stream.d.ts.map +1 -0
- package/dist/commonjs/to-stream.js +22 -0
- package/dist/commonjs/to-stream.js.map +1 -0
- package/dist/commonjs/types.d.ts +4 -3
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +4 -3
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/unpack.d.ts +135 -89
- package/dist/commonjs/unpack.d.ts.map +1 -1
- package/dist/commonjs/unpack.js +760 -727
- package/dist/commonjs/unpack.js.map +1 -1
- package/dist/commonjs/update.d.ts +11 -1
- package/dist/commonjs/update.d.ts.map +1 -1
- package/dist/commonjs/update.js +37 -28
- package/dist/commonjs/update.js.map +1 -1
- package/dist/commonjs/warn.d.ts +27 -0
- package/dist/commonjs/warn.d.ts.map +1 -0
- package/dist/commonjs/warn.js +36 -0
- package/dist/commonjs/warn.js.map +1 -0
- package/dist/commonjs/win32-path.d.ts +16 -0
- package/dist/commonjs/win32-path.d.ts.map +1 -0
- package/dist/commonjs/win32-path.js +67 -0
- package/dist/commonjs/win32-path.js.map +1 -0
- package/dist/commonjs/write-entry.d.ts +64 -111
- package/dist/commonjs/write-entry.d.ts.map +1 -1
- package/dist/commonjs/write-entry.js +108 -672
- package/dist/commonjs/write-entry.js.map +1 -1
- package/dist/commonjs/write-flag.d.ts +18 -0
- package/dist/commonjs/write-flag.d.ts.map +1 -0
- package/dist/commonjs/write-flag.js +29 -0
- package/dist/commonjs/write-flag.js.map +1 -0
- package/dist/esm/bytes.d.ts +21 -0
- package/dist/esm/bytes.d.ts.map +1 -0
- package/dist/esm/bytes.js +72 -0
- package/dist/esm/bytes.js.map +1 -0
- package/dist/esm/codec.d.ts +53 -0
- package/dist/esm/codec.d.ts.map +1 -0
- package/dist/esm/codec.js +32 -0
- package/dist/esm/codec.js.map +1 -0
- package/dist/esm/concat.d.ts +3 -0
- package/dist/esm/concat.d.ts.map +1 -0
- package/dist/esm/concat.js +16 -0
- package/dist/esm/concat.js.map +1 -0
- package/dist/esm/create.d.ts +39 -2
- package/dist/esm/create.d.ts.map +1 -1
- package/dist/esm/create.js +144 -61
- package/dist/esm/create.js.map +1 -1
- package/dist/esm/dealias.d.ts +79 -0
- package/dist/esm/dealias.d.ts.map +1 -0
- package/dist/esm/dealias.js +46 -0
- package/dist/esm/dealias.js.map +1 -0
- package/dist/esm/delete.d.ts +19 -0
- package/dist/esm/delete.d.ts.map +1 -0
- package/dist/esm/delete.js +117 -0
- package/dist/esm/delete.js.map +1 -0
- package/dist/esm/entries.d.ts +82 -0
- package/dist/esm/entries.d.ts.map +1 -0
- package/dist/esm/entries.js +388 -0
- package/dist/esm/entries.js.map +1 -0
- package/dist/esm/extract.d.ts +14 -2
- package/dist/esm/extract.d.ts.map +1 -1
- package/dist/esm/extract.js +37 -44
- package/dist/esm/extract.js.map +1 -1
- package/dist/esm/fs.d.ts +201 -0
- package/dist/esm/fs.d.ts.map +1 -0
- package/dist/esm/fs.js +4 -0
- package/dist/esm/fs.js.map +1 -0
- package/dist/esm/header.d.ts +4 -4
- package/dist/esm/header.d.ts.map +1 -1
- package/dist/esm/header.js +38 -42
- package/dist/esm/header.js.map +1 -1
- package/dist/esm/index.d.ts +25 -18
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +23 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +2 -3
- package/dist/esm/index.min.js.map +4 -4
- package/dist/esm/large-numbers.d.ts +2 -2
- package/dist/esm/large-numbers.d.ts.map +1 -1
- package/dist/esm/large-numbers.js +4 -4
- package/dist/esm/large-numbers.js.map +1 -1
- package/dist/esm/list.d.ts +23 -6
- package/dist/esm/list.d.ts.map +1 -1
- package/dist/esm/list.js +96 -101
- package/dist/esm/list.js.map +1 -1
- package/dist/esm/mkdir.d.ts +16 -11
- package/dist/esm/mkdir.d.ts.map +1 -1
- package/dist/esm/mkdir.js +119 -154
- package/dist/esm/mkdir.js.map +1 -1
- package/dist/esm/options.d.ts +284 -513
- package/dist/esm/options.d.ts.map +1 -1
- package/dist/esm/options.js +17 -51
- package/dist/esm/options.js.map +1 -1
- package/dist/esm/pack.d.ts +150 -96
- package/dist/esm/pack.d.ts.map +1 -1
- package/dist/esm/pack.js +750 -441
- package/dist/esm/pack.js.map +1 -1
- package/dist/esm/parser.d.ts +94 -0
- package/dist/esm/parser.d.ts.map +1 -0
- package/dist/esm/parser.js +377 -0
- package/dist/esm/parser.js.map +1 -0
- package/dist/esm/path-reservations.d.ts +17 -7
- package/dist/esm/path-reservations.d.ts.map +1 -1
- package/dist/esm/path-reservations.js +96 -119
- package/dist/esm/path-reservations.js.map +1 -1
- package/dist/esm/path.d.ts +19 -0
- package/dist/esm/path.d.ts.map +1 -0
- package/dist/esm/path.js +80 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/pax.d.ts +3 -1
- package/dist/esm/pax.d.ts.map +1 -1
- package/dist/esm/pax.js +52 -36
- package/dist/esm/pax.js.map +1 -1
- package/dist/esm/read-entry.d.ts +97 -11
- package/dist/esm/read-entry.d.ts.map +1 -1
- package/dist/esm/read-entry.js +245 -96
- package/dist/esm/read-entry.js.map +1 -1
- package/dist/esm/read-file.d.ts +22 -0
- package/dist/esm/read-file.d.ts.map +1 -0
- package/dist/esm/read-file.js +99 -0
- package/dist/esm/read-file.js.map +1 -0
- package/dist/esm/replace.d.ts +45 -1
- package/dist/esm/replace.d.ts.map +1 -1
- package/dist/esm/replace.js +161 -207
- package/dist/esm/replace.js.map +1 -1
- package/dist/esm/server/codecs.d.ts +38 -0
- package/dist/esm/server/codecs.d.ts.map +1 -0
- package/dist/esm/server/codecs.js +214 -0
- package/dist/esm/server/codecs.js.map +1 -0
- package/dist/esm/server/index.d.ts +115 -0
- package/dist/esm/server/index.d.ts.map +1 -0
- package/dist/esm/server/index.js +102 -0
- package/dist/esm/server/index.js.map +1 -0
- package/dist/esm/server/index.min.js +3 -0
- package/dist/esm/server/index.min.js.map +7 -0
- package/dist/esm/strip-absolute-path.d.ts +8 -0
- package/dist/esm/strip-absolute-path.d.ts.map +1 -1
- package/dist/esm/strip-absolute-path.js +17 -20
- package/dist/esm/strip-absolute-path.js.map +1 -1
- package/dist/esm/to-stream.d.ts +7 -0
- package/dist/esm/to-stream.d.ts.map +1 -0
- package/dist/esm/to-stream.js +18 -0
- package/dist/esm/to-stream.js.map +1 -0
- package/dist/esm/types.d.ts +4 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +4 -3
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/unpack.d.ts +135 -89
- package/dist/esm/unpack.d.ts.map +1 -1
- package/dist/esm/unpack.js +756 -721
- package/dist/esm/unpack.js.map +1 -1
- package/dist/esm/update.d.ts +11 -1
- package/dist/esm/update.d.ts.map +1 -1
- package/dist/esm/update.js +35 -28
- package/dist/esm/update.js.map +1 -1
- package/dist/esm/warn.d.ts +27 -0
- package/dist/esm/warn.d.ts.map +1 -0
- package/dist/esm/warn.js +31 -0
- package/dist/esm/warn.js.map +1 -0
- package/dist/esm/win32-path.d.ts +16 -0
- package/dist/esm/win32-path.d.ts.map +1 -0
- package/dist/esm/win32-path.js +60 -0
- package/dist/esm/win32-path.js.map +1 -0
- package/dist/esm/write-entry.d.ts +64 -111
- package/dist/esm/write-entry.d.ts.map +1 -1
- package/dist/esm/write-entry.js +107 -633
- package/dist/esm/write-entry.js.map +1 -1
- package/dist/esm/write-flag.d.ts +18 -0
- package/dist/esm/write-flag.d.ts.map +1 -0
- package/dist/esm/write-flag.js +25 -0
- package/dist/esm/write-flag.js.map +1 -0
- package/package.json +68 -224
- package/dist/commonjs/get-write-flag.d.ts +0 -2
- package/dist/commonjs/get-write-flag.d.ts.map +0 -1
- package/dist/commonjs/get-write-flag.js +0 -32
- package/dist/commonjs/get-write-flag.js.map +0 -1
- package/dist/commonjs/make-command.d.ts +0 -49
- package/dist/commonjs/make-command.d.ts.map +0 -1
- package/dist/commonjs/make-command.js +0 -52
- package/dist/commonjs/make-command.js.map +0 -1
- package/dist/commonjs/normalize-windows-path.d.ts +0 -2
- package/dist/commonjs/normalize-windows-path.d.ts.map +0 -1
- package/dist/commonjs/normalize-windows-path.js +0 -12
- package/dist/commonjs/normalize-windows-path.js.map +0 -1
- package/dist/commonjs/parse.d.ts +0 -92
- package/dist/commonjs/parse.d.ts.map +0 -1
- package/dist/commonjs/parse.js +0 -655
- package/dist/commonjs/parse.js.map +0 -1
- package/dist/commonjs/process-umask.d.ts +0 -2
- package/dist/commonjs/process-umask.d.ts.map +0 -1
- package/dist/commonjs/process-umask.js +0 -7
- package/dist/commonjs/process-umask.js.map +0 -1
- package/dist/commonjs/warn-method.d.ts +0 -24
- package/dist/commonjs/warn-method.d.ts.map +0 -1
- package/dist/commonjs/warn-method.js +0 -31
- package/dist/commonjs/warn-method.js.map +0 -1
- package/dist/esm/get-write-flag.d.ts +0 -2
- package/dist/esm/get-write-flag.d.ts.map +0 -1
- package/dist/esm/get-write-flag.js +0 -26
- package/dist/esm/get-write-flag.js.map +0 -1
- package/dist/esm/make-command.d.ts +0 -49
- package/dist/esm/make-command.d.ts.map +0 -1
- package/dist/esm/make-command.js +0 -48
- package/dist/esm/make-command.js.map +0 -1
- package/dist/esm/normalize-windows-path.d.ts +0 -2
- package/dist/esm/normalize-windows-path.d.ts.map +0 -1
- package/dist/esm/normalize-windows-path.js +0 -9
- package/dist/esm/normalize-windows-path.js.map +0 -1
- package/dist/esm/parse.d.ts +0 -92
- package/dist/esm/parse.d.ts.map +0 -1
- package/dist/esm/parse.js +0 -651
- package/dist/esm/parse.js.map +0 -1
- package/dist/esm/process-umask.d.ts +0 -2
- package/dist/esm/process-umask.d.ts.map +0 -1
- package/dist/esm/process-umask.js +0 -3
- package/dist/esm/process-umask.js.map +0 -1
- package/dist/esm/warn-method.d.ts +0 -24
- package/dist/esm/warn-method.d.ts.map +0 -1
- package/dist/esm/warn-method.js +0 -27
- package/dist/esm/warn-method.js.map +0 -1
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { decodeUtf8 } from './bytes.js';
|
|
2
|
+
import { Header } from './header.js';
|
|
3
|
+
import { Pax } from './pax.js';
|
|
4
|
+
import { ownOptions } from './options.js';
|
|
5
|
+
import { EntryData } from './read-entry.js';
|
|
6
|
+
import { warn } from './warn.js';
|
|
7
|
+
const BEGIN = 0;
|
|
8
|
+
const HEADER = 1;
|
|
9
|
+
const BODY = 2;
|
|
10
|
+
const IGNORE = 3;
|
|
11
|
+
const META = 4;
|
|
12
|
+
const ENTRY_END = { type: 'entryEnd' };
|
|
13
|
+
const END = { type: 'end' };
|
|
14
|
+
const metaTypes = new Set([
|
|
15
|
+
'ExtendedHeader',
|
|
16
|
+
'OldExtendedHeader',
|
|
17
|
+
'GlobalExtendedHeader',
|
|
18
|
+
'NextFileHasLongPath',
|
|
19
|
+
'OldGnuLongPath',
|
|
20
|
+
'NextFileHasLongLinkpath',
|
|
21
|
+
]);
|
|
22
|
+
// The text up to the first NUL.
|
|
23
|
+
const cstring = (buf) => {
|
|
24
|
+
const nul = buf.indexOf(0);
|
|
25
|
+
return decodeUtf8(buf, 0, nul === -1 ? buf.length : nul);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A tar parser that the caller pulls. Give it input with `push()`,
|
|
29
|
+
* and call `next()` for each event until it returns `undefined`.
|
|
30
|
+
* Then give it more input, or call `end()` and call `next()` again.
|
|
31
|
+
*
|
|
32
|
+
* It does not decompress. It calls no code of the caller but
|
|
33
|
+
* `filter`, `onwarn`, and the function that makes the entry objects.
|
|
34
|
+
*
|
|
35
|
+
* With `strict`, `next()` throws at each problem. The parser stays
|
|
36
|
+
* usable: the next call continues after the block with the problem.
|
|
37
|
+
*/
|
|
38
|
+
export class Parser {
|
|
39
|
+
maxMetaEntrySize;
|
|
40
|
+
/**
|
|
41
|
+
* The number of input bytes up to the end of the last complete
|
|
42
|
+
* entry that is not a meta entry.
|
|
43
|
+
*/
|
|
44
|
+
position = 0;
|
|
45
|
+
/**
|
|
46
|
+
* The number of input bytes that are parsed: the header blocks and
|
|
47
|
+
* the body blocks. At an `entry` event, it is the place of the body
|
|
48
|
+
* of the entry in the input.
|
|
49
|
+
*/
|
|
50
|
+
offset = 0;
|
|
51
|
+
#opt;
|
|
52
|
+
#filter;
|
|
53
|
+
#create;
|
|
54
|
+
#queue = [];
|
|
55
|
+
#chunk;
|
|
56
|
+
#pos = 0;
|
|
57
|
+
// a header block that is in more than one chunk
|
|
58
|
+
#block;
|
|
59
|
+
#blockLen = 0;
|
|
60
|
+
#state = BEGIN;
|
|
61
|
+
// the entry of the body that is read or skipped now
|
|
62
|
+
#entry;
|
|
63
|
+
#header;
|
|
64
|
+
#meta;
|
|
65
|
+
#metaLen = 0;
|
|
66
|
+
// body bytes to come, without and with the padding
|
|
67
|
+
#remain = 0;
|
|
68
|
+
#blockRemain = 0;
|
|
69
|
+
#ex;
|
|
70
|
+
// the names of the GNU long name headers for the next entry
|
|
71
|
+
#longPath;
|
|
72
|
+
#longLinkpath;
|
|
73
|
+
#gex;
|
|
74
|
+
#ended = false;
|
|
75
|
+
#sawValid;
|
|
76
|
+
#entryEnd = false;
|
|
77
|
+
// 0: reading, 1: the end is found, 2: the end event is returned
|
|
78
|
+
#done = 0;
|
|
79
|
+
/**
|
|
80
|
+
* @param createEntry makes the object for each entry event. It is
|
|
81
|
+
* required if `E` is not `EntryData`.
|
|
82
|
+
*/
|
|
83
|
+
constructor(opt = {}, createEntry) {
|
|
84
|
+
opt = this.#opt = ownOptions(opt);
|
|
85
|
+
this.maxMetaEntrySize = opt.maxMetaEntrySize || 1024 * 1024;
|
|
86
|
+
this.#filter = opt.filter;
|
|
87
|
+
const win32 = opt.platform === 'win32';
|
|
88
|
+
this.#create =
|
|
89
|
+
createEntry ??
|
|
90
|
+
((header, ex, gex) => new EntryData(header, ex, gex, win32));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Report a problem to `onwarn`. Throws if `strict` is set, or if
|
|
94
|
+
* `data.recoverable` is false.
|
|
95
|
+
*/
|
|
96
|
+
warn(code, message, data) {
|
|
97
|
+
warn(this.#opt, code, message, data);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Add input. The parser keeps the chunk until `next()` returns
|
|
101
|
+
* `undefined`, and each body event is a view into it. Input after
|
|
102
|
+
* `end()`, or after the end of the archive, is dropped.
|
|
103
|
+
*/
|
|
104
|
+
push(chunk) {
|
|
105
|
+
if (!this.#ended)
|
|
106
|
+
this.#queue.push(chunk);
|
|
107
|
+
}
|
|
108
|
+
/** Tell the parser that the input is complete. */
|
|
109
|
+
end() {
|
|
110
|
+
this.#ended = true;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The number of bytes of the body of the current entry, with its
|
|
114
|
+
* padding, that are after the input given so far. The caller can
|
|
115
|
+
* skip them in its input, and call `skipBody()`. It is 0 if the
|
|
116
|
+
* parser has input that it did not parse, and in a PAX or GNU
|
|
117
|
+
* header, because the parser reads that body.
|
|
118
|
+
*/
|
|
119
|
+
get bodyRemain() {
|
|
120
|
+
const chunk = this.#chunk;
|
|
121
|
+
const state = this.#state;
|
|
122
|
+
return ((state !== BODY && state !== IGNORE) ||
|
|
123
|
+
this.#queue.length ||
|
|
124
|
+
(chunk && this.#pos < chunk.length)) ?
|
|
125
|
+
0
|
|
126
|
+
: this.#blockRemain;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Count the `bodyRemain` bytes as parsed. The next input is the
|
|
130
|
+
* header after the body.
|
|
131
|
+
*/
|
|
132
|
+
skipBody() {
|
|
133
|
+
this.#entryEnd = this.#state === BODY;
|
|
134
|
+
this.offset += this.#blockRemain;
|
|
135
|
+
this.#remain = this.#blockRemain = 0;
|
|
136
|
+
this.#endBody();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The next event. `undefined` means that the parser needs more
|
|
140
|
+
* input, or after the `end` event, that it is done.
|
|
141
|
+
*/
|
|
142
|
+
next() {
|
|
143
|
+
if (this.#entryEnd) {
|
|
144
|
+
this.#entryEnd = false;
|
|
145
|
+
return ENTRY_END;
|
|
146
|
+
}
|
|
147
|
+
for (;;) {
|
|
148
|
+
let chunk = this.#chunk;
|
|
149
|
+
let pos = this.#pos;
|
|
150
|
+
if (!chunk || pos === chunk.length) {
|
|
151
|
+
chunk = this.#chunk = this.#queue.shift();
|
|
152
|
+
pos = this.#pos = 0;
|
|
153
|
+
if (!chunk) {
|
|
154
|
+
if (!this.#ended || this.#done === 2)
|
|
155
|
+
return undefined;
|
|
156
|
+
const ev = this.#finish();
|
|
157
|
+
if (ev)
|
|
158
|
+
return ev;
|
|
159
|
+
}
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const avail = chunk.length - pos;
|
|
163
|
+
const state = this.#state;
|
|
164
|
+
if (state <= HEADER) {
|
|
165
|
+
let ev;
|
|
166
|
+
if (this.#blockLen === 0 && avail >= 512) {
|
|
167
|
+
this.#pos = pos + 512;
|
|
168
|
+
ev = this.#consumeHeader(chunk, pos);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
const block = (this.#block ??= new Uint8Array(512));
|
|
172
|
+
const n = Math.min(512 - this.#blockLen, avail);
|
|
173
|
+
block.set(chunk.subarray(pos, pos + n), this.#blockLen);
|
|
174
|
+
this.#pos = pos + n;
|
|
175
|
+
this.#blockLen += n;
|
|
176
|
+
if (this.#blockLen < 512)
|
|
177
|
+
continue;
|
|
178
|
+
this.#blockLen = 0;
|
|
179
|
+
ev = this.#consumeHeader(block, 0);
|
|
180
|
+
}
|
|
181
|
+
if (ev)
|
|
182
|
+
return ev;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const blockRemain = this.#blockRemain;
|
|
186
|
+
const n = avail < blockRemain ? avail : blockRemain;
|
|
187
|
+
const remain = this.#remain;
|
|
188
|
+
const len = n < remain ? n : remain;
|
|
189
|
+
this.#pos = pos + n;
|
|
190
|
+
this.offset += n;
|
|
191
|
+
this.#blockRemain = blockRemain - n;
|
|
192
|
+
this.#remain = remain - len;
|
|
193
|
+
const last = n === blockRemain;
|
|
194
|
+
if (state === META) {
|
|
195
|
+
const meta = this.#meta;
|
|
196
|
+
meta.set(chunk.subarray(pos, pos + len), this.#metaLen);
|
|
197
|
+
this.#metaLen += len;
|
|
198
|
+
if (last) {
|
|
199
|
+
this.#endBody();
|
|
200
|
+
this.#applyMeta(meta);
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (last)
|
|
205
|
+
this.#endBody();
|
|
206
|
+
if (state === IGNORE)
|
|
207
|
+
continue;
|
|
208
|
+
if (len === 0) {
|
|
209
|
+
if (last)
|
|
210
|
+
return ENTRY_END;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
this.#entryEnd = last;
|
|
214
|
+
return {
|
|
215
|
+
type: 'body',
|
|
216
|
+
data: len === chunk.length ? chunk : chunk.subarray(pos, pos + len),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
#endBody() {
|
|
221
|
+
const entry = this.#entry;
|
|
222
|
+
if (entry) {
|
|
223
|
+
this.position = this.offset;
|
|
224
|
+
this.#entry = undefined;
|
|
225
|
+
}
|
|
226
|
+
if (!entry?.invalid)
|
|
227
|
+
this.#sawValid = true;
|
|
228
|
+
this.#state = HEADER;
|
|
229
|
+
}
|
|
230
|
+
// The input is complete, and all of it is read.
|
|
231
|
+
#finish() {
|
|
232
|
+
const state = this.#state;
|
|
233
|
+
if (state > HEADER) {
|
|
234
|
+
// The body of the last entry is not complete.
|
|
235
|
+
const entry = this.#entry;
|
|
236
|
+
// The bytes of the last block of the input, which is not
|
|
237
|
+
// complete, and the bytes from the start of that block to the
|
|
238
|
+
// end of the body. The chunks of the input do not change them.
|
|
239
|
+
const held = (512 - (this.#blockRemain % 512)) % 512;
|
|
240
|
+
const need = this.#blockRemain + held;
|
|
241
|
+
this.#entry = undefined;
|
|
242
|
+
this.#meta = undefined;
|
|
243
|
+
this.#state = HEADER;
|
|
244
|
+
if (!entry?.invalid)
|
|
245
|
+
this.#sawValid = true;
|
|
246
|
+
this.#entryEnd = state === BODY;
|
|
247
|
+
this.warn('TAR_BAD_ARCHIVE', `Truncated input (needed ${need} more bytes, only ${held} available)`, { entry, header: this.#header });
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
if (this.#entryEnd) {
|
|
251
|
+
this.#entryEnd = false;
|
|
252
|
+
return ENTRY_END;
|
|
253
|
+
}
|
|
254
|
+
if (this.#done === 0) {
|
|
255
|
+
this.#done = 1;
|
|
256
|
+
if (state === BEGIN || this.#sawValid === false) {
|
|
257
|
+
// Less than one block of data, or no valid entry.
|
|
258
|
+
this.warn('TAR_BAD_ARCHIVE', 'Unrecognized archive format');
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
this.#done = 2;
|
|
262
|
+
return END;
|
|
263
|
+
}
|
|
264
|
+
#consumeHeader(buf, off) {
|
|
265
|
+
this.offset += 512;
|
|
266
|
+
if (this.#sawValid === undefined)
|
|
267
|
+
this.#sawValid = false;
|
|
268
|
+
// A PAX name wins over a GNU long name. The header does not use
|
|
269
|
+
// these values if it is a PAX or GNU header itself.
|
|
270
|
+
let ex = this.#ex;
|
|
271
|
+
const longPath = this.#longPath;
|
|
272
|
+
const longLinkpath = this.#longLinkpath;
|
|
273
|
+
if (longPath !== undefined || longLinkpath !== undefined) {
|
|
274
|
+
ex = Object.assign(Object.create(null), ex);
|
|
275
|
+
ex.path ??= longPath;
|
|
276
|
+
ex.linkpath ??= longLinkpath;
|
|
277
|
+
}
|
|
278
|
+
let header;
|
|
279
|
+
try {
|
|
280
|
+
header = new Header(buf, off, ex, this.#gex);
|
|
281
|
+
}
|
|
282
|
+
catch (er) {
|
|
283
|
+
this.warn('TAR_ENTRY_INVALID', er);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (header.nullBlock) {
|
|
287
|
+
// A null block is the end of the archive, as it is for bsdtar.
|
|
288
|
+
// A second null block normally comes after it. All the data
|
|
289
|
+
// after the first one is dropped, so an entry there is not
|
|
290
|
+
// read.
|
|
291
|
+
this.#ended = true;
|
|
292
|
+
this.#chunk = undefined;
|
|
293
|
+
this.#queue.length = 0;
|
|
294
|
+
this.#blockLen = 0;
|
|
295
|
+
// The input is not shorter than one block. An archive with no
|
|
296
|
+
// valid entry still gets the warning of `#finish`.
|
|
297
|
+
this.#state = HEADER;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (!header.cksumValid) {
|
|
301
|
+
this.warn('TAR_ENTRY_INVALID', 'checksum failure', { header });
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (!header.path) {
|
|
305
|
+
this.warn('TAR_ENTRY_INVALID', 'path is required', { header });
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const type = header.type;
|
|
309
|
+
const link = type === 'Link' || type === 'SymbolicLink';
|
|
310
|
+
if (link && !header.linkpath) {
|
|
311
|
+
this.warn('TAR_ENTRY_INVALID', 'linkpath required', { header });
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (!link &&
|
|
315
|
+
header.linkpath &&
|
|
316
|
+
type !== 'ExtendedHeader' &&
|
|
317
|
+
type !== 'GlobalExtendedHeader') {
|
|
318
|
+
this.warn('TAR_ENTRY_INVALID', 'linkpath forbidden', { header });
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const size = header.size ?? 0;
|
|
322
|
+
this.#header = header;
|
|
323
|
+
this.#remain = size;
|
|
324
|
+
this.#blockRemain = 512 * Math.ceil(size / 512);
|
|
325
|
+
// A meta entry or an ignored entry is valid tar also.
|
|
326
|
+
if (!size)
|
|
327
|
+
this.#sawValid = true;
|
|
328
|
+
if (metaTypes.has(type)) {
|
|
329
|
+
if (size > this.maxMetaEntrySize) {
|
|
330
|
+
this.#state = IGNORE;
|
|
331
|
+
}
|
|
332
|
+
else if (size > 0) {
|
|
333
|
+
this.#meta = new Uint8Array(size);
|
|
334
|
+
this.#metaLen = 0;
|
|
335
|
+
this.#state = META;
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
this.#ex = this.#longPath = this.#longLinkpath = undefined;
|
|
340
|
+
const entry = this.#create(header, ex, this.#gex);
|
|
341
|
+
if (!entry.ignore &&
|
|
342
|
+
this.#filter &&
|
|
343
|
+
!this.#filter(entry.path, entry)) {
|
|
344
|
+
entry.ignore = true;
|
|
345
|
+
}
|
|
346
|
+
if (size) {
|
|
347
|
+
this.#entry = entry;
|
|
348
|
+
this.#state = entry.ignore ? IGNORE : BODY;
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
this.#state = HEADER;
|
|
352
|
+
this.position = this.offset;
|
|
353
|
+
this.#entryEnd = !entry.ignore;
|
|
354
|
+
}
|
|
355
|
+
return { type: 'entry', entry };
|
|
356
|
+
}
|
|
357
|
+
#applyMeta(meta) {
|
|
358
|
+
switch (this.#header.type) {
|
|
359
|
+
case 'ExtendedHeader':
|
|
360
|
+
case 'OldExtendedHeader':
|
|
361
|
+
this.#ex = Pax.parseBytes(meta, this.#ex, false);
|
|
362
|
+
break;
|
|
363
|
+
case 'GlobalExtendedHeader':
|
|
364
|
+
this.#gex = Pax.parseBytes(meta, this.#gex, true);
|
|
365
|
+
break;
|
|
366
|
+
// The last GNU long name of each kind is the one to use.
|
|
367
|
+
case 'NextFileHasLongPath':
|
|
368
|
+
case 'OldGnuLongPath':
|
|
369
|
+
this.#longPath = cstring(meta);
|
|
370
|
+
break;
|
|
371
|
+
// NextFileHasLongLinkpath
|
|
372
|
+
default:
|
|
373
|
+
this.#longLinkpath = cstring(meta);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE9B,OAAO,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAmC,MAAM,WAAW,CAAA;AAwBjE,MAAM,KAAK,GAAG,CAAC,CAAA;AACf,MAAM,MAAM,GAAG,CAAC,CAAA;AAChB,MAAM,IAAI,GAAG,CAAC,CAAA;AACd,MAAM,MAAM,GAAG,CAAC,CAAA;AAChB,M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M,GAAG,KAAK,CAAA;YACnB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;QAC5C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;YACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAA;YAC3B,IAAI,CAAC,SAAS,GAAG,CAAC,KAAK,CAAC,MAAM,CAAA;QAChC,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IACjC,CAAC;IAED,UAAU,CAAC,IAAgB;QACzB,QAAS,IAAI,CAAC,OAAkB,CAAC,IAAI,EAAE,CAAC;YACtC,KAAK,gBAAgB,CAAC;YACtB,KAAK,mBAAmB;gBACtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;gBAChD,MAAK;YACP,KAAK,sBAAsB;gBACzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;gBACjD,MAAK;YACP,yDAAyD;YACzD,KAAK,qBAAqB,CAAC;YAC3B,KAAK,gBAAgB;gBACnB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;gBAC9B,MAAK;YACP,0BAA0B;YAC1B;gBACE,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;CACF","sourcesContent":["import { decodeUtf8 } from './bytes.js'\nimport { Header } from './header.js'\nimport { Pax } from './pax.js'\nimport type { EntryTypeName } from './types.js'\nimport { ownOptions, type ParserOptions } from './options.js'\nimport { EntryData } from './read-entry.js'\nimport { warn, type WarnData, type WarnOptions } from './warn.js'\n\n/** What `Parser.next()` returns. */\nexport type ParseEvent<E extends EntryData = EntryData> =\n /**\n * An entry that is not a PAX or GNU meta entry. If `entry.ignore`\n * is set, the parser skips the body, and no other event follows\n * for this entry.\n */\n | { type: 'entry'; entry: E }\n /** A part of the body of the entry. A view into the input. */\n | { type: 'body'; data: Uint8Array }\n /** The end of the body of the entry. */\n | { type: 'entryEnd' }\n /** The end of the archive. No event follows. */\n | { type: 'end' }\n\n/** Makes the entry object for a header. */\nexport type CreateEntry<E extends EntryData> = (\n header: Header,\n ex: Pax | undefined,\n gex: Pax | undefined,\n) => E\n\nconst BEGIN = 0\nconst HEADER = 1\nconst BODY = 2\nconst IGNORE = 3\nconst META = 4\n\nconst ENTRY_END = { type: 'entryEnd' } as const\nconst END = { type: 'end' } as const\n\nconst metaTypes = new Set<EntryTypeName>([\n 'ExtendedHeader',\n 'OldExtendedHeader',\n 'GlobalExtendedHeader',\n 'NextFileHasLongPath',\n 'OldGnuLongPath',\n 'NextFileHasLongLinkpath',\n])\n\n// The text up to the first NUL.\nconst cstring = (buf: Uint8Array) => {\n const nul = buf.indexOf(0)\n return decodeUtf8(buf, 0, nul === -1 ? buf.length : nul)\n}\n\n/**\n * A tar parser that the caller pulls. Give it input with `push()`,\n * and call `next()` for each event until it returns `undefined`.\n * Then give it more input, or call `end()` and call `next()` again.\n *\n * It does not decompress. It calls no code of the caller but\n * `filter`, `onwarn`, and the function that makes the entry objects.\n *\n * With `strict`, `next()` throws at each problem. The parser stays\n * usable: the next call continues after the block with the problem.\n */\nexport class Parser<E extends EntryData = EntryData> {\n maxMetaEntrySize: number\n /**\n * The number of input bytes up to the end of the last complete\n * entry that is not a meta entry.\n */\n position: number = 0\n /**\n * The number of input bytes that are parsed: the header blocks and\n * the body blocks. At an `entry` event, it is the place of the body\n * of the entry in the input.\n */\n offset: number = 0\n\n #opt: WarnOptions\n #filter?: (path: string, entry: E) => boolean\n #create: CreateEntry<E>\n #queue: Uint8Array[] = []\n #chunk?: Uint8Array\n #pos: number = 0\n // a header block that is in more than one chunk\n #block?: Uint8Array\n #blockLen: number = 0\n #state: number = BEGIN\n // the entry of the body that is read or skipped now\n #entry?: E\n #header?: Header\n #meta?: Uint8Array\n #metaLen: number = 0\n // body bytes to come, without and with the padding\n #remain: number = 0\n #blockRemain: number = 0\n #ex?: Pax\n // the names of the GNU long name headers for the next entry\n #longPath?: string\n #longLinkpath?: string\n #gex?: Pax\n #ended: boolean = false\n #sawValid?: boolean\n #entryEnd: boolean = false\n // 0: reading, 1: the end is found, 2: the end event is returned\n #done: number = 0\n\n /**\n * @param createEntry makes the object for each entry event. It is\n * required if `E` is not `EntryData`.\n */\n constructor(opt: ParserOptions<E> = {}, createEntry?: CreateEntry<E>) {\n opt = this.#opt = ownOptions(opt)\n this.maxMetaEntrySize = opt.maxMetaEntrySize || 1024 * 1024\n this.#filter = opt.filter\n const win32 = opt.platform === 'win32'\n this.#create =\n createEntry ??\n ((header, ex, gex) => new EntryData(header, ex, gex, win32) as E)\n }\n\n /**\n * Report a problem to `onwarn`. Throws if `strict` is set, or if\n * `data.recoverable` is false.\n */\n warn(code: string, message: string | Error, data?: WarnData): void {\n warn(this.#opt, code, message, data)\n }\n\n /**\n * Add input. The parser keeps the chunk until `next()` returns\n * `undefined`, and each body event is a view into it. Input after\n * `end()`, or after the end of the archive, is dropped.\n */\n push(chunk: Uint8Array): void {\n if (!this.#ended) this.#queue.push(chunk)\n }\n\n /** Tell the parser that the input is complete. */\n end(): void {\n this.#ended = true\n }\n\n /**\n * The number of bytes of the body of the current entry, with its\n * padding, that are after the input given so far. The caller can\n * skip them in its input, and call `skipBody()`. It is 0 if the\n * parser has input that it did not parse, and in a PAX or GNU\n * header, because the parser reads that body.\n */\n get bodyRemain(): number {\n const chunk = this.#chunk\n const state = this.#state\n return (\n (state !== BODY && state !== IGNORE) ||\n this.#queue.length ||\n (chunk && this.#pos < chunk.length)\n ) ?\n 0\n : this.#blockRemain\n }\n\n /**\n * Count the `bodyRemain` bytes as parsed. The next input is the\n * header after the body.\n */\n skipBody(): void {\n this.#entryEnd = this.#state === BODY\n this.offset += this.#blockRemain\n this.#remain = this.#blockRemain = 0\n this.#endBody()\n }\n\n /**\n * The next event. `undefined` means that the parser needs more\n * input, or after the `end` event, that it is done.\n */\n next(): ParseEvent<E> | undefined {\n if (this.#entryEnd) {\n this.#entryEnd = false\n return ENTRY_END\n }\n for (;;) {\n let chunk = this.#chunk\n let pos = this.#pos\n if (!chunk || pos === chunk.length) {\n chunk = this.#chunk = this.#queue.shift()\n pos = this.#pos = 0\n if (!chunk) {\n if (!this.#ended || this.#done === 2) return undefined\n const ev = this.#finish()\n if (ev) return ev\n }\n continue\n }\n const avail = chunk.length - pos\n const state = this.#state\n\n if (state <= HEADER) {\n let ev: ParseEvent<E> | undefined\n if (this.#blockLen === 0 && avail >= 512) {\n this.#pos = pos + 512\n ev = this.#consumeHeader(chunk, pos)\n } else {\n const block = (this.#block ??= new Uint8Array(512))\n const n = Math.min(512 - this.#blockLen, avail)\n block.set(chunk.subarray(pos, pos + n), this.#blockLen)\n this.#pos = pos + n\n this.#blockLen += n\n if (this.#blockLen < 512) continue\n this.#blockLen = 0\n ev = this.#consumeHeader(block, 0)\n }\n if (ev) return ev\n continue\n }\n\n const blockRemain = this.#blockRemain\n const n = avail < blockRemain ? avail : blockRemain\n const remain = this.#remain\n const len = n < remain ? n : remain\n this.#pos = pos + n\n this.offset += n\n this.#blockRemain = blockRemain - n\n this.#remain = remain - len\n const last = n === blockRemain\n\n if (state === META) {\n const meta = this.#meta as Uint8Array\n meta.set(chunk.subarray(pos, pos + len), this.#metaLen)\n this.#metaLen += len\n if (last) {\n this.#endBody()\n this.#applyMeta(meta)\n }\n continue\n }\n if (last) this.#endBody()\n if (state === IGNORE) continue\n if (len === 0) {\n if (last) return ENTRY_END\n continue\n }\n this.#entryEnd = last\n return {\n type: 'body',\n data:\n len === chunk.length ? chunk : chunk.subarray(pos, pos + len),\n }\n }\n }\n\n #endBody() {\n const entry = this.#entry\n if (entry) {\n this.position = this.offset\n this.#entry = undefined\n }\n if (!entry?.invalid) this.#sawValid = true\n this.#state = HEADER\n }\n\n // The input is complete, and all of it is read.\n #finish(): ParseEvent<E> | undefined {\n const state = this.#state\n if (state > HEADER) {\n // The body of the last entry is not complete.\n const entry = this.#entry\n // The bytes of the last block of the input, which is not\n // complete, and the bytes from the start of that block to the\n // end of the body. The chunks of the input do not change them.\n const held = (512 - (this.#blockRemain % 512)) % 512\n const need = this.#blockRemain + held\n this.#entry = undefined\n this.#meta = undefined\n this.#state = HEADER\n if (!entry?.invalid) this.#sawValid = true\n this.#entryEnd = state === BODY\n this.warn(\n 'TAR_BAD_ARCHIVE',\n `Truncated input (needed ${need} more bytes, only ${held} available)`,\n { entry, header: this.#header },\n )\n return undefined\n }\n if (this.#entryEnd) {\n this.#entryEnd = false\n return ENTRY_END\n }\n if (this.#done === 0) {\n this.#done = 1\n if (state === BEGIN || this.#sawValid === false) {\n // Less than one block of data, or no valid entry.\n this.warn('TAR_BAD_ARCHIVE', 'Unrecognized archive format')\n }\n }\n this.#done = 2\n return END\n }\n\n #consumeHeader(buf: Uint8Array, off: number): ParseEvent<E> | undefined {\n this.offset += 512\n if (this.#sawValid === undefined) this.#sawValid = false\n // A PAX name wins over a GNU long name. The header does not use\n // these values if it is a PAX or GNU header itself.\n let ex = this.#ex\n const longPath = this.#longPath\n const longLinkpath = this.#longLinkpath\n if (longPath !== undefined || longLinkpath !== undefined) {\n ex = Object.assign(Object.create(null) as Pax, ex)\n ex.path ??= longPath\n ex.linkpath ??= longLinkpath\n }\n let header: Header\n try {\n header = new Header(buf, off, ex, this.#gex)\n } catch (er) {\n this.warn('TAR_ENTRY_INVALID', er as Error)\n return\n }\n\n if (header.nullBlock) {\n // A null block is the end of the archive, as it is for bsdtar.\n // A second null block normally comes after it. All the data\n // after the first one is dropped, so an entry there is not\n // read.\n this.#ended = true\n this.#chunk = undefined\n this.#queue.length = 0\n this.#blockLen = 0\n // The input is not shorter than one block. An archive with no\n // valid entry still gets the warning of `#finish`.\n this.#state = HEADER\n return\n }\n\n if (!header.cksumValid) {\n this.warn('TAR_ENTRY_INVALID', 'checksum failure', { header })\n return\n }\n if (!header.path) {\n this.warn('TAR_ENTRY_INVALID', 'path is required', { header })\n return\n }\n const type = header.type\n const link = type === 'Link' || type === 'SymbolicLink'\n if (link && !header.linkpath) {\n this.warn('TAR_ENTRY_INVALID', 'linkpath required', { header })\n return\n }\n if (\n !link &&\n header.linkpath &&\n type !== 'ExtendedHeader' &&\n type !== 'GlobalExtendedHeader'\n ) {\n this.warn('TAR_ENTRY_INVALID', 'linkpath forbidden', { header })\n return\n }\n\n const size = header.size ?? 0\n this.#header = header\n this.#remain = size\n this.#blockRemain = 512 * Math.ceil(size / 512)\n // A meta entry or an ignored entry is valid tar also.\n if (!size) this.#sawValid = true\n\n if (metaTypes.has(type)) {\n if (size > this.maxMetaEntrySize) {\n this.#state = IGNORE\n } else if (size > 0) {\n this.#meta = new Uint8Array(size)\n this.#metaLen = 0\n this.#state = META\n }\n return\n }\n\n this.#ex = this.#longPath = this.#longLinkpath = undefined\n const entry = this.#create(header, ex, this.#gex)\n if (\n !entry.ignore &&\n this.#filter &&\n !this.#filter(entry.path, entry)\n ) {\n entry.ignore = true\n }\n if (size) {\n this.#entry = entry\n this.#state = entry.ignore ? IGNORE : BODY\n } else {\n this.#state = HEADER\n this.position = this.offset\n this.#entryEnd = !entry.ignore\n }\n return { type: 'entry', entry }\n }\n\n #applyMeta(meta: Uint8Array) {\n switch ((this.#header as Header).type) {\n case 'ExtendedHeader':\n case 'OldExtendedHeader':\n this.#ex = Pax.parseBytes(meta, this.#ex, false)\n break\n case 'GlobalExtendedHeader':\n this.#gex = Pax.parseBytes(meta, this.#gex, true)\n break\n // The last GNU long name of each kind is the one to use.\n case 'NextFileHasLongPath':\n case 'OldGnuLongPath':\n this.#longPath = cstring(meta)\n break\n // NextFileHasLongLinkpath\n default:\n this.#longLinkpath = cstring(meta)\n }\n }\n}\n"]}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Gives each task the exclusive use of its paths, and the shared use
|
|
3
|
+
* of their parent directories. A task starts when each task before
|
|
4
|
+
* it that uses one of its paths, or a directory above or below one,
|
|
5
|
+
* is done.
|
|
6
|
+
*
|
|
7
|
+
* Paths that differ only in case or in Unicode form are the same
|
|
8
|
+
* path, because they can be the same file on disk.
|
|
9
|
+
*/
|
|
6
10
|
export declare class PathReservations {
|
|
7
11
|
#private;
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
/** @param win32 run one task at a time */
|
|
13
|
+
constructor(win32?: boolean);
|
|
14
|
+
/**
|
|
15
|
+
* Call `fn` when it is first in line for each of its paths. The
|
|
16
|
+
* paths are free again when the promise of `fn` settles. Returns a
|
|
17
|
+
* promise with the result of `fn`.
|
|
18
|
+
*/
|
|
19
|
+
reserve(paths: string[], fn: () => Promise<void>): Promise<void>;
|
|
10
20
|
}
|
|
11
21
|
//# sourceMappingURL=path-reservations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-reservations.d.ts","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path-reservations.d.ts","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":"AAsBA;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;;IAS3B,0CAA0C;gBAC9B,KAAK,GAAE,OAAe;IAIlC;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAgGjE"}
|