tar 7.5.24 → 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 -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 +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 -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 +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
package/dist/commonjs/pack.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// A readable tar stream creator
|
|
3
|
-
// Technically, this is a transform stream that you write paths into,
|
|
4
|
-
// and tar format comes out of.
|
|
5
|
-
// The `add()` method is like `write()` but returns this,
|
|
6
|
-
// and end() return `this` as well, so you can
|
|
7
|
-
// do `new Pack(opt).add('files').add('dir').end().pipe(output)
|
|
8
|
-
// You could also do something like:
|
|
9
|
-
// streamOfPaths().pipe(new Pack()).pipe(new fs.WriteStream('out.tar'))
|
|
10
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
3
|
if (k2 === undefined) k2 = k;
|
|
12
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -40,504 +32,819 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
40
32
|
return result;
|
|
41
33
|
};
|
|
42
34
|
})();
|
|
43
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
44
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
|
-
};
|
|
46
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.PackSync = exports.Pack = exports.PackJob = void 0;
|
|
48
|
-
const
|
|
36
|
+
exports.PackSync = exports.Pack = exports.PackBase = exports.PackJob = void 0;
|
|
37
|
+
const bytes_js_1 = require("./bytes.js");
|
|
38
|
+
const mode_fix_js_1 = require("./mode-fix.js");
|
|
39
|
+
const winchars = __importStar(require("./winchars.js"));
|
|
40
|
+
const codec_js_1 = require("./codec.js");
|
|
41
|
+
const concat_js_1 = require("./concat.js");
|
|
42
|
+
const options_js_1 = require("./options.js");
|
|
43
|
+
const path_js_1 = require("./path.js");
|
|
44
|
+
const strip_absolute_path_js_1 = require("./strip-absolute-path.js");
|
|
45
|
+
const to_stream_js_1 = require("./to-stream.js");
|
|
46
|
+
const warn_js_1 = require("./warn.js");
|
|
47
|
+
const win32_path_js_1 = require("./win32-path.js");
|
|
49
48
|
const write_entry_js_1 = require("./write-entry.js");
|
|
49
|
+
const MAX_READ = 16 * 1024 * 1024;
|
|
50
|
+
const noop = () => { };
|
|
51
|
+
const blockLength = (size) => 512 * Math.ceil(size / 512);
|
|
52
|
+
const slashes = (path) => path.replaceAll('\\', '/');
|
|
53
|
+
// The identity of a file: a key for a `Map`, and a value to compare.
|
|
54
|
+
// The key of two `bigint` values is the key of the same two numbers.
|
|
55
|
+
const idOf = (id) => `${id.dev}:${id.ino}`;
|
|
56
|
+
const BIG = { bigint: true };
|
|
57
|
+
// Node.js gives `dev` and `ino` as numbers. A value that is not a
|
|
58
|
+
// safe integer can be the value of more than one file. On NTFS, most
|
|
59
|
+
// `ino` values are not safe integers.
|
|
60
|
+
const lossy = ({ dev, ino }) => !Number.isSafeInteger(dev) || !Number.isSafeInteger(ino);
|
|
61
|
+
// True if the path is still the object of its stat. The numbers are
|
|
62
|
+
// enough here: one object always gives the same numbers, so numbers
|
|
63
|
+
// that are not exact give no false alarm, and need no second stat.
|
|
64
|
+
const same = (a, b) => a.dev === b.dev && a.ino === b.ino;
|
|
65
|
+
const eof = (message, path) => Object.assign(new Error(message), { path, syscall: 'read', code: 'EOF' });
|
|
66
|
+
// The file does not have the number of bytes that its stat gave.
|
|
67
|
+
const fewer = (path, size) => eof(`encountered unexpected EOF: ${path} has fewer than the ${size} bytes of its stat`, path);
|
|
68
|
+
const more = (path, size) => eof(`did not encounter expected EOF: ${path} has more than the ${size} bytes of its stat`, path);
|
|
69
|
+
const pathOf = (entry) => entry.absolute ?? entry.path;
|
|
70
|
+
const tooLong = (entry) => Object.assign(new Error('writing more data than expected'), {
|
|
71
|
+
path: pathOf(entry),
|
|
72
|
+
});
|
|
73
|
+
// The package has more than one copy of each class: the entry points
|
|
74
|
+
// `tar` and `tar/core` are separate bundles, and each has an ESM and
|
|
75
|
+
// a CommonJS build. `instanceof` is false for an entry of a different
|
|
76
|
+
// copy, so these checks use the shape of the item. A `PackJob` is
|
|
77
|
+
// always of this copy, because only the pack makes it.
|
|
78
|
+
// A source of entries is an iterable. An entry is not.
|
|
79
|
+
const isSource = (item) => Symbol.asyncIterator in item || Symbol.iterator in item;
|
|
80
|
+
// A `WriteEntry` can encode its header. An entry of an archive
|
|
81
|
+
// cannot.
|
|
82
|
+
const isWriteEntry = (item) => typeof item.encode === 'function';
|
|
83
|
+
/** A path in the queue of a pack. */
|
|
50
84
|
class PackJob {
|
|
51
85
|
path;
|
|
52
86
|
absolute;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
piped = false;
|
|
87
|
+
/** The directories above it, when the pack follows symbolic links. */
|
|
88
|
+
up;
|
|
89
|
+
/** The target, when the pack writes the file as a hard link. */
|
|
90
|
+
linkpath;
|
|
91
|
+
/** Set when `Pack` starts to read the path. */
|
|
92
|
+
ready;
|
|
60
93
|
constructor(path, absolute) {
|
|
61
|
-
this.path = path
|
|
94
|
+
this.path = path;
|
|
62
95
|
this.absolute = absolute;
|
|
63
96
|
}
|
|
64
97
|
}
|
|
65
98
|
exports.PackJob = PackJob;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const ENDED = Symbol('ended');
|
|
73
|
-
const QUEUE = Symbol('queue');
|
|
74
|
-
const PENDINGLINKS = Symbol('pendingLinks');
|
|
75
|
-
const CURRENT = Symbol('current');
|
|
76
|
-
const PROCESS = Symbol('process');
|
|
77
|
-
const PROCESSING = Symbol('processing');
|
|
78
|
-
const PROCESSJOB = Symbol('processJob');
|
|
79
|
-
const JOBS = Symbol('jobs');
|
|
80
|
-
const JOBDONE = Symbol('jobDone');
|
|
81
|
-
const ADDFSENTRY = Symbol('addFSEntry');
|
|
82
|
-
const ADDTARENTRY = Symbol('addTarEntry');
|
|
83
|
-
const STAT = Symbol('stat');
|
|
84
|
-
const READDIR = Symbol('readdir');
|
|
85
|
-
const ONREADDIR = Symbol('onreaddir');
|
|
86
|
-
const PIPE = Symbol('pipe');
|
|
87
|
-
const ENTRY = Symbol('entry');
|
|
88
|
-
const ENTRYOPT = Symbol('entryOpt');
|
|
89
|
-
const WRITEENTRYCLASS = Symbol('writeEntryClass');
|
|
90
|
-
const WRITE = Symbol('write');
|
|
91
|
-
const ONDRAIN = Symbol('ondrain');
|
|
92
|
-
const path_1 = __importDefault(require("path"));
|
|
93
|
-
const normalize_windows_path_js_1 = require("./normalize-windows-path.js");
|
|
94
|
-
class Pack extends minipass_1.Minipass {
|
|
95
|
-
sync = false;
|
|
99
|
+
/**
|
|
100
|
+
* The parts of `Pack` and `PackSync` that are the same: the options,
|
|
101
|
+
* the queue, and the rules that make an entry from a path or from an
|
|
102
|
+
* entry of another archive.
|
|
103
|
+
*/
|
|
104
|
+
class PackBase {
|
|
96
105
|
opt;
|
|
106
|
+
fs;
|
|
107
|
+
/** The normalized form of `opt.cwd`. */
|
|
97
108
|
cwd;
|
|
109
|
+
win32;
|
|
98
110
|
maxReadSize;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.on('warn', opt.onwarn);
|
|
147
|
-
}
|
|
148
|
-
this.portable = !!opt.portable;
|
|
149
|
-
if (opt.gzip || opt.brotli || opt.zstd) {
|
|
150
|
-
if ((opt.gzip ? 1 : 0) + (opt.brotli ? 1 : 0) + (opt.zstd ? 1 : 0) >
|
|
151
|
-
1) {
|
|
152
|
-
throw new TypeError('gzip, brotli, zstd are mutually exclusive');
|
|
153
|
-
}
|
|
154
|
-
if (opt.gzip) {
|
|
155
|
-
if (typeof opt.gzip !== 'object') {
|
|
156
|
-
opt.gzip = {};
|
|
157
|
-
}
|
|
158
|
-
if (this.portable) {
|
|
159
|
-
opt.gzip.portable = true;
|
|
160
|
-
}
|
|
161
|
-
this.zip = new zlib.Gzip(opt.gzip);
|
|
162
|
-
}
|
|
163
|
-
if (opt.brotli) {
|
|
164
|
-
if (typeof opt.brotli !== 'object') {
|
|
165
|
-
opt.brotli = {};
|
|
166
|
-
}
|
|
167
|
-
this.zip = new zlib.BrotliCompress(opt.brotli);
|
|
168
|
-
}
|
|
169
|
-
if (opt.zstd) {
|
|
170
|
-
if (typeof opt.zstd !== 'object') {
|
|
171
|
-
opt.zstd = {};
|
|
172
|
-
}
|
|
173
|
-
this.zip = new zlib.ZstdCompress(opt.zstd);
|
|
111
|
+
/** The options of `WriteEntry.encode`. */
|
|
112
|
+
header;
|
|
113
|
+
/** The compression of the output. */
|
|
114
|
+
codec;
|
|
115
|
+
codecOptions;
|
|
116
|
+
/** True after `end()`. */
|
|
117
|
+
ended = false;
|
|
118
|
+
head;
|
|
119
|
+
tail;
|
|
120
|
+
wake;
|
|
121
|
+
// The first path of each file that has more than one link.
|
|
122
|
+
#links = new Map();
|
|
123
|
+
constructor(opt, compress) {
|
|
124
|
+
opt = this.opt = (0, options_js_1.ownOptions)(opt);
|
|
125
|
+
this.fs = opt.fs;
|
|
126
|
+
this.win32 = opt.platform === 'win32';
|
|
127
|
+
this.maxReadSize = (0, options_js_1.countOption)('maxReadSize', opt.maxReadSize, MAX_READ);
|
|
128
|
+
const { prefix, noPax } = opt;
|
|
129
|
+
this.header = {
|
|
130
|
+
prefix: prefix && this.win32 ? slashes(prefix) : prefix,
|
|
131
|
+
noPax,
|
|
132
|
+
};
|
|
133
|
+
const cwd = opt.cwd && (this.win32 ? slashes(opt.cwd) : opt.cwd);
|
|
134
|
+
// This code has no working directory to make a path absolute.
|
|
135
|
+
if (cwd && !(this.win32 ? win32_path_js_1.win32IsAbsolute : path_js_1.isAbsolute)(cwd)) {
|
|
136
|
+
throw new TypeError('cwd must be an absolute path');
|
|
137
|
+
}
|
|
138
|
+
this.cwd = cwd && this.#resolve(cwd, '');
|
|
139
|
+
const set = opt;
|
|
140
|
+
const names = ['gzip', 'brotli', 'zstd', 'compress'].filter(name => set[name]);
|
|
141
|
+
if (names.length > 1) {
|
|
142
|
+
throw new TypeError(`${names.join(', ')} are mutually exclusive`);
|
|
143
|
+
}
|
|
144
|
+
const [name] = names;
|
|
145
|
+
if (name) {
|
|
146
|
+
const custom = opt.compress;
|
|
147
|
+
// The named options use a codec of `codecs`, or the gzip of
|
|
148
|
+
// the runtime. The `compress` option has its own codec.
|
|
149
|
+
const [codec, value] = !custom ?
|
|
150
|
+
[
|
|
151
|
+
[...(opt.codecs ?? []), codec_js_1.gzip].find(c => c.name === name),
|
|
152
|
+
set[name],
|
|
153
|
+
]
|
|
154
|
+
: Array.isArray(custom) ? custom
|
|
155
|
+
: [custom];
|
|
156
|
+
if (!codec?.[compress]) {
|
|
157
|
+
throw new TypeError(`no codec named ${codec?.name ?? name} has a ${compress} function`);
|
|
174
158
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.on('resume', () => zip.resume());
|
|
159
|
+
this.codec = codec;
|
|
160
|
+
this.codecOptions = {
|
|
161
|
+
...(typeof value === 'object' ? value : undefined),
|
|
162
|
+
...(codec.name === 'gzip' && opt.portable ?
|
|
163
|
+
{ portable: true }
|
|
164
|
+
: undefined),
|
|
165
|
+
};
|
|
183
166
|
}
|
|
184
|
-
else {
|
|
185
|
-
this.on('drain', this[ONDRAIN]);
|
|
186
|
-
}
|
|
187
|
-
this.noDirRecurse = !!opt.noDirRecurse;
|
|
188
|
-
this.follow = !!opt.follow;
|
|
189
|
-
this.noMtime = !!opt.noMtime;
|
|
190
|
-
if (opt.mtime)
|
|
191
|
-
this.mtime = opt.mtime;
|
|
192
|
-
this.filter =
|
|
193
|
-
typeof opt.filter === 'function' ? opt.filter : () => true;
|
|
194
|
-
this[QUEUE] = new yallist_1.Yallist();
|
|
195
|
-
this[JOBS] = 0;
|
|
196
|
-
this.jobs = Number(opt.jobs) || 4;
|
|
197
|
-
this[PROCESSING] = false;
|
|
198
|
-
this[ENDED] = false;
|
|
199
|
-
}
|
|
200
|
-
[WRITE](chunk) {
|
|
201
|
-
return super.write(chunk);
|
|
202
|
-
}
|
|
203
|
-
add(path) {
|
|
204
|
-
this.write(path);
|
|
205
|
-
return this;
|
|
206
167
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (typeof path === 'function') {
|
|
210
|
-
cb = path;
|
|
211
|
-
path = undefined;
|
|
212
|
-
}
|
|
213
|
-
if (typeof encoding === 'function') {
|
|
214
|
-
cb = encoding;
|
|
215
|
-
encoding = undefined;
|
|
216
|
-
}
|
|
217
|
-
/* c8 ignore stop */
|
|
218
|
-
if (path) {
|
|
219
|
-
this.add(path);
|
|
220
|
-
}
|
|
221
|
-
this[ENDED] = true;
|
|
222
|
-
this[PROCESS]();
|
|
223
|
-
/* c8 ignore next */
|
|
224
|
-
if (cb)
|
|
225
|
-
cb();
|
|
226
|
-
return this;
|
|
168
|
+
#resolve(cwd, path) {
|
|
169
|
+
return this.win32 ? (0, win32_path_js_1.win32Resolve)(cwd, path) : (0, path_js_1.resolve)(cwd, path);
|
|
227
170
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (typeof path === 'string') {
|
|
233
|
-
this[ADDFSENTRY](path);
|
|
171
|
+
/** The absolute form of a path that is relative to `cwd`. */
|
|
172
|
+
resolve(path) {
|
|
173
|
+
if (!this.cwd || !this.fs) {
|
|
174
|
+
throw new TypeError('a path needs the cwd and fs options');
|
|
234
175
|
}
|
|
176
|
+
return this.#resolve(this.cwd, this.win32 ? slashes(path) : path);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Put a path, an entry, or a source of entries at the end of the
|
|
180
|
+
* queue. A directory is added with all that is in it.
|
|
181
|
+
*/
|
|
182
|
+
add(item) {
|
|
183
|
+
if (this.ended)
|
|
184
|
+
throw new Error('write after end');
|
|
185
|
+
if (typeof item !== 'string')
|
|
186
|
+
this.push(item);
|
|
235
187
|
else {
|
|
236
|
-
this
|
|
188
|
+
const path = this.win32 ? slashes(item) : item;
|
|
189
|
+
this.push(new PackJob(path || './', this.resolve(path)));
|
|
237
190
|
}
|
|
238
|
-
return this
|
|
191
|
+
return this;
|
|
239
192
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
const job = new PackJob(p.path, absolute);
|
|
248
|
-
job.entry = new write_entry_js_1.WriteEntryTar(p, this[ENTRYOPT](job));
|
|
249
|
-
job.entry.on('end', () => this[JOBDONE](job));
|
|
250
|
-
this[JOBS] += 1;
|
|
251
|
-
this[QUEUE].push(job);
|
|
252
|
-
}
|
|
253
|
-
this[PROCESS]();
|
|
254
|
-
}
|
|
255
|
-
[ADDFSENTRY](p) {
|
|
256
|
-
const absolute = (0, normalize_windows_path_js_1.normalizeWindowsPath)(path_1.default.resolve(this.cwd, p));
|
|
257
|
-
this[QUEUE].push(new PackJob(p, absolute));
|
|
258
|
-
this[PROCESS]();
|
|
259
|
-
}
|
|
260
|
-
[STAT](job) {
|
|
261
|
-
job.pending = true;
|
|
262
|
-
this[JOBS] += 1;
|
|
263
|
-
const stat = this.follow ? 'stat' : 'lstat';
|
|
264
|
-
fs_1.default[stat](job.absolute, (er, stat) => {
|
|
265
|
-
job.pending = false;
|
|
266
|
-
this[JOBS] -= 1;
|
|
267
|
-
if (er) {
|
|
268
|
-
this.emit('error', er);
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
this[ONSTAT](job, stat);
|
|
272
|
-
}
|
|
273
|
-
});
|
|
193
|
+
/** Add no more. The archive ends after the last item of the queue. */
|
|
194
|
+
end() {
|
|
195
|
+
this.ended = true;
|
|
196
|
+
this.wake?.();
|
|
197
|
+
return this;
|
|
274
198
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
199
|
+
push(item) {
|
|
200
|
+
const node = { item };
|
|
201
|
+
if (this.tail)
|
|
202
|
+
this.tail.next = node;
|
|
203
|
+
else
|
|
204
|
+
this.head = node;
|
|
205
|
+
this.tail = node;
|
|
206
|
+
this.wake?.();
|
|
207
|
+
}
|
|
208
|
+
shift() {
|
|
209
|
+
this.head = this.head?.next;
|
|
210
|
+
if (!this.head)
|
|
211
|
+
this.tail = undefined;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* True if the pack must read the exact `dev` and `ino` of the
|
|
215
|
+
* object with the `bigint` option: the numbers are not exact, and a
|
|
216
|
+
* wrong match loses data. That is a file with more than one link,
|
|
217
|
+
* which a wrong match makes a hard link to a different file, and
|
|
218
|
+
* with `follow` a directory, which a wrong match skips as a
|
|
219
|
+
* directory in itself. Each other object gets no second stat.
|
|
220
|
+
*/
|
|
221
|
+
needsExact(stat) {
|
|
222
|
+
return (lossy(stat) &&
|
|
223
|
+
(stat.isDirectory() ?
|
|
224
|
+
!!this.opt.follow
|
|
225
|
+
: stat.isFile() && stat.nlink > 1));
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The type of the entry to write for a path, or `undefined` to
|
|
229
|
+
* write no entry. The pack calls it one time for each path, in the
|
|
230
|
+
* order of the queue. `id` is the stat, or the exact `dev` and `ino`
|
|
231
|
+
* of the object.
|
|
232
|
+
*/
|
|
233
|
+
plan(job, stat, id) {
|
|
234
|
+
const { filter } = this.opt;
|
|
235
|
+
if (filter && !filter(job.path, stat))
|
|
236
|
+
return;
|
|
237
|
+
if (stat.isDirectory()) {
|
|
238
|
+
for (let a = job.up; a; a = a.up) {
|
|
239
|
+
if (a.key !== idOf(id))
|
|
240
|
+
continue;
|
|
241
|
+
(0, warn_js_1.warn)(this.opt, 'TAR_ENTRY_ERROR', 'directory is its own ancestor', {
|
|
242
|
+
path: job.path,
|
|
243
|
+
absolute: job.absolute,
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
291
246
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
247
|
+
return 'Directory';
|
|
248
|
+
}
|
|
249
|
+
if (stat.isSymbolicLink())
|
|
250
|
+
return 'SymbolicLink';
|
|
251
|
+
if (!stat.isFile()) {
|
|
252
|
+
// A socket, a FIFO, or a device.
|
|
253
|
+
(0, warn_js_1.warn)(this.opt, 'TAR_ENTRY_UNSUPPORTED', 'unsupported file type', {
|
|
254
|
+
path: job.path,
|
|
255
|
+
absolute: job.absolute,
|
|
256
|
+
});
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (stat.nlink > 1) {
|
|
260
|
+
const key = idOf(id);
|
|
261
|
+
const target = this.#links.get(key);
|
|
262
|
+
const cwd = this.cwd;
|
|
263
|
+
// A link is only made to a path in the cwd. A directory beside
|
|
264
|
+
// the cwd can have a name that starts with the name of the cwd.
|
|
265
|
+
// A path that is added two times is a file each time: a link to
|
|
266
|
+
// itself cannot be extracted.
|
|
267
|
+
if (target !== job.absolute &&
|
|
268
|
+
target?.startsWith(cwd.endsWith('/') ? cwd : cwd + '/')) {
|
|
269
|
+
job.linkpath = (0, path_js_1.relative)(cwd, target);
|
|
270
|
+
return 'Link';
|
|
303
271
|
}
|
|
272
|
+
this.#links.set(key, job.absolute);
|
|
304
273
|
}
|
|
305
|
-
|
|
274
|
+
return 'File';
|
|
306
275
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
276
|
+
/** The jobs for the names in the directory of `job`. */
|
|
277
|
+
children(job, names, id) {
|
|
278
|
+
const base = job.path === './' ? '' : job.path.replace(/\/*$/, '/');
|
|
279
|
+
const dir = job.absolute.endsWith('/') ? job.absolute : job.absolute + '/';
|
|
280
|
+
// Only a pack that follows symbolic links can find a directory
|
|
281
|
+
// in itself.
|
|
282
|
+
const up = this.opt.follow ? { key: idOf(id), up: job.up } : undefined;
|
|
283
|
+
// Node.js sorts the names of a directory. Bun does not. Sort
|
|
284
|
+
// them, so that each runtime makes the same archive.
|
|
285
|
+
return [...names].sort().map(name => {
|
|
286
|
+
const child = new PackJob(base + name, dir + name);
|
|
287
|
+
child.up = up;
|
|
288
|
+
return child;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Report a path that does not exist, and skip it. Each other error
|
|
293
|
+
* of the stat is thrown.
|
|
294
|
+
*/
|
|
295
|
+
missing(job, er) {
|
|
296
|
+
if (er?.code !== 'ENOENT')
|
|
297
|
+
throw er;
|
|
298
|
+
(0, warn_js_1.warn)(this.opt, 'TAR_ENTRY_ERROR', er, {
|
|
299
|
+
path: job.path,
|
|
300
|
+
absolute: job.absolute,
|
|
317
301
|
});
|
|
318
302
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
303
|
+
/** Report a path that is a different object after its `lstat`. */
|
|
304
|
+
changed(job, type) {
|
|
305
|
+
(0, warn_js_1.warn)(this.opt, 'TAR_ENTRY_ERROR', type === 'Directory' ?
|
|
306
|
+
'directory changed between lstat and readdir'
|
|
307
|
+
: 'file changed between lstat and open', { path: job.path, absolute: job.absolute });
|
|
323
308
|
}
|
|
324
|
-
|
|
325
|
-
|
|
309
|
+
/** Make the entry for a path. */
|
|
310
|
+
pathEntry(job, stat, type, linkpath, body) {
|
|
311
|
+
const { processUid, processUname = '' } = this.opt;
|
|
312
|
+
const entry = new write_entry_js_1.WriteEntry({
|
|
313
|
+
path: job.path,
|
|
314
|
+
type,
|
|
315
|
+
mode: stat.mode,
|
|
316
|
+
uid: stat.uid,
|
|
317
|
+
gid: stat.gid,
|
|
318
|
+
uname: stat.uid === processUid ? processUname : '',
|
|
319
|
+
size: type === 'File' ? stat.size : 0,
|
|
320
|
+
mtime: stat.mtime,
|
|
321
|
+
atime: stat.atime,
|
|
322
|
+
ctime: stat.ctime,
|
|
323
|
+
linkpath: linkpath && this.win32 ? slashes(linkpath) : linkpath,
|
|
324
|
+
dev: stat.dev,
|
|
325
|
+
ino: stat.ino,
|
|
326
|
+
nlink: stat.nlink,
|
|
327
|
+
}, body);
|
|
328
|
+
entry.absolute = job.absolute;
|
|
329
|
+
return this.#finish(entry, true);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Make the entry to write for an entry that the caller added.
|
|
333
|
+
* `undefined` if the filter refuses an entry of another archive.
|
|
334
|
+
*/
|
|
335
|
+
addedEntry(item) {
|
|
336
|
+
if (isWriteEntry(item))
|
|
337
|
+
return this.#finish(item, false);
|
|
338
|
+
const { filter } = this.opt;
|
|
339
|
+
if (filter && !filter(item.path, item))
|
|
326
340
|
return;
|
|
341
|
+
return this.#finish(new write_entry_js_1.WriteEntry(item, item.body), false);
|
|
342
|
+
}
|
|
343
|
+
// Apply the options to the fields of the entry.
|
|
344
|
+
#finish(entry, fromPath) {
|
|
345
|
+
const { opt, win32 } = this;
|
|
346
|
+
const dir = entry.type === 'Directory';
|
|
347
|
+
if (win32 && !fromPath) {
|
|
348
|
+
entry.path = slashes(entry.path);
|
|
349
|
+
if (entry.linkpath)
|
|
350
|
+
entry.linkpath = slashes(entry.linkpath);
|
|
351
|
+
}
|
|
352
|
+
const [root, stripped] = opt.preservePaths ? ['', entry.path] : (0, strip_absolute_path_js_1.stripAbsolutePath)(entry.path);
|
|
353
|
+
entry.path = stripped;
|
|
354
|
+
if (fromPath) {
|
|
355
|
+
if (win32)
|
|
356
|
+
entry.path = winchars.decode(entry.path);
|
|
357
|
+
if (entry.path === '')
|
|
358
|
+
entry.path = './';
|
|
359
|
+
}
|
|
360
|
+
if (root) {
|
|
361
|
+
(0, warn_js_1.warn)(opt, 'TAR_ENTRY_INFO', `stripping ${root} from absolute path`, {
|
|
362
|
+
entry,
|
|
363
|
+
path: root + entry.path,
|
|
364
|
+
});
|
|
327
365
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
366
|
+
if (fromPath && dir && !entry.path.endsWith('/'))
|
|
367
|
+
entry.path += '/';
|
|
368
|
+
if (opt.portable) {
|
|
369
|
+
entry.uid =
|
|
370
|
+
entry.gid =
|
|
371
|
+
entry.dev =
|
|
372
|
+
entry.ino =
|
|
373
|
+
entry.nlink =
|
|
374
|
+
undefined;
|
|
375
|
+
entry.uname = entry.gname = undefined;
|
|
376
|
+
entry.atime = entry.ctime = undefined;
|
|
377
|
+
}
|
|
378
|
+
if (entry.mode !== undefined) {
|
|
379
|
+
entry.mode = (0, mode_fix_js_1.modeFix)(entry.mode, dir, !!opt.portable);
|
|
380
|
+
}
|
|
381
|
+
entry.mtime =
|
|
382
|
+
opt.noMtime || (opt.portable && dir) ?
|
|
383
|
+
undefined
|
|
384
|
+
: opt.mtime || entry.mtime;
|
|
385
|
+
return entry;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
exports.PackBase = PackBase;
|
|
389
|
+
// Read from the handle into `buf` at `off`, until the buffer is full
|
|
390
|
+
// or the file has no more bytes. `pos` is the place in the file.
|
|
391
|
+
// Returns the new place.
|
|
392
|
+
const fill = async (handle, buf, off, pos, size, path) => {
|
|
393
|
+
while (off < buf.length && pos < size) {
|
|
394
|
+
const { bytesRead } = await handle.read(buf, off, buf.length - off, pos);
|
|
395
|
+
if (bytesRead <= 0)
|
|
396
|
+
throw fewer(path, size);
|
|
397
|
+
if (bytesRead > size - pos)
|
|
398
|
+
throw more(path, size);
|
|
399
|
+
off += bytesRead;
|
|
400
|
+
pos += bytesRead;
|
|
401
|
+
}
|
|
402
|
+
return pos;
|
|
403
|
+
};
|
|
404
|
+
const fillSync = (fs, fd, buf, off, pos, size, path) => {
|
|
405
|
+
while (off < buf.length && pos < size) {
|
|
406
|
+
const bytesRead = fs.readSync(fd, buf, off, buf.length - off, pos);
|
|
407
|
+
if (bytesRead <= 0)
|
|
408
|
+
throw fewer(path, size);
|
|
409
|
+
if (bytesRead > size - pos)
|
|
410
|
+
throw more(path, size);
|
|
411
|
+
off += bytesRead;
|
|
412
|
+
pos += bytesRead;
|
|
413
|
+
}
|
|
414
|
+
return pos;
|
|
415
|
+
};
|
|
416
|
+
// The chunks of a body, from each kind of content.
|
|
417
|
+
async function* chunks(body) {
|
|
418
|
+
if ((0, bytes_js_1.isUint8Array)(body))
|
|
419
|
+
yield body;
|
|
420
|
+
else if ((0, bytes_js_1.isBlob)(body) || (0, bytes_js_1.isReadableStream)(body)) {
|
|
421
|
+
const reader = ((0, bytes_js_1.isBlob)(body) ? body.stream() : body).getReader();
|
|
422
|
+
try {
|
|
423
|
+
for (;;) {
|
|
424
|
+
const res = await reader.read();
|
|
425
|
+
if (res.done)
|
|
426
|
+
break;
|
|
427
|
+
yield res.value;
|
|
335
428
|
}
|
|
336
429
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
430
|
+
finally {
|
|
431
|
+
await reader.cancel().catch(noop);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
else if (body)
|
|
435
|
+
yield* body;
|
|
436
|
+
}
|
|
437
|
+
function* chunksSync(body) {
|
|
438
|
+
if ((0, bytes_js_1.isUint8Array)(body))
|
|
439
|
+
yield body;
|
|
440
|
+
else if (body && Symbol.iterator in body)
|
|
441
|
+
yield* body;
|
|
442
|
+
else if (body) {
|
|
443
|
+
throw new TypeError('PackSync needs a body that is a string, a Uint8Array, or an iterable');
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// Count the bytes of a body part. Returns the bytes that are left.
|
|
447
|
+
const count = (entry, remain, chunk) => {
|
|
448
|
+
if (chunk.length > remain)
|
|
449
|
+
throw tooLong(entry);
|
|
450
|
+
return remain - chunk.length;
|
|
451
|
+
};
|
|
452
|
+
// The zeros after a body, or an error if the body was too short.
|
|
453
|
+
const padding = (entry, remain) => {
|
|
454
|
+
if (remain)
|
|
455
|
+
throw eof('encountered unexpected EOF', pathOf(entry));
|
|
456
|
+
return new Uint8Array(blockLength(entry.size) - entry.size);
|
|
457
|
+
};
|
|
458
|
+
// The body of the entry, with the zeros that fill its last block.
|
|
459
|
+
async function* bodyBlocks(entry) {
|
|
460
|
+
if (!entry.size)
|
|
461
|
+
return;
|
|
462
|
+
let remain = entry.size;
|
|
463
|
+
for await (const chunk of chunks(entry.body)) {
|
|
464
|
+
remain = count(entry, remain, chunk);
|
|
465
|
+
yield chunk;
|
|
466
|
+
}
|
|
467
|
+
const pad = padding(entry, remain);
|
|
468
|
+
if (pad.length)
|
|
469
|
+
yield pad;
|
|
470
|
+
}
|
|
471
|
+
function* bodyBlocksSync(entry) {
|
|
472
|
+
if (!entry.size)
|
|
473
|
+
return;
|
|
474
|
+
let remain = entry.size;
|
|
475
|
+
for (const chunk of chunksSync(entry.body)) {
|
|
476
|
+
remain = count(entry, remain, chunk);
|
|
477
|
+
yield chunk;
|
|
478
|
+
}
|
|
479
|
+
const pad = padding(entry, remain);
|
|
480
|
+
if (pad.length)
|
|
481
|
+
yield pad;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Makes an archive. `add()` paths and entries, then `end()`. The
|
|
485
|
+
* pack is the async iterator of the bytes of the archive, compressed
|
|
486
|
+
* if an option selects a codec.
|
|
487
|
+
*
|
|
488
|
+
* It reads the file system only when the consumer asks for bytes.
|
|
489
|
+
* Then it reads the first `jobs` paths of the queue at the same
|
|
490
|
+
* time, and writes them in the order of the queue. The entries of a
|
|
491
|
+
* directory go to the end of the queue.
|
|
492
|
+
*
|
|
493
|
+
* `return()` closes each file that is open.
|
|
494
|
+
*/
|
|
495
|
+
class Pack extends PackBase {
|
|
496
|
+
jobs;
|
|
497
|
+
#out;
|
|
498
|
+
// Settles when the pack called `plan()` for each path that it
|
|
499
|
+
// started to read. It keeps the calls in the order of the queue.
|
|
500
|
+
#planned = Promise.resolve();
|
|
501
|
+
constructor(opt = {}) {
|
|
502
|
+
super(opt, 'compress');
|
|
503
|
+
this.jobs = (0, options_js_1.countOption)('jobs', this.opt.jobs, 4);
|
|
504
|
+
}
|
|
505
|
+
async next() {
|
|
506
|
+
const res = await (this.#out ??= this.#output()).next();
|
|
507
|
+
return res.done ? { value: undefined, done: true } : res;
|
|
508
|
+
}
|
|
509
|
+
/** Stop, and close each file that is open. */
|
|
510
|
+
async return() {
|
|
511
|
+
this.end();
|
|
512
|
+
await this.#out?.return();
|
|
513
|
+
return { value: undefined, done: true };
|
|
514
|
+
}
|
|
515
|
+
[Symbol.asyncIterator]() {
|
|
516
|
+
return this;
|
|
517
|
+
}
|
|
518
|
+
#output() {
|
|
519
|
+
const { codec } = this;
|
|
520
|
+
return codec?.compress ?
|
|
521
|
+
this.#compress(codec.compress(this.codecOptions))
|
|
522
|
+
: this.#run();
|
|
523
|
+
}
|
|
524
|
+
async *#compress(stream) {
|
|
525
|
+
const run = this.#run();
|
|
526
|
+
// An error of the pack goes to the consumer, also when the codec
|
|
527
|
+
// does not pass it on: then the cancel ends the read.
|
|
528
|
+
let failure;
|
|
529
|
+
const reader = (0, to_stream_js_1.toStream)({
|
|
530
|
+
next: () => run.next().catch(er => {
|
|
531
|
+
failure = { er };
|
|
532
|
+
void reader.cancel().catch(noop);
|
|
533
|
+
throw er;
|
|
534
|
+
}),
|
|
535
|
+
})
|
|
536
|
+
.pipeThrough(stream)
|
|
537
|
+
.getReader();
|
|
538
|
+
try {
|
|
539
|
+
for (;;) {
|
|
540
|
+
const res = await reader.read();
|
|
541
|
+
if (failure)
|
|
542
|
+
throw failure.er;
|
|
543
|
+
if (res.done)
|
|
544
|
+
break;
|
|
545
|
+
yield res.value;
|
|
345
546
|
}
|
|
346
547
|
}
|
|
548
|
+
finally {
|
|
549
|
+
await reader.cancel().catch(noop);
|
|
550
|
+
await run.return();
|
|
551
|
+
}
|
|
347
552
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const key = `${stat.dev}:${stat.ino}`;
|
|
358
|
-
const pending = this[PENDINGLINKS].get(key);
|
|
359
|
-
if (pending) {
|
|
360
|
-
this[PENDINGLINKS].delete(key);
|
|
361
|
-
for (const job of pending) {
|
|
362
|
-
job.pending = false;
|
|
363
|
-
this[PROCESSJOB](job);
|
|
553
|
+
async *#run() {
|
|
554
|
+
try {
|
|
555
|
+
for (;;) {
|
|
556
|
+
const node = this.head;
|
|
557
|
+
if (!node) {
|
|
558
|
+
if (this.ended)
|
|
559
|
+
break;
|
|
560
|
+
await new Promise(res => (this.wake = res));
|
|
561
|
+
continue;
|
|
364
562
|
}
|
|
563
|
+
this.#start();
|
|
564
|
+
const { item } = node;
|
|
565
|
+
if (item instanceof PackJob)
|
|
566
|
+
yield* this.#path(item);
|
|
567
|
+
else if (!isSource(item))
|
|
568
|
+
yield* this.#entry(item);
|
|
569
|
+
else
|
|
570
|
+
for await (const entry of item)
|
|
571
|
+
yield* this.#entry(entry);
|
|
572
|
+
this.shift();
|
|
573
|
+
}
|
|
574
|
+
yield new Uint8Array(1024);
|
|
575
|
+
}
|
|
576
|
+
finally {
|
|
577
|
+
// Close the files of the paths that the pack did not write.
|
|
578
|
+
for (let node = this.head; node; node = node.next) {
|
|
579
|
+
const { item } = node;
|
|
580
|
+
if (!(item instanceof PackJob) || !item.ready)
|
|
581
|
+
break;
|
|
582
|
+
const load = await item.ready.catch(noop);
|
|
583
|
+
await load?.handle?.close().catch(noop);
|
|
365
584
|
}
|
|
366
585
|
}
|
|
367
|
-
this[PROCESS]();
|
|
368
586
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
job
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
587
|
+
// Start to read the paths at the start of the queue.
|
|
588
|
+
#start() {
|
|
589
|
+
const fs = this.fs;
|
|
590
|
+
let node = this.head;
|
|
591
|
+
for (let n = 0; node && n < this.jobs; n++, node = node.next) {
|
|
592
|
+
const job = node.item;
|
|
593
|
+
// An entry can change what the filter does with a later path.
|
|
594
|
+
if (!(job instanceof PackJob))
|
|
595
|
+
break;
|
|
596
|
+
if (job.ready)
|
|
597
|
+
continue;
|
|
598
|
+
const stat = this.#stat(fs, job.absolute);
|
|
599
|
+
stat.catch(noop);
|
|
600
|
+
const planned = this.#planned
|
|
601
|
+
.then(() => stat)
|
|
602
|
+
.then(([st, id]) => {
|
|
603
|
+
const type = this.plan(job, st, id);
|
|
604
|
+
return type && { load: this.#load(fs, job, st, id, type) };
|
|
605
|
+
}, er => this.missing(job, er));
|
|
606
|
+
this.#planned = planned.catch(noop);
|
|
607
|
+
job.ready = planned.then(p => p?.load);
|
|
608
|
+
job.ready.catch(noop);
|
|
378
609
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
610
|
+
}
|
|
611
|
+
// The stat of a path, and the identity of the object.
|
|
612
|
+
async #stat(fs, path) {
|
|
613
|
+
const { follow } = this.opt;
|
|
614
|
+
const stat = await (follow ? fs.stat(path) : fs.lstat(path));
|
|
615
|
+
const id = !this.needsExact(stat) ?
|
|
616
|
+
stat
|
|
617
|
+
: await (follow ? fs.stat(path, BIG) : fs.lstat(path, BIG));
|
|
618
|
+
return [stat, id];
|
|
619
|
+
}
|
|
620
|
+
async #load(fs, job, stat, id, type) {
|
|
621
|
+
const { absolute } = job;
|
|
622
|
+
const { follow, noDirRecurse } = this.opt;
|
|
623
|
+
const load = { stat, id, type };
|
|
624
|
+
if (type === 'SymbolicLink') {
|
|
625
|
+
load.linkpath = await fs.readlink(absolute);
|
|
626
|
+
}
|
|
627
|
+
else if (type === 'Directory' && !noDirRecurse) {
|
|
628
|
+
load.names = await fs.readdir(absolute);
|
|
629
|
+
load.changed = !follow && !same(stat, await fs.lstat(absolute));
|
|
630
|
+
}
|
|
631
|
+
else if (type === 'File' && stat.size) {
|
|
632
|
+
const handle = await fs.open(absolute, 'r');
|
|
633
|
+
try {
|
|
634
|
+
const { size } = stat;
|
|
635
|
+
const length = blockLength(size);
|
|
636
|
+
if (!follow && !same(stat, await handle.stat())) {
|
|
637
|
+
load.changed = true;
|
|
638
|
+
}
|
|
639
|
+
else if (length > this.maxReadSize)
|
|
640
|
+
load.handle = handle;
|
|
641
|
+
else {
|
|
642
|
+
load.buf = new Uint8Array(512 + length);
|
|
643
|
+
await fill(handle, load.buf, 512, 0, size, absolute);
|
|
644
|
+
}
|
|
389
645
|
}
|
|
390
|
-
|
|
391
|
-
|
|
646
|
+
catch (er) {
|
|
647
|
+
await handle.close().catch(noop);
|
|
648
|
+
throw er;
|
|
392
649
|
}
|
|
650
|
+
if (!load.handle)
|
|
651
|
+
await handle.close();
|
|
393
652
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
if (
|
|
653
|
+
return load;
|
|
654
|
+
}
|
|
655
|
+
async *#path(job) {
|
|
656
|
+
const load = await job.ready;
|
|
657
|
+
if (!load)
|
|
399
658
|
return;
|
|
400
|
-
}
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
659
|
+
const { stat, id, type, names, buf, handle } = load;
|
|
660
|
+
if (load.changed)
|
|
661
|
+
return this.changed(job, type);
|
|
662
|
+
let ok = false;
|
|
663
|
+
try {
|
|
664
|
+
const body = buf ?
|
|
665
|
+
buf.subarray(512, 512 + stat.size)
|
|
666
|
+
: handle && this.#read(handle, stat.size, job.absolute);
|
|
667
|
+
const entry = this.pathEntry(job, stat, type, load.linkpath ?? job.linkpath, body);
|
|
668
|
+
if (names) {
|
|
669
|
+
for (const child of this.children(job, names, id)) {
|
|
670
|
+
this.push(child);
|
|
671
|
+
}
|
|
405
672
|
}
|
|
406
|
-
|
|
407
|
-
|
|
673
|
+
await this.opt.onWriteEntry?.(entry);
|
|
674
|
+
// The header goes in the space before a body that is in `buf`.
|
|
675
|
+
const whole = buf && entry.body === body && entry.size === stat.size;
|
|
676
|
+
yield* entry.encode(this.header, whole ? buf : undefined);
|
|
677
|
+
if (!whole)
|
|
678
|
+
yield* bodyBlocks(entry);
|
|
679
|
+
ok = true;
|
|
680
|
+
}
|
|
681
|
+
finally {
|
|
682
|
+
if (handle) {
|
|
683
|
+
load.handle = undefined;
|
|
684
|
+
const closed = handle.close();
|
|
685
|
+
await (ok ? closed : closed.catch(noop));
|
|
408
686
|
}
|
|
409
|
-
if (!job.readdir) {
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
// we know it doesn't have an entry, because that got checked above
|
|
414
|
-
job.entry = this[ENTRY](job);
|
|
415
|
-
if (!job.entry) {
|
|
416
|
-
job.ignore = true;
|
|
417
|
-
return;
|
|
418
687
|
}
|
|
419
|
-
|
|
420
|
-
|
|
688
|
+
}
|
|
689
|
+
// The chunks of a file that is larger than `maxReadSize`.
|
|
690
|
+
async *#read(handle, size, path) {
|
|
691
|
+
const length = blockLength(size);
|
|
692
|
+
for (let pos = 0; pos < size;) {
|
|
693
|
+
// Ask for the bytes of the last block also, to find a file that
|
|
694
|
+
// is larger now.
|
|
695
|
+
const buf = new Uint8Array(Math.min(length - pos, this.maxReadSize));
|
|
696
|
+
const end = await fill(handle, buf, 0, pos, size, path);
|
|
697
|
+
yield buf.subarray(0, end - pos);
|
|
698
|
+
pos = end;
|
|
421
699
|
}
|
|
422
700
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
701
|
+
async *#entry(item) {
|
|
702
|
+
const entry = this.addedEntry(item);
|
|
703
|
+
if (!entry)
|
|
704
|
+
return;
|
|
705
|
+
await this.opt.onWriteEntry?.(entry);
|
|
706
|
+
yield* entry.encode(this.header);
|
|
707
|
+
yield* bodyBlocks(entry);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
exports.Pack = Pack;
|
|
711
|
+
/**
|
|
712
|
+
* Makes an archive with no promise. `add()` paths and entries. The
|
|
713
|
+
* pack is the iterator of the bytes of the archive. It reads the
|
|
714
|
+
* file system only when the consumer asks for bytes, one path at a
|
|
715
|
+
* time. The entries of a directory come before the next item that
|
|
716
|
+
* the caller added.
|
|
717
|
+
*
|
|
718
|
+
* The pack ends when the iterator comes to the end of the queue.
|
|
719
|
+
* With compression, the iterator gives all the archive in one chunk.
|
|
720
|
+
*/
|
|
721
|
+
class PackSync extends PackBase {
|
|
722
|
+
#out;
|
|
723
|
+
constructor(opt = {}) {
|
|
724
|
+
super(opt, 'compressSync');
|
|
725
|
+
}
|
|
726
|
+
next() {
|
|
727
|
+
const res = (this.#out ??= this.#output()).next();
|
|
728
|
+
return res.done ? { value: undefined, done: true } : res;
|
|
440
729
|
}
|
|
441
|
-
|
|
442
|
-
|
|
730
|
+
/** Stop, and close the file that is open. */
|
|
731
|
+
return() {
|
|
732
|
+
this.ended = true;
|
|
733
|
+
this.#out?.return();
|
|
734
|
+
return { value: undefined, done: true };
|
|
735
|
+
}
|
|
736
|
+
[Symbol.iterator]() {
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
*#output() {
|
|
740
|
+
const { codec } = this;
|
|
741
|
+
if (!codec?.compressSync)
|
|
742
|
+
return yield* this.#run();
|
|
743
|
+
yield codec.compressSync((0, concat_js_1.concat)([...this.#run()]), this.codecOptions);
|
|
744
|
+
}
|
|
745
|
+
*#run() {
|
|
746
|
+
for (let node; (node = this.head); this.shift()) {
|
|
747
|
+
const { item } = node;
|
|
748
|
+
if (item instanceof PackJob) {
|
|
749
|
+
const jobs = [item];
|
|
750
|
+
for (const job of jobs)
|
|
751
|
+
yield* this.#path(job, jobs);
|
|
752
|
+
}
|
|
753
|
+
else if (!isSource(item))
|
|
754
|
+
yield* this.#entry(item);
|
|
755
|
+
else
|
|
756
|
+
for (const entry of item)
|
|
757
|
+
yield* this.#entry(entry);
|
|
758
|
+
}
|
|
759
|
+
this.ended = true;
|
|
760
|
+
yield new Uint8Array(1024);
|
|
761
|
+
}
|
|
762
|
+
*#path(job, jobs) {
|
|
763
|
+
const fs = this.fs;
|
|
764
|
+
const { absolute } = job;
|
|
765
|
+
const { follow, noDirRecurse } = this.opt;
|
|
766
|
+
let stat;
|
|
443
767
|
try {
|
|
444
|
-
|
|
445
|
-
return e
|
|
446
|
-
.on('end', () => this[JOBDONE](job))
|
|
447
|
-
.on('error', er => this.emit('error', er));
|
|
768
|
+
stat = follow ? fs.statSync(absolute) : fs.lstatSync(absolute);
|
|
448
769
|
}
|
|
449
770
|
catch (er) {
|
|
450
|
-
this.
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
[ONDRAIN]() {
|
|
454
|
-
if (this[CURRENT] && this[CURRENT].entry) {
|
|
455
|
-
this[CURRENT].entry.resume();
|
|
771
|
+
return this.missing(job, er);
|
|
456
772
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
source.on('data', chunk => {
|
|
476
|
-
if (!zip.write(chunk)) {
|
|
477
|
-
source.pause();
|
|
773
|
+
const id = !this.needsExact(stat) ? stat
|
|
774
|
+
: follow ? fs.statSync(absolute, BIG)
|
|
775
|
+
: fs.lstatSync(absolute, BIG);
|
|
776
|
+
const type = this.plan(job, stat, id);
|
|
777
|
+
if (!type)
|
|
778
|
+
return;
|
|
779
|
+
let { linkpath } = job;
|
|
780
|
+
let buf;
|
|
781
|
+
let body;
|
|
782
|
+
let fd;
|
|
783
|
+
let ok = false;
|
|
784
|
+
try {
|
|
785
|
+
if (type === 'SymbolicLink')
|
|
786
|
+
linkpath = fs.readlinkSync(absolute);
|
|
787
|
+
else if (type === 'Directory' && !noDirRecurse) {
|
|
788
|
+
const names = fs.readdirSync(absolute);
|
|
789
|
+
if (!follow && !same(stat, fs.lstatSync(absolute))) {
|
|
790
|
+
return this.changed(job, type);
|
|
478
791
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
792
|
+
jobs.push(...this.children(job, names, id));
|
|
793
|
+
}
|
|
794
|
+
else if (type === 'File' && stat.size) {
|
|
795
|
+
const { size } = stat;
|
|
796
|
+
const length = blockLength(size);
|
|
797
|
+
fd = fs.openSync(absolute, 'r');
|
|
798
|
+
if (!follow && !same(stat, fs.fstatSync(fd))) {
|
|
799
|
+
return this.changed(job, type);
|
|
485
800
|
}
|
|
486
|
-
|
|
801
|
+
if (length > this.maxReadSize) {
|
|
802
|
+
body = this.#read(fs, fd, size, absolute);
|
|
803
|
+
}
|
|
804
|
+
else {
|
|
805
|
+
buf = new Uint8Array(512 + length);
|
|
806
|
+
fillSync(fs, fd, buf, 512, 0, size, absolute);
|
|
807
|
+
body = buf.subarray(512, 512 + size);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
const entry = this.pathEntry(job, stat, type, linkpath, body);
|
|
811
|
+
this.opt.onWriteEntry?.(entry);
|
|
812
|
+
// The header goes in the space before a body that is in `buf`.
|
|
813
|
+
const whole = buf && entry.body === body && entry.size === stat.size;
|
|
814
|
+
yield* entry.encode(this.header, whole ? buf : undefined);
|
|
815
|
+
if (!whole)
|
|
816
|
+
yield* bodyBlocksSync(entry);
|
|
817
|
+
ok = true;
|
|
818
|
+
}
|
|
819
|
+
finally {
|
|
820
|
+
// An error of close must not hide the first error.
|
|
821
|
+
if (fd !== undefined && !ok) {
|
|
822
|
+
try {
|
|
823
|
+
fs.closeSync(fd);
|
|
824
|
+
}
|
|
825
|
+
catch { }
|
|
826
|
+
}
|
|
487
827
|
}
|
|
828
|
+
if (fd !== undefined)
|
|
829
|
+
fs.closeSync(fd);
|
|
488
830
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
831
|
+
// The chunks of a file that is larger than `maxReadSize`.
|
|
832
|
+
*#read(fs, fd, size, path) {
|
|
833
|
+
const length = blockLength(size);
|
|
834
|
+
for (let pos = 0; pos < size;) {
|
|
835
|
+
const buf = new Uint8Array(Math.min(length - pos, this.maxReadSize));
|
|
836
|
+
const end = fillSync(fs, fd, buf, 0, pos, size, path);
|
|
837
|
+
yield buf.subarray(0, end - pos);
|
|
838
|
+
pos = end;
|
|
492
839
|
}
|
|
493
|
-
return super.pause();
|
|
494
|
-
}
|
|
495
|
-
warn(code, message, data = {}) {
|
|
496
|
-
(0, warn_method_js_1.warnMethod)(this, code, message, data);
|
|
497
840
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
// pause/resume are no-ops in sync streams.
|
|
507
|
-
pause() { }
|
|
508
|
-
resume() { }
|
|
509
|
-
[STAT](job) {
|
|
510
|
-
const stat = this.follow ? 'statSync' : 'lstatSync';
|
|
511
|
-
this[ONSTAT](job, fs_1.default[stat](job.absolute));
|
|
512
|
-
}
|
|
513
|
-
[READDIR](job) {
|
|
514
|
-
this[ONREADDIR](job, fs_1.default.readdirSync(job.absolute));
|
|
515
|
-
}
|
|
516
|
-
// gotta get it all in this tick
|
|
517
|
-
[PIPE](job) {
|
|
518
|
-
const source = job.entry;
|
|
519
|
-
const zip = this.zip;
|
|
520
|
-
if (job.readdir) {
|
|
521
|
-
job.readdir.forEach(entry => {
|
|
522
|
-
const p = job.path;
|
|
523
|
-
const base = p === './' ? '' : p.replace(/\/*$/, '/');
|
|
524
|
-
this[ADDFSENTRY](base + entry);
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
/* c8 ignore start */
|
|
528
|
-
if (!source)
|
|
529
|
-
throw new Error('Cannot pipe without source');
|
|
530
|
-
/* c8 ignore stop */
|
|
531
|
-
if (zip) {
|
|
532
|
-
source.on('data', chunk => {
|
|
533
|
-
zip.write(chunk);
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
source.on('data', chunk => {
|
|
538
|
-
super[WRITE](chunk);
|
|
539
|
-
});
|
|
540
|
-
}
|
|
841
|
+
*#entry(item) {
|
|
842
|
+
const entry = this.addedEntry(item);
|
|
843
|
+
if (!entry)
|
|
844
|
+
return;
|
|
845
|
+
this.opt.onWriteEntry?.(entry);
|
|
846
|
+
yield* entry.encode(this.header);
|
|
847
|
+
yield* bodyBlocksSync(entry);
|
|
541
848
|
}
|
|
542
849
|
}
|
|
543
850
|
exports.PackSync = PackSync;
|