tar 7.5.24 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1712 -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 -43
- 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 +143 -89
- package/dist/commonjs/unpack.d.ts.map +1 -1
- package/dist/commonjs/unpack.js +782 -725
- 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 -42
- 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 +143 -89
- package/dist/esm/unpack.d.ts.map +1 -1
- package/dist/esm/unpack.js +778 -719
- 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,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entriesSync = exports.entries = exports.TarReaderSync = exports.TarReader = exports.EntryCursor = exports.findCodec = exports.headLength = void 0;
|
|
4
|
+
const bytes_js_1 = require("./bytes.js");
|
|
5
|
+
const header_js_1 = require("./header.js");
|
|
6
|
+
const codec_js_1 = require("./codec.js");
|
|
7
|
+
const concat_js_1 = require("./concat.js");
|
|
8
|
+
const options_js_1 = require("./options.js");
|
|
9
|
+
const parser_js_1 = require("./parser.js");
|
|
10
|
+
const read_entry_js_1 = require("./read-entry.js");
|
|
11
|
+
const read_file_js_1 = require("./read-file.js");
|
|
12
|
+
const warn_js_1 = require("./warn.js");
|
|
13
|
+
const noop = () => { };
|
|
14
|
+
// The number of bytes to read before the choice of a codec.
|
|
15
|
+
const headLength = (codecs) => Math.max(512, ...codecs.map(c => c.headLength));
|
|
16
|
+
exports.headLength = headLength;
|
|
17
|
+
const isTar = (head) => {
|
|
18
|
+
try {
|
|
19
|
+
const header = new header_js_1.Header(head);
|
|
20
|
+
return header.cksumValid || header.nullBlock;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const findCodec = (codecs, head, file = '') => codecs.find(c => c.detect(head)) ??
|
|
27
|
+
(isTar(head) ? undefined : (codecs.find(c => c.extensions?.some(x => file.endsWith(x)))));
|
|
28
|
+
exports.findCodec = findCodec;
|
|
29
|
+
const maxRatio = (opt) => typeof opt.maxDecompressionRatio === 'number' ?
|
|
30
|
+
opt.maxDecompressionRatio
|
|
31
|
+
: 1000;
|
|
32
|
+
const abort = (opt, er) => (0, warn_js_1.tarError)(opt, 'TAR_ABORT', er, { recoverable: false });
|
|
33
|
+
const ratioError = (opt, ratio, max) => abort(opt, new Error(`max decompression ratio exceeded: ${ratio.toFixed(2)} > ${max}`));
|
|
34
|
+
const notCurrent = () => new TypeError('The body of an entry cannot be read after a later entry');
|
|
35
|
+
/**
|
|
36
|
+
* Gets entries and the parts of their bodies from a `Parser`. The
|
|
37
|
+
* readers use it. It does not read input.
|
|
38
|
+
*/
|
|
39
|
+
class EntryCursor {
|
|
40
|
+
parser;
|
|
41
|
+
/** The entry that has a body to read now. */
|
|
42
|
+
current;
|
|
43
|
+
/** True after the end of the archive. */
|
|
44
|
+
ended = false;
|
|
45
|
+
constructor(parser) {
|
|
46
|
+
this.parser = parser;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The next entry that is not ignored. `null` at the end of the
|
|
50
|
+
* archive. `undefined` if the parser needs more input. The rest of
|
|
51
|
+
* the body of the entry before it is skipped.
|
|
52
|
+
*/
|
|
53
|
+
entry() {
|
|
54
|
+
this.current = undefined;
|
|
55
|
+
if (this.ended)
|
|
56
|
+
return null;
|
|
57
|
+
for (let ev; (ev = this.parser.next());) {
|
|
58
|
+
if (ev.type === 'end') {
|
|
59
|
+
this.ended = true;
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (ev.type === 'entry' && !ev.entry.ignore) {
|
|
63
|
+
return (this.current = ev.entry);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The next part of the body of `entry`. `null` at the end of the
|
|
69
|
+
* body. `undefined` if the parser needs more input.
|
|
70
|
+
*/
|
|
71
|
+
body(entry) {
|
|
72
|
+
if (entry !== this.current)
|
|
73
|
+
throw notCurrent();
|
|
74
|
+
const ev = this.parser.next();
|
|
75
|
+
if (!ev)
|
|
76
|
+
return undefined;
|
|
77
|
+
if (ev.type === 'body')
|
|
78
|
+
return ev.data;
|
|
79
|
+
this.current = undefined;
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.EntryCursor = EntryCursor;
|
|
84
|
+
// Skip the rest of a body that no consumer reads, if it is after the
|
|
85
|
+
// input that the parser has, and the source can skip it. The source
|
|
86
|
+
// must be the input of the reader: decompressed data has no place in
|
|
87
|
+
// the input.
|
|
88
|
+
const skipBody = (cursor, source) => {
|
|
89
|
+
if (cursor.current)
|
|
90
|
+
return;
|
|
91
|
+
const n = cursor.parser.bodyRemain;
|
|
92
|
+
if (n && source[read_file_js_1.SKIP]?.(n))
|
|
93
|
+
cursor.parser.skipBody();
|
|
94
|
+
};
|
|
95
|
+
const toSource = (input) => {
|
|
96
|
+
if ((0, bytes_js_1.isUint8Array)(input))
|
|
97
|
+
return [input].values();
|
|
98
|
+
if ((0, bytes_js_1.isArrayBuffer)(input))
|
|
99
|
+
return [new Uint8Array(input)].values();
|
|
100
|
+
if ((0, bytes_js_1.isBlob)(input))
|
|
101
|
+
input = input.stream();
|
|
102
|
+
if ((0, bytes_js_1.isReadableStream)(input)) {
|
|
103
|
+
const reader = input.getReader();
|
|
104
|
+
return { next: () => reader.read(), return: () => reader.cancel() };
|
|
105
|
+
}
|
|
106
|
+
return Symbol.asyncIterator in input ?
|
|
107
|
+
input[Symbol.asyncIterator]()
|
|
108
|
+
: input[Symbol.iterator]();
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Reads the entries of an archive from async input. It is the
|
|
112
|
+
* iterator that `entries()` returns.
|
|
113
|
+
*
|
|
114
|
+
* Input is read only when the consumer asks for the next entry or
|
|
115
|
+
* for more of a body. `poll()` and `fill()` do the same work as
|
|
116
|
+
* `next()`, with no promise for an entry that is in memory.
|
|
117
|
+
*/
|
|
118
|
+
class TarReader {
|
|
119
|
+
parser;
|
|
120
|
+
#cursor;
|
|
121
|
+
#opt;
|
|
122
|
+
#input;
|
|
123
|
+
#source;
|
|
124
|
+
// the first bytes of input that is not compressed
|
|
125
|
+
#head;
|
|
126
|
+
#filling;
|
|
127
|
+
#done = false;
|
|
128
|
+
constructor(input, opt = {}) {
|
|
129
|
+
opt = (0, options_js_1.ownOptions)(opt);
|
|
130
|
+
const win32 = opt.platform === 'win32';
|
|
131
|
+
this.parser = new parser_js_1.Parser(opt, (header, ex, gex) => new read_entry_js_1.ReadEntry(header, ex, gex, win32, this));
|
|
132
|
+
this.#cursor = new EntryCursor(this.parser);
|
|
133
|
+
this.#opt = opt;
|
|
134
|
+
this.#input = toSource(input);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The next entry, if it is in memory. `null` at the end of the
|
|
138
|
+
* archive. `undefined` if more input is needed: then await `fill()`
|
|
139
|
+
* and call this again.
|
|
140
|
+
*/
|
|
141
|
+
poll() {
|
|
142
|
+
return this.#done ? null : this.#cursor.entry();
|
|
143
|
+
}
|
|
144
|
+
readBody(entry) {
|
|
145
|
+
return this.#cursor.body(entry);
|
|
146
|
+
}
|
|
147
|
+
/** Read one chunk of input, and give it to the parser. */
|
|
148
|
+
fill() {
|
|
149
|
+
return (this.#filling ??= this.#fill());
|
|
150
|
+
}
|
|
151
|
+
async #fill() {
|
|
152
|
+
try {
|
|
153
|
+
const source = (this.#source ??= await this.#open(this.#input));
|
|
154
|
+
const head = this.#head;
|
|
155
|
+
this.#head = undefined;
|
|
156
|
+
if (source === this.#input)
|
|
157
|
+
skipBody(this.#cursor, source);
|
|
158
|
+
const res = head ? { value: head, done: false } : await source.next();
|
|
159
|
+
if (res.done)
|
|
160
|
+
this.parser.end();
|
|
161
|
+
else
|
|
162
|
+
this.parser.push(res.value);
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
this.#filling = undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Read the first bytes, and add the decompression if they need it.
|
|
169
|
+
async #open(input) {
|
|
170
|
+
const opt = this.#opt;
|
|
171
|
+
const codecs = [...(opt.codecs ?? []), codec_js_1.gzip];
|
|
172
|
+
const need = (0, exports.headLength)(codecs);
|
|
173
|
+
let head;
|
|
174
|
+
while (!head || head.length < need) {
|
|
175
|
+
const res = await input.next();
|
|
176
|
+
if (res.done)
|
|
177
|
+
break;
|
|
178
|
+
head = head ? (0, concat_js_1.concat)([head, res.value]) : res.value;
|
|
179
|
+
}
|
|
180
|
+
const codec = head && (0, exports.findCodec)(codecs, head, opt.file);
|
|
181
|
+
if (!codec) {
|
|
182
|
+
this.#head = head;
|
|
183
|
+
return input;
|
|
184
|
+
}
|
|
185
|
+
let compressed = 0;
|
|
186
|
+
let decompressed = 0;
|
|
187
|
+
const { readable, writable } = codec.decompress();
|
|
188
|
+
const writer = writable.getWriter();
|
|
189
|
+
const reader = readable.getReader();
|
|
190
|
+
let stopped = false;
|
|
191
|
+
// Give the input to the codec, as fast as the codec takes it. This
|
|
192
|
+
// loop holds each promise of the writer, so that a write that
|
|
193
|
+
// fails after the consumer stops is not an unhandled rejection.
|
|
194
|
+
const feed = async () => {
|
|
195
|
+
try {
|
|
196
|
+
for (;;) {
|
|
197
|
+
await writer.ready;
|
|
198
|
+
if (stopped)
|
|
199
|
+
return;
|
|
200
|
+
const res = head ? { value: head, done: false } : await input.next();
|
|
201
|
+
head = undefined;
|
|
202
|
+
if (stopped)
|
|
203
|
+
return;
|
|
204
|
+
if (res.done)
|
|
205
|
+
return await writer.close();
|
|
206
|
+
compressed += res.value.length;
|
|
207
|
+
await writer.write(res.value);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (er) {
|
|
211
|
+
// An error of the input goes to the reader of the output. An
|
|
212
|
+
// error of the codec is there already.
|
|
213
|
+
if (!stopped)
|
|
214
|
+
await writer.abort(er).catch(noop);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
void feed();
|
|
218
|
+
const max = maxRatio(opt);
|
|
219
|
+
return {
|
|
220
|
+
next: async () => {
|
|
221
|
+
const res = await reader.read().catch(er => {
|
|
222
|
+
throw abort(opt, er);
|
|
223
|
+
});
|
|
224
|
+
if (!res.done) {
|
|
225
|
+
decompressed += res.value.length;
|
|
226
|
+
const ratio = decompressed / compressed;
|
|
227
|
+
if (ratio > max)
|
|
228
|
+
throw ratioError(opt, ratio, max);
|
|
229
|
+
}
|
|
230
|
+
return res;
|
|
231
|
+
},
|
|
232
|
+
return: async () => {
|
|
233
|
+
stopped = true;
|
|
234
|
+
await reader.cancel().catch(noop);
|
|
235
|
+
await writer.abort().catch(noop);
|
|
236
|
+
await input.return?.();
|
|
237
|
+
return { value: undefined, done: true };
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async next() {
|
|
242
|
+
try {
|
|
243
|
+
for (;;) {
|
|
244
|
+
const entry = this.poll();
|
|
245
|
+
if (entry)
|
|
246
|
+
return { value: entry, done: false };
|
|
247
|
+
if (entry === null)
|
|
248
|
+
break;
|
|
249
|
+
await this.fill();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (er) {
|
|
253
|
+
await this.return();
|
|
254
|
+
throw er;
|
|
255
|
+
}
|
|
256
|
+
return this.return();
|
|
257
|
+
}
|
|
258
|
+
/** Stop reading, and release the input. */
|
|
259
|
+
async return() {
|
|
260
|
+
if (!this.#done) {
|
|
261
|
+
this.#done = true;
|
|
262
|
+
this.#cursor.current = undefined;
|
|
263
|
+
await (this.#source ?? this.#input).return?.();
|
|
264
|
+
}
|
|
265
|
+
return { value: undefined, done: true };
|
|
266
|
+
}
|
|
267
|
+
[Symbol.asyncIterator]() {
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
exports.TarReader = TarReader;
|
|
272
|
+
/**
|
|
273
|
+
* Reads the entries of an archive from sync input. It is the
|
|
274
|
+
* iterator that `entriesSync()` returns.
|
|
275
|
+
*/
|
|
276
|
+
class TarReaderSync {
|
|
277
|
+
parser;
|
|
278
|
+
#cursor;
|
|
279
|
+
#opt;
|
|
280
|
+
#input;
|
|
281
|
+
#source;
|
|
282
|
+
// the first bytes of input that is not compressed
|
|
283
|
+
#head;
|
|
284
|
+
#done = false;
|
|
285
|
+
constructor(input, opt = {}) {
|
|
286
|
+
opt = (0, options_js_1.ownOptions)(opt);
|
|
287
|
+
const win32 = opt.platform === 'win32';
|
|
288
|
+
this.parser = new parser_js_1.Parser(opt, (header, ex, gex) => new read_entry_js_1.ReadEntrySync(header, ex, gex, win32, this));
|
|
289
|
+
this.#cursor = new EntryCursor(this.parser);
|
|
290
|
+
this.#opt = opt;
|
|
291
|
+
this.#input =
|
|
292
|
+
(0, bytes_js_1.isUint8Array)(input) ? [input].values()
|
|
293
|
+
: (0, bytes_js_1.isArrayBuffer)(input) ? [new Uint8Array(input)].values()
|
|
294
|
+
: input[Symbol.iterator]();
|
|
295
|
+
}
|
|
296
|
+
readBody(entry) {
|
|
297
|
+
for (;;) {
|
|
298
|
+
const part = this.#cursor.body(entry);
|
|
299
|
+
if (part !== undefined)
|
|
300
|
+
return part;
|
|
301
|
+
this.#fill();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
#fill() {
|
|
305
|
+
const source = (this.#source ??= this.#open(this.#input));
|
|
306
|
+
const head = this.#head;
|
|
307
|
+
this.#head = undefined;
|
|
308
|
+
if (source === this.#input)
|
|
309
|
+
skipBody(this.#cursor, source);
|
|
310
|
+
const res = head ? { value: head, done: false } : source.next();
|
|
311
|
+
if (res.done)
|
|
312
|
+
this.parser.end();
|
|
313
|
+
else
|
|
314
|
+
this.parser.push(res.value);
|
|
315
|
+
}
|
|
316
|
+
// Read the first bytes. If they are compressed, read and decompress
|
|
317
|
+
// all the input.
|
|
318
|
+
#open(input) {
|
|
319
|
+
const opt = this.#opt;
|
|
320
|
+
const codecs = [...(opt.codecs ?? []), codec_js_1.gzip];
|
|
321
|
+
const need = (0, exports.headLength)(codecs);
|
|
322
|
+
let head;
|
|
323
|
+
let res;
|
|
324
|
+
while ((!head || head.length < need) && !(res = input.next()).done) {
|
|
325
|
+
head = head ? (0, concat_js_1.concat)([head, res.value]) : res.value;
|
|
326
|
+
}
|
|
327
|
+
const codec = head && (0, exports.findCodec)(codecs, head, opt.file);
|
|
328
|
+
if (!head || !codec) {
|
|
329
|
+
this.#head = head;
|
|
330
|
+
return input;
|
|
331
|
+
}
|
|
332
|
+
const { decompressSync } = codec;
|
|
333
|
+
if (!decompressSync) {
|
|
334
|
+
throw abort(opt, new Error(`the ${codec.name} codec has no decompressSync function`));
|
|
335
|
+
}
|
|
336
|
+
const parts = [head];
|
|
337
|
+
while (!(res = input.next()).done)
|
|
338
|
+
parts.push(res.value);
|
|
339
|
+
const data = (0, concat_js_1.concat)(parts);
|
|
340
|
+
const max = maxRatio(opt);
|
|
341
|
+
let out;
|
|
342
|
+
try {
|
|
343
|
+
out = decompressSync(data, { maxOutputLength: data.length * max });
|
|
344
|
+
}
|
|
345
|
+
catch (er) {
|
|
346
|
+
throw abort(opt, er);
|
|
347
|
+
}
|
|
348
|
+
const ratio = out.length / data.length;
|
|
349
|
+
if (ratio > max)
|
|
350
|
+
throw ratioError(opt, ratio, max);
|
|
351
|
+
return [out].values();
|
|
352
|
+
}
|
|
353
|
+
next() {
|
|
354
|
+
try {
|
|
355
|
+
for (;;) {
|
|
356
|
+
const entry = this.#done ? null : this.#cursor.entry();
|
|
357
|
+
if (entry)
|
|
358
|
+
return { value: entry, done: false };
|
|
359
|
+
if (entry === null)
|
|
360
|
+
break;
|
|
361
|
+
this.#fill();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
catch (er) {
|
|
365
|
+
this.return();
|
|
366
|
+
throw er;
|
|
367
|
+
}
|
|
368
|
+
return this.return();
|
|
369
|
+
}
|
|
370
|
+
/** Stop reading, and release the input. */
|
|
371
|
+
return() {
|
|
372
|
+
if (!this.#done) {
|
|
373
|
+
this.#done = true;
|
|
374
|
+
this.#cursor.current = undefined;
|
|
375
|
+
(this.#source ?? this.#input).return?.();
|
|
376
|
+
}
|
|
377
|
+
return { value: undefined, done: true };
|
|
378
|
+
}
|
|
379
|
+
[Symbol.iterator]() {
|
|
380
|
+
return this;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
exports.TarReaderSync = TarReaderSync;
|
|
384
|
+
/**
|
|
385
|
+
* Read the entries of an archive. Gzip input is decompressed.
|
|
386
|
+
*
|
|
387
|
+
* Read the body of an entry before the next entry: when the iterator
|
|
388
|
+
* moves on, the rest of the body is skipped.
|
|
389
|
+
*/
|
|
390
|
+
const entries = (input, opt) => new TarReader(input, opt);
|
|
391
|
+
exports.entries = entries;
|
|
392
|
+
/**
|
|
393
|
+
* Read the entries of an archive with no promises. Compressed input
|
|
394
|
+
* needs a codec with a `decompressSync` function in `opt.codecs`.
|
|
395
|
+
*/
|
|
396
|
+
const entriesSync = (input, opt) => new TarReaderSync(input, opt);
|
|
397
|
+
exports.entriesSync = entriesSync;
|
|
398
|
+
//# sourceMappingURL=entries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entries.js","sourceRoot":"","sources":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;;;GAGG;AACI,MAAM,WAAW,GAAG,CACzB,KAAmB,EACnB,GAAqB,EACuB,EAAE,CAC9C,IAAI,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAJlB,QAAA,WAAW,eAIO","sourcesContent":["import {\n isArrayBuffer,\n isBlob,\n isReadableStream,\n isUint8Array,\n} from './bytes.js'\nimport { Header } from './header.js'\nimport { gzip, type Codec } from './codec.js'\nimport { concat } from './concat.js'\nimport {\n ownOptions,\n type ReadOptions,\n type ReadOptionsSync,\n type TarInput,\n type TarInputSync,\n} from './options.js'\nimport { Parser } from './parser.js'\nimport {\n ReadEntry,\n ReadEntrySync,\n type BodySource,\n type BodySourceSync,\n type EntryData,\n} from './read-entry.js'\nimport { SKIP, type Skip } from './read-file.js'\nimport { tarError } from './warn.js'\n\nconst noop = () => {}\n\n// A source of input chunks: an iterator, or the reader of a stream.\ntype Source = Partial<Skip> & {\n next():\n | IteratorResult<Uint8Array, unknown>\n | Promise<IteratorResult<Uint8Array, unknown>>\n return?(): unknown\n}\ntype SourceSync = Iterator<Uint8Array, unknown> & Partial<Skip>\n\n// The number of bytes to read before the choice of a codec.\nexport const headLength = (codecs: Codec[]) =>\n Math.max(512, ...codecs.map(c => c.headLength))\n\nconst isTar = (head: Uint8Array) => {\n try {\n const header = new Header(head)\n return header.cksumValid || header.nullBlock\n } catch {\n return false\n }\n}\n\nexport const findCodec = (\n codecs: Codec[],\n head: Uint8Array,\n file: string = '',\n): Codec | undefined =>\n codecs.find(c => c.detect(head)) ??\n (isTar(head) ? undefined : (\n codecs.find(c => c.extensions?.some(x => file.endsWith(x)))\n ))\n\nconst maxRatio = (opt: ReadOptions<never>) =>\n typeof opt.maxDecompressionRatio === 'number' ?\n opt.maxDecompressionRatio\n : 1000\n\nconst abort = (opt: ReadOptions<never>, er: Error) =>\n tarError(opt, 'TAR_ABORT', er, { recoverable: false })\n\nconst ratioError = (opt: ReadOptions<never>, ratio: number, max: number) =>\n abort(\n opt,\n new Error(\n `max decompression ratio exceeded: ${ratio.toFixed(2)} > ${max}`,\n ),\n )\n\nconst notCurrent = () =>\n new TypeError('The body of an entry cannot be read after a later entry')\n\n/**\n * Gets entries and the parts of their bodies from a `Parser`. The\n * readers use it. It does not read input.\n */\nexport class EntryCursor<E extends EntryData> {\n parser: Parser<E>\n /** The entry that has a body to read now. */\n current?: E\n /** True after the end of the archive. */\n ended: boolean = false\n\n constructor(parser: Parser<E>) {\n this.parser = parser\n }\n\n /**\n * The next entry that is not ignored. `null` at the end of the\n * archive. `undefined` if the parser needs more input. The rest of\n * the body of the entry before it is skipped.\n */\n entry(): E | null | undefined {\n this.current = undefined\n if (this.ended) return null\n for (let ev; (ev = this.parser.next()); ) {\n if (ev.type === 'end') {\n this.ended = true\n return null\n }\n if (ev.type === 'entry' && !ev.entry.ignore) {\n return (this.current = ev.entry)\n }\n }\n }\n\n /**\n * The next part of the body of `entry`. `null` at the end of the\n * body. `undefined` if the parser needs more input.\n */\n body(entry: E): Uint8Array | null | undefined {\n if (entry !== this.current) throw notCurrent()\n const ev = this.parser.next()\n if (!ev) return undefined\n if (ev.type === 'body') return ev.data\n this.current = undefined\n return null\n }\n}\n\n// Skip the rest of a body that no consumer reads, if it is after the\n// input that the parser has, and the source can skip it. The source\n// must be the input of the reader: decompressed data has no place in\n// the input.\nconst skipBody = <E extends EntryData>(\n cursor: EntryCursor<E>,\n source: Partial<Skip>,\n) => {\n if (cursor.current) return\n const n = cursor.parser.bodyRemain\n if (n && source[SKIP]?.(n)) cursor.parser.skipBody()\n}\n\nconst toSource = (input: TarInput): Source => {\n if (isUint8Array(input)) return [input].values()\n if (isArrayBuffer(input)) return [new Uint8Array(input)].values()\n if (isBlob(input)) input = input.stream()\n if (isReadableStream(input)) {\n const reader = input.getReader()\n return { next: () => reader.read(), return: () => reader.cancel() }\n }\n return Symbol.asyncIterator in input ?\n input[Symbol.asyncIterator]()\n : input[Symbol.iterator]()\n}\n\n/**\n * Reads the entries of an archive from async input. It is the\n * iterator that `entries()` returns.\n *\n * Input is read only when the consumer asks for the next entry or\n * for more of a body. `poll()` and `fill()` do the same work as\n * `next()`, with no promise for an entry that is in memory.\n */\nexport class TarReader\n implements AsyncIterableIterator<ReadEntry, undefined>, BodySource\n{\n parser: Parser<ReadEntry>\n #cursor: EntryCursor<ReadEntry>\n #opt: ReadOptions\n #input: Source\n #source?: Source\n // the first bytes of input that is not compressed\n #head?: Uint8Array\n #filling?: Promise<void>\n #done: boolean = false\n\n constructor(input: TarInput, opt: ReadOptions = {}) {\n opt = ownOptions(opt)\n const win32 = opt.platform === 'win32'\n this.parser = new Parser<ReadEntry>(\n opt,\n (header, ex, gex) => new ReadEntry(header, ex, gex, win32, this),\n )\n this.#cursor = new EntryCursor(this.parser)\n this.#opt = opt\n this.#input = toSource(input)\n }\n\n /**\n * The next entry, if it is in memory. `null` at the end of the\n * archive. `undefined` if more input is needed: then await `fill()`\n * and call this again.\n */\n poll(): ReadEntry | null | undefined {\n return this.#done ? null : this.#cursor.entry()\n }\n\n readBody(entry: ReadEntry): Uint8Array | null | undefined {\n return this.#cursor.body(entry)\n }\n\n /** Read one chunk of input, and give it to the parser. */\n fill(): Promise<void> {\n return (this.#filling ??= this.#fill())\n }\n\n async #fill() {\n try {\n const source = (this.#source ??= await this.#open(this.#input))\n const head = this.#head\n this.#head = undefined\n if (source === this.#input) skipBody(this.#cursor, source)\n const res = head ? { value: head, done: false } : await source.next()\n if (res.done) this.parser.end()\n else this.parser.push(res.value)\n } finally {\n this.#filling = undefined\n }\n }\n\n // Read the first bytes, and add the decompression if they need it.\n async #open(input: Source): Promise<Source> {\n const opt = this.#opt\n const codecs = [...(opt.codecs ?? []), gzip]\n const need = headLength(codecs)\n let head: Uint8Array | undefined\n while (!head || head.length < need) {\n const res = await input.next()\n if (res.done) break\n head = head ? concat([head, res.value]) : res.value\n }\n const codec = head && findCodec(codecs, head, opt.file)\n if (!codec) {\n this.#head = head\n return input\n }\n let compressed = 0\n let decompressed = 0\n const { readable, writable } = codec.decompress()\n const writer = writable.getWriter()\n const reader = readable.getReader()\n let stopped = false\n // Give the input to the codec, as fast as the codec takes it. This\n // loop holds each promise of the writer, so that a write that\n // fails after the consumer stops is not an unhandled rejection.\n const feed = async () => {\n try {\n for (;;) {\n await writer.ready\n if (stopped) return\n const res =\n head ? { value: head, done: false } : await input.next()\n head = undefined\n if (stopped) return\n if (res.done) return await writer.close()\n compressed += res.value.length\n await writer.write(res.value)\n }\n } catch (er) {\n // An error of the input goes to the reader of the output. An\n // error of the codec is there already.\n if (!stopped) await writer.abort(er).catch(noop)\n }\n }\n void feed()\n const max = maxRatio(opt)\n return {\n next: async () => {\n const res = await reader.read().catch(er => {\n throw abort(opt, er as Error)\n })\n if (!res.done) {\n decompressed += res.value.length\n const ratio = decompressed / compressed\n if (ratio > max) throw ratioError(opt, ratio, max)\n }\n return res\n },\n return: async () => {\n stopped = true\n await reader.cancel().catch(noop)\n await writer.abort().catch(noop)\n await input.return?.()\n return { value: undefined, done: true }\n },\n }\n }\n\n async next(): Promise<IteratorResult<ReadEntry, undefined>> {\n try {\n for (;;) {\n const entry = this.poll()\n if (entry) return { value: entry, done: false }\n if (entry === null) break\n await this.fill()\n }\n } catch (er) {\n await this.return()\n throw er\n }\n return this.return()\n }\n\n /** Stop reading, and release the input. */\n async return(): Promise<IteratorResult<ReadEntry, undefined>> {\n if (!this.#done) {\n this.#done = true\n this.#cursor.current = undefined\n await (this.#source ?? this.#input).return?.()\n }\n return { value: undefined, done: true }\n }\n\n [Symbol.asyncIterator](): this {\n return this\n }\n}\n\n/**\n * Reads the entries of an archive from sync input. It is the\n * iterator that `entriesSync()` returns.\n */\nexport class TarReaderSync\n implements IterableIterator<ReadEntrySync, undefined>, BodySourceSync\n{\n parser: Parser<ReadEntrySync>\n #cursor: EntryCursor<ReadEntrySync>\n #opt: ReadOptionsSync\n #input: SourceSync\n #source?: SourceSync\n // the first bytes of input that is not compressed\n #head?: Uint8Array\n #done: boolean = false\n\n constructor(input: TarInputSync, opt: ReadOptionsSync = {}) {\n opt = ownOptions(opt)\n const win32 = opt.platform === 'win32'\n this.parser = new Parser<ReadEntrySync>(\n opt,\n (header, ex, gex) => new ReadEntrySync(header, ex, gex, win32, this),\n )\n this.#cursor = new EntryCursor(this.parser)\n this.#opt = opt\n this.#input =\n isUint8Array(input) ? [input].values()\n : isArrayBuffer(input) ? [new Uint8Array(input)].values()\n : input[Symbol.iterator]()\n }\n\n readBody(entry: ReadEntrySync): Uint8Array | null {\n for (;;) {\n const part = this.#cursor.body(entry)\n if (part !== undefined) return part\n this.#fill()\n }\n }\n\n #fill() {\n const source = (this.#source ??= this.#open(this.#input))\n const head = this.#head\n this.#head = undefined\n if (source === this.#input) skipBody(this.#cursor, source)\n const res = head ? { value: head, done: false } : source.next()\n if (res.done) this.parser.end()\n else this.parser.push(res.value)\n }\n\n // Read the first bytes. If they are compressed, read and decompress\n // all the input.\n #open(input: SourceSync): SourceSync {\n const opt = this.#opt\n const codecs = [...(opt.codecs ?? []), gzip]\n const need = headLength(codecs)\n let head: Uint8Array | undefined\n let res: IteratorResult<Uint8Array, unknown>\n while ((!head || head.length < need) && !(res = input.next()).done) {\n head = head ? concat([head, res.value]) : res.value\n }\n const codec = head && findCodec(codecs, head, opt.file)\n if (!head || !codec) {\n this.#head = head\n return input\n }\n const { decompressSync } = codec\n if (!decompressSync) {\n throw abort(\n opt,\n new Error(\n `the ${codec.name} codec has no decompressSync function`,\n ),\n )\n }\n const parts = [head]\n while (!(res = input.next()).done) parts.push(res.value)\n const data = concat(parts)\n const max = maxRatio(opt)\n let out: Uint8Array\n try {\n out = decompressSync(data, { maxOutputLength: data.length * max })\n } catch (er) {\n throw abort(opt, er as Error)\n }\n const ratio = out.length / data.length\n if (ratio > max) throw ratioError(opt, ratio, max)\n return [out].values()\n }\n\n next(): IteratorResult<ReadEntrySync, undefined> {\n try {\n for (;;) {\n const entry = this.#done ? null : this.#cursor.entry()\n if (entry) return { value: entry, done: false }\n if (entry === null) break\n this.#fill()\n }\n } catch (er) {\n this.return()\n throw er\n }\n return this.return()\n }\n\n /** Stop reading, and release the input. */\n return(): IteratorResult<ReadEntrySync, undefined> {\n if (!this.#done) {\n this.#done = true\n this.#cursor.current = undefined\n ;(this.#source ?? this.#input).return?.()\n }\n return { value: undefined, done: true }\n }\n\n [Symbol.iterator](): this {\n return this\n }\n}\n\n/**\n * Read the entries of an archive. Gzip input is decompressed.\n *\n * Read the body of an entry before the next entry: when the iterator\n * moves on, the rest of the body is skipped.\n */\nexport const entries = (\n input: TarInput,\n opt?: ReadOptions,\n): AsyncIterableIterator<ReadEntry, undefined> => new TarReader(input, opt)\n\n/**\n * Read the entries of an archive with no promises. Compressed input\n * needs a codec with a `decompressSync` function in `opt.codecs`.\n */\nexport const entriesSync = (\n input: TarInputSync,\n opt?: ReadOptionsSync,\n): IterableIterator<ReadEntrySync, undefined> =>\n new TarReaderSync(input, opt)\n"]}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { type WithAliases } from './dealias.js';
|
|
2
|
+
import type { ExtractOptions, ExtractOptionsSync } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extract the entries of an archive into the directory `opt.cwd`.
|
|
5
|
+
* If `files` is set, only the entries that it lists, and the entries
|
|
6
|
+
* in the directories that it lists.
|
|
7
|
+
*
|
|
8
|
+
* A problem with one entry is a warning for `opt.onwarn`, and the
|
|
9
|
+
* extraction continues. A listed path that no entry matches is a
|
|
10
|
+
* warning when the archive ends. With `opt.strict`, each is an error.
|
|
11
|
+
*/
|
|
12
|
+
export declare const extract: (options: WithAliases<ExtractOptions>, files?: string[]) => Promise<void>;
|
|
13
|
+
/** The sync form of `extract`. */
|
|
14
|
+
export declare const extractSync: (options: WithAliases<ExtractOptionsSync>, files?: string[]) => void;
|
|
3
15
|
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/extract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAMtE;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,GAClB,SAAS,WAAW,CAAC,cAAc,CAAC,EACpC,QAAQ,MAAM,EAAE,KACf,OAAO,CAAC,IAAI,CAWd,CAAA;AAED,kCAAkC;AAClC,eAAO,MAAM,WAAW,GACtB,SAAS,WAAW,CAAC,kBAAkB,CAAC,EACxC,QAAQ,MAAM,EAAE,KACf,IAaF,CAAA"}
|
package/dist/commonjs/extract.js
CHANGED
|
@@ -1,88 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.extract = void 0;
|
|
40
|
-
|
|
41
|
-
const fsm = __importStar(require("@isaacs/fs-minipass"));
|
|
42
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
3
|
+
exports.extractSync = exports.extract = void 0;
|
|
4
|
+
const dealias_js_1 = require("./dealias.js");
|
|
43
5
|
const list_js_1 = require("./list.js");
|
|
44
|
-
const
|
|
6
|
+
const read_file_js_1 = require("./read-file.js");
|
|
45
7
|
const unpack_js_1 = require("./unpack.js");
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
8
|
+
const noInput = () => new TypeError('extract needs input or file');
|
|
9
|
+
/**
|
|
10
|
+
* Extract the entries of an archive into the directory `opt.cwd`.
|
|
11
|
+
* If `files` is set, only the entries that it lists, and the entries
|
|
12
|
+
* in the directories that it lists.
|
|
13
|
+
*
|
|
14
|
+
* A problem with one entry is a warning for `opt.onwarn`, and the
|
|
15
|
+
* extraction continues. A listed path that no entry matches is a
|
|
16
|
+
* warning when the archive ends. With `opt.strict`, each is an error.
|
|
17
|
+
*/
|
|
18
|
+
const extract = async (options, files) => {
|
|
19
|
+
const opt = (0, dealias_js_1.dealias)(options);
|
|
20
|
+
const source = opt.input ??
|
|
21
|
+
(opt.file ? (0, read_file_js_1.readFile)(opt.fs, opt.file, opt.maxReadSize) : undefined);
|
|
22
|
+
if (!source)
|
|
23
|
+
throw noInput();
|
|
24
|
+
const [filter, report] = files?.length ? (0, list_js_1.filesFilter)(files, opt.filter) : [];
|
|
25
|
+
if (filter)
|
|
26
|
+
opt.filter = filter;
|
|
27
|
+
await new unpack_js_1.Unpack(opt).extract(source);
|
|
28
|
+
report?.(opt);
|
|
58
29
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
readSize: readSize,
|
|
75
|
-
size: stat.size,
|
|
76
|
-
});
|
|
77
|
-
stream.on('error', reject);
|
|
78
|
-
stream.pipe(u);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
return p;
|
|
30
|
+
exports.extract = extract;
|
|
31
|
+
/** The sync form of `extract`. */
|
|
32
|
+
const extractSync = (options, files) => {
|
|
33
|
+
const opt = (0, dealias_js_1.dealias)(options);
|
|
34
|
+
const source = opt.input ??
|
|
35
|
+
(opt.file ?
|
|
36
|
+
(0, read_file_js_1.readFileSync)(opt.fs, opt.file, opt.maxReadSize)
|
|
37
|
+
: undefined);
|
|
38
|
+
if (!source)
|
|
39
|
+
throw noInput();
|
|
40
|
+
const [filter, report] = files?.length ? (0, list_js_1.filesFilter)(files, opt.filter) : [];
|
|
41
|
+
if (filter)
|
|
42
|
+
opt.filter = filter;
|
|
43
|
+
new unpack_js_1.UnpackSync(opt).extract(source);
|
|
44
|
+
report?.(opt);
|
|
83
45
|
};
|
|
84
|
-
exports.
|
|
85
|
-
if (files?.length)
|
|
86
|
-
(0, list_js_1.filesFilter)(opt, files);
|
|
87
|
-
});
|
|
46
|
+
exports.extractSync = extractSync;
|
|
88
47
|
//# sourceMappingURL=extract.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/extract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/extract.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AACxD,uCAAuC;AAEvC,iDAAuD;AACvD,2CAAgD;AAEhD,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAA;AAElE;;;;;;;;GAQG;AACI,MAAM,OAAO,GAAG,KAAK,EAC1B,OAAoC,EACpC,KAAgB,EACD,EAAE;IACjB,MAAM,GAAG,GAAG,IAAA,oBAAO,EAAiB,OAAO,CAAC,CAAA;IAC5C,MAAM,MAAM,GACV,GAAG,CAAC,KAAK;QACT,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,uBAAQ,EAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtE,IAAI,CAAC,MAAM;QAAE,MAAM,OAAO,EAAE,CAAA;IAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,qBAAW,EAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACrD,IAAI,MAAM;QAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;IAC/B,MAAM,IAAI,kBAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACrC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;AACf,CAAC,CAAA;AAdY,QAAA,OAAO,WAcnB;AAED,kCAAkC;AAC3B,MAAM,WAAW,GAAG,CACzB,OAAwC,EACxC,KAAgB,EACV,EAAE;IACR,MAAM,GAAG,GAAG,IAAA,oBAAO,EAAqB,OAAO,CAAC,CAAA;IAChD,MAAM,MAAM,GACV,GAAG,CAAC,KAAK;QACT,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACT,IAAA,2BAAY,EAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC;YACjD,CAAC,CAAC,SAAS,CAAC,CAAA;IACd,IAAI,CAAC,MAAM;QAAE,MAAM,OAAO,EAAE,CAAA;IAC5B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAA,qBAAW,EAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACrD,IAAI,MAAM;QAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;IAC/B,IAAI,sBAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACnC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;AACf,CAAC,CAAA;AAhBY,QAAA,WAAW,eAgBvB","sourcesContent":["import { dealias, type WithAliases } from './dealias.js'\nimport { filesFilter } from './list.js'\nimport type { ExtractOptions, ExtractOptionsSync } from './options.js'\nimport { readFile, readFileSync } from './read-file.js'\nimport { Unpack, UnpackSync } from './unpack.js'\n\nconst noInput = () => new TypeError('extract needs input or file')\n\n/**\n * Extract the entries of an archive into the directory `opt.cwd`.\n * If `files` is set, only the entries that it lists, and the entries\n * in the directories that it lists.\n *\n * A problem with one entry is a warning for `opt.onwarn`, and the\n * extraction continues. A listed path that no entry matches is a\n * warning when the archive ends. With `opt.strict`, each is an error.\n */\nexport const extract = async (\n options: WithAliases<ExtractOptions>,\n files?: string[],\n): Promise<void> => {\n const opt = dealias<ExtractOptions>(options)\n const source =\n opt.input ??\n (opt.file ? readFile(opt.fs, opt.file, opt.maxReadSize) : undefined)\n if (!source) throw noInput()\n const [filter, report] =\n files?.length ? filesFilter(files, opt.filter) : []\n if (filter) opt.filter = filter\n await new Unpack(opt).extract(source)\n report?.(opt)\n}\n\n/** The sync form of `extract`. */\nexport const extractSync = (\n options: WithAliases<ExtractOptionsSync>,\n files?: string[],\n): void => {\n const opt = dealias<ExtractOptionsSync>(options)\n const source =\n opt.input ??\n (opt.file ?\n readFileSync(opt.fs, opt.file, opt.maxReadSize)\n : undefined)\n if (!source) throw noInput()\n const [filter, report] =\n files?.length ? filesFilter(files, opt.filter) : []\n if (filter) opt.filter = filter\n new UnpackSync(opt).extract(source)\n report?.(opt)\n}\n"]}
|