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
package/dist/esm/create.js
CHANGED
|
@@ -1,76 +1,159 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { dealias, } from './dealias.js';
|
|
2
|
+
import { TarReader, TarReaderSync } from './entries.js';
|
|
3
|
+
import { Pack, PackSync, } from './pack.js';
|
|
4
|
+
import { readFile, readFileSync } from './read-file.js';
|
|
5
|
+
import { toStream } from './to-stream.js';
|
|
6
|
+
// Chunks that are smaller than this are put together for one write.
|
|
7
|
+
const SMALL = 64 * 1024;
|
|
8
|
+
const BATCH = 4 * SMALL;
|
|
9
|
+
const noop = () => { };
|
|
10
|
+
const check = (opt, files) => {
|
|
11
|
+
if (!files?.length) {
|
|
12
|
+
throw new TypeError('no paths specified to add to archive');
|
|
13
|
+
}
|
|
14
|
+
if (opt.file && !opt.fs) {
|
|
15
|
+
throw new TypeError('the file option needs the fs option');
|
|
16
|
+
}
|
|
13
17
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
p.pipe(stream);
|
|
20
|
-
const promise = new Promise((res, rej) => {
|
|
21
|
-
stream.on('error', rej);
|
|
22
|
-
stream.on('close', res);
|
|
23
|
-
p.on('error', rej);
|
|
24
|
-
});
|
|
25
|
-
addFilesAsync(p, files).catch(er => p.emit('error', er));
|
|
26
|
-
return promise;
|
|
18
|
+
const writeAll = async (handle, buf, length, position) => {
|
|
19
|
+
for (let off = 0; off < length;) {
|
|
20
|
+
off += (await handle.write(buf, off, length - off, position + off))
|
|
21
|
+
.bytesWritten;
|
|
22
|
+
}
|
|
27
23
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Write the chunks to the file, from `position`. Chunks that are
|
|
26
|
+
* smaller than 64 KiB are put together for one write.
|
|
27
|
+
*/
|
|
28
|
+
export const writeChunks = async (handle, chunks, position) => {
|
|
29
|
+
const batch = new Uint8Array(BATCH);
|
|
30
|
+
let used = 0;
|
|
31
|
+
const flush = async () => {
|
|
32
|
+
await writeAll(handle, batch, used, position);
|
|
33
|
+
position += used;
|
|
34
|
+
used = 0;
|
|
35
|
+
};
|
|
36
|
+
for await (const chunk of chunks) {
|
|
37
|
+
if (used + chunk.length > BATCH || chunk.length >= SMALL)
|
|
38
|
+
await flush();
|
|
39
|
+
if (chunk.length >= SMALL) {
|
|
40
|
+
await writeAll(handle, chunk, chunk.length, position);
|
|
41
|
+
position += chunk.length;
|
|
37
42
|
}
|
|
38
43
|
else {
|
|
39
|
-
|
|
44
|
+
batch.set(chunk, used);
|
|
45
|
+
used += chunk.length;
|
|
40
46
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
47
|
+
}
|
|
48
|
+
await flush();
|
|
43
49
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
p.add(entry);
|
|
52
|
-
},
|
|
53
|
-
});
|
|
50
|
+
/** The sync form of `writeChunks`. */
|
|
51
|
+
export const writeChunksSync = (fs, fd, chunks, position) => {
|
|
52
|
+
const batch = new Uint8Array(BATCH);
|
|
53
|
+
let used = 0;
|
|
54
|
+
const write = (buf, length) => {
|
|
55
|
+
for (let off = 0; off < length;) {
|
|
56
|
+
off += fs.writeSync(fd, buf, off, length - off, position + off);
|
|
54
57
|
}
|
|
58
|
+
position += length;
|
|
59
|
+
};
|
|
60
|
+
for (const chunk of chunks) {
|
|
61
|
+
if (used + chunk.length > BATCH || chunk.length >= SMALL) {
|
|
62
|
+
write(batch, used);
|
|
63
|
+
used = 0;
|
|
64
|
+
}
|
|
65
|
+
if (chunk.length >= SMALL)
|
|
66
|
+
write(chunk, chunk.length);
|
|
55
67
|
else {
|
|
56
|
-
|
|
68
|
+
batch.set(chunk, used);
|
|
69
|
+
used += chunk.length;
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
|
-
|
|
72
|
+
write(batch, used);
|
|
60
73
|
};
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
const createFile = async (pack, fs, file, mode) => {
|
|
75
|
+
const handle = await fs.open(file, 'w', mode);
|
|
76
|
+
let ok = false;
|
|
77
|
+
try {
|
|
78
|
+
await writeChunks(handle, pack, 0);
|
|
79
|
+
ok = true;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
const closed = handle.close();
|
|
83
|
+
await (ok ? closed : closed.catch(noop));
|
|
84
|
+
}
|
|
65
85
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Make the pack for the files of a command. A name that starts with
|
|
88
|
+
* `@` is the path of an archive: the pack gets its entries.
|
|
89
|
+
*/
|
|
90
|
+
export const packFiles = (opt, files) => {
|
|
91
|
+
const { fs, strict, onwarn, codecs, platform } = opt;
|
|
92
|
+
const pack = new Pack(opt);
|
|
93
|
+
for (const item of files) {
|
|
94
|
+
if (typeof item !== 'string' || item.charAt(0) !== '@')
|
|
95
|
+
pack.add(item);
|
|
96
|
+
else {
|
|
97
|
+
const archive = pack.resolve(item.slice(1));
|
|
98
|
+
pack.add(new TarReader(readFile(fs, archive, opt.maxReadSize), {
|
|
99
|
+
strict,
|
|
100
|
+
onwarn,
|
|
101
|
+
codecs,
|
|
102
|
+
platform,
|
|
103
|
+
file: archive,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return pack.end();
|
|
70
108
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
109
|
+
/** The sync form of `packFiles`. */
|
|
110
|
+
export const packFilesSync = (opt, files) => {
|
|
111
|
+
const { strict, onwarn, codecs, platform } = opt;
|
|
112
|
+
const pack = new PackSync(opt);
|
|
113
|
+
for (const item of files) {
|
|
114
|
+
if (typeof item !== 'string' || item.charAt(0) !== '@')
|
|
115
|
+
pack.add(item);
|
|
116
|
+
else {
|
|
117
|
+
const archive = pack.resolve(item.slice(1));
|
|
118
|
+
pack.add(new TarReaderSync(readFileSync(opt.fs, archive, opt.maxReadSize), { strict, onwarn, codecs, platform, file: archive }));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return pack;
|
|
122
|
+
};
|
|
123
|
+
export function create(options, files) {
|
|
124
|
+
const opt = dealias(options);
|
|
125
|
+
if (!opt.file) {
|
|
126
|
+
check(opt, files);
|
|
127
|
+
return toStream(packFiles(opt, files));
|
|
128
|
+
}
|
|
129
|
+
// The file form returns a promise, so a bad argument rejects it.
|
|
130
|
+
try {
|
|
131
|
+
check(opt, files);
|
|
132
|
+
return createFile(packFiles(opt, files), opt.fs, opt.file, opt.mode || 0o666);
|
|
133
|
+
}
|
|
134
|
+
catch (er) {
|
|
135
|
+
return Promise.reject(er);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export function createSync(options, files) {
|
|
139
|
+
const opt = dealias(options);
|
|
140
|
+
check(opt, files);
|
|
141
|
+
const { file } = opt;
|
|
142
|
+
const fs = opt.fs;
|
|
143
|
+
const pack = packFilesSync(opt, files);
|
|
144
|
+
if (!file)
|
|
145
|
+
return pack;
|
|
146
|
+
const fd = fs.openSync(file, 'w', opt.mode || 0o666);
|
|
147
|
+
try {
|
|
148
|
+
writeChunksSync(fs, fd, pack, 0);
|
|
149
|
+
}
|
|
150
|
+
catch (er) {
|
|
151
|
+
try {
|
|
152
|
+
fs.closeSync(fd);
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
throw er;
|
|
74
156
|
}
|
|
75
|
-
|
|
157
|
+
fs.closeSync(fd);
|
|
158
|
+
}
|
|
76
159
|
//# sourceMappingURL=create.js.map
|
package/dist/esm/create.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAO/C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,cAAc,GAAG,CAAC,GAAuB,EAAE,KAAe,EAAE,EAAE;I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,EAAE,KAAK,CAAC,CAAA;IACtB,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,GAAe,EAAE,KAAe,EAAE,EAAE;IACvD,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAA;IACvB,aAAa,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;IACxD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,WAAW,CAC/B,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;IACd,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAA;IAC7D,CAAC;AACH,CAAC,CACF,CAAA","sourcesContent":["import { WriteStream, WriteStreamSync } from '@isaacs/fs-minipass'\nimport type { Minipass } from 'minipass'\nimport path from 'node:path'\nimport { list } from './list.js'\nimport { makeCommand } from './make-command.js'\nimport type {\n TarOptions,\n TarOptionsFile,\n TarOptionsSync,\n TarOptionsSyncFile,\n} from './options.js'\nimport { Pack, PackSync } from './pack.js'\n\nconst createFileSync = (opt: TarOptionsSyncFile, files: string[]) => {\n const p = new PackSync(opt)\n const stream = new WriteStreamSync(opt.file, {\n mode: opt.mode || 0o666,\n })\n p.pipe(stream as unknown as Minipass.Writable)\n addFilesSync(p, files)\n}\n\nconst createFile = (opt: TarOptionsFile, files: string[]) => {\n const p = new Pack(opt)\n const stream = new WriteStream(opt.file, {\n mode: opt.mode || 0o666,\n })\n p.pipe(stream as unknown as Minipass.Writable)\n\n const promise = new Promise<void>((res, rej) => {\n stream.on('error', rej)\n stream.on('close', res)\n p.on('error', rej)\n })\n\n addFilesAsync(p, files).catch(er => p.emit('error', er))\n\n return promise\n}\n\nconst addFilesSync = (p: PackSync, files: string[]) => {\n files.forEach(file => {\n if (file.charAt(0) === '@') {\n list({\n file: path.resolve(p.cwd, file.slice(1)),\n sync: true,\n noResume: true,\n onReadEntry: entry => p.add(entry),\n })\n } else {\n p.add(file)\n }\n })\n p.end()\n}\n\nconst addFilesAsync = async (p: Pack, files: string[]): Promise<void> => {\n for (const file of files) {\n if (file.charAt(0) === '@') {\n await list({\n file: path.resolve(String(p.cwd), file.slice(1)),\n noResume: true,\n onReadEntry: entry => {\n p.add(entry)\n },\n })\n } else {\n p.add(file)\n }\n }\n p.end()\n}\n\nconst createSync = (opt: TarOptionsSync, files: string[]) => {\n const p = new PackSync(opt)\n addFilesSync(p, files)\n return p\n}\n\nconst createAsync = (opt: TarOptions, files: string[]) => {\n const p = new Pack(opt)\n addFilesAsync(p, files).catch(er => p.emit('error', er))\n return p\n}\n\nexport const create = makeCommand(\n createFileSync,\n createFile,\n createSync,\n createAsync,\n (_opt, files) => {\n if (!files?.length) {\n throw new TypeError('no paths specified to add to archive')\n }\n },\n)\n"]}
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAIR,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGvD,OAAO,EACL,IAAI,EACJ,QAAQ,GAGT,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,oEAAoE;AACpE,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,CAAA;AACvB,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAA;AACvB,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB,MAAM,KAAK,GAAG,CAA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AAC;YACH,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAClB,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QACV,MAAM,EAAE,CAAA;IACV,CAAC;IACD,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;AAClB,CAAC","sourcesContent":["import {\n dealias,\n type FileOption,\n type NoFileOption,\n type WithAliases,\n} from './dealias.js'\nimport { TarReader, TarReaderSync } from './entries.js'\nimport type { CreateFileHandle, CreateFS, CreateFSSync } from './fs.js'\nimport type { CreateOptions, CreateOptionsSync } from './options.js'\nimport {\n Pack,\n PackSync,\n type PackInput,\n type PackInputSync,\n} from './pack.js'\nimport { readFile, readFileSync } from './read-file.js'\nimport { toStream } from './to-stream.js'\n\n// Chunks that are smaller than this are put together for one write.\nconst SMALL = 64 * 1024\nconst BATCH = 4 * SMALL\nconst noop = () => {}\n\nconst check = (opt: { file?: string; fs?: unknown }, files: unknown[]) => {\n if (!files?.length) {\n throw new TypeError('no paths specified to add to archive')\n }\n if (opt.file && !opt.fs) {\n throw new TypeError('the file option needs the fs option')\n }\n}\n\nconst writeAll = async (\n handle: CreateFileHandle,\n buf: Uint8Array,\n length: number,\n position: number,\n) => {\n for (let off = 0; off < length; ) {\n off += (await handle.write(buf, off, length - off, position + off))\n .bytesWritten\n }\n}\n\n/**\n * Write the chunks to the file, from `position`. Chunks that are\n * smaller than 64 KiB are put together for one write.\n */\nexport const writeChunks = async (\n handle: CreateFileHandle,\n chunks: AsyncIterable<Uint8Array>,\n position: number,\n): Promise<void> => {\n const batch = new Uint8Array(BATCH)\n let used = 0\n const flush = async () => {\n await writeAll(handle, batch, used, position)\n position += used\n used = 0\n }\n for await (const chunk of chunks) {\n if (used + chunk.length > BATCH || chunk.length >= SMALL) await flush()\n if (chunk.length >= SMALL) {\n await writeAll(handle, chunk, chunk.length, position)\n position += chunk.length\n } else {\n batch.set(chunk, used)\n used += chunk.length\n }\n }\n await flush()\n}\n\n/** The sync form of `writeChunks`. */\nexport const writeChunksSync = (\n fs: CreateFSSync,\n fd: number,\n chunks: Iterable<Uint8Array>,\n position: number,\n): void => {\n const batch = new Uint8Array(BATCH)\n let used = 0\n const write = (buf: Uint8Array, length: number) => {\n for (let off = 0; off < length; ) {\n off += fs.writeSync(fd, buf, off, length - off, position + off)\n }\n position += length\n }\n for (const chunk of chunks) {\n if (used + chunk.length > BATCH || chunk.length >= SMALL) {\n write(batch, used)\n used = 0\n }\n if (chunk.length >= SMALL) write(chunk, chunk.length)\n else {\n batch.set(chunk, used)\n used += chunk.length\n }\n }\n write(batch, used)\n}\n\nconst createFile = async (\n pack: Pack,\n fs: CreateFS,\n file: string,\n mode: number,\n): Promise<void> => {\n const handle = await fs.open(file, 'w', mode)\n let ok = false\n try {\n await writeChunks(handle, pack, 0)\n ok = true\n } finally {\n const closed = handle.close()\n await (ok ? closed : closed.catch(noop))\n }\n}\n\n/**\n * Make the pack for the files of a command. A name that starts with\n * `@` is the path of an archive: the pack gets its entries.\n */\nexport const packFiles = (\n opt: CreateOptions,\n files: PackInput[],\n): Pack => {\n const { fs, strict, onwarn, codecs, platform } = opt\n const pack = new Pack(opt)\n for (const item of files) {\n if (typeof item !== 'string' || item.charAt(0) !== '@') pack.add(item)\n else {\n const archive = pack.resolve(item.slice(1))\n pack.add(\n new TarReader(readFile(fs as CreateFS, archive, opt.maxReadSize), {\n strict,\n onwarn,\n codecs,\n platform,\n file: archive,\n }),\n )\n }\n }\n return pack.end()\n}\n\n/** The sync form of `packFiles`. */\nexport const packFilesSync = (\n opt: CreateOptionsSync,\n files: PackInputSync[],\n): PackSync => {\n const { strict, onwarn, codecs, platform } = opt\n const pack = new PackSync(opt)\n for (const item of files) {\n if (typeof item !== 'string' || item.charAt(0) !== '@') pack.add(item)\n else {\n const archive = pack.resolve(item.slice(1))\n pack.add(\n new TarReaderSync(\n readFileSync(opt.fs as CreateFSSync, archive, opt.maxReadSize),\n { strict, onwarn, codecs, platform, file: archive },\n ),\n )\n }\n }\n return pack\n}\n\n/**\n * Make an archive of the files. A directory is added with all that\n * is in it. A name that starts with `@` is the path of an archive:\n * its entries are added. A file can also be an entry, or a source of\n * entries, as in `Pack.add()`.\n *\n * With `opt.file`, the archive is written to that path through\n * `opt.fs`. With no `opt.file`, the result is a stream of the bytes\n * of the archive. Files are read only when the stream is read.\n */\nexport function create(\n opt: WithAliases<CreateOptions> & FileOption,\n files: PackInput[],\n): Promise<void>\nexport function create(\n opt: WithAliases<CreateOptions> & NoFileOption,\n files: PackInput[],\n): ReadableStream<Uint8Array>\nexport function create(\n opt: WithAliases<CreateOptions>,\n files: PackInput[],\n): Promise<void> | ReadableStream<Uint8Array>\nexport function create(\n options: WithAliases<CreateOptions>,\n files: PackInput[],\n): Promise<void> | ReadableStream<Uint8Array> {\n const opt = dealias<CreateOptions>(options)\n if (!opt.file) {\n check(opt, files)\n return toStream(packFiles(opt, files))\n }\n // The file form returns a promise, so a bad argument rejects it.\n try {\n check(opt, files)\n return createFile(\n packFiles(opt, files),\n opt.fs as CreateFS,\n opt.file,\n opt.mode || 0o666,\n )\n } catch (er) {\n return Promise.reject(er)\n }\n}\n\n/**\n * The sync form of `create`. With no `opt.file`, the result is an\n * iterator of the bytes of the archive. Files are read only when the\n * iterator is read.\n */\nexport function createSync(\n opt: WithAliases<CreateOptionsSync> & FileOption,\n files: PackInputSync[],\n): void\nexport function createSync(\n opt: WithAliases<CreateOptionsSync> & NoFileOption,\n files: PackInputSync[],\n): IterableIterator<Uint8Array, undefined>\nexport function createSync(\n opt: WithAliases<CreateOptionsSync>,\n files: PackInputSync[],\n): void | IterableIterator<Uint8Array, undefined>\nexport function createSync(\n options: WithAliases<CreateOptionsSync>,\n files: PackInputSync[],\n): void | IterableIterator<Uint8Array, undefined> {\n const opt = dealias<CreateOptionsSync>(options)\n check(opt, files)\n const { file } = opt\n const fs = opt.fs as CreateFSSync\n const pack = packFilesSync(opt, files)\n if (!file) return pack\n const fd = fs.openSync(file, 'w', opt.mode || 0o666)\n try {\n writeChunksSync(fs, fd, pack, 0)\n } catch (er) {\n try {\n fs.closeSync(fd)\n } catch {}\n throw er\n }\n fs.closeSync(fd)\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The option aliases of the commands: the short names of the tar
|
|
3
|
+
* program, and the long names of version 7. Each alias has the name
|
|
4
|
+
* of its option.
|
|
5
|
+
*/
|
|
6
|
+
export declare const aliases: {
|
|
7
|
+
readonly C: "cwd";
|
|
8
|
+
readonly f: "file";
|
|
9
|
+
readonly z: "gzip";
|
|
10
|
+
readonly P: "preservePaths";
|
|
11
|
+
readonly U: "unlink";
|
|
12
|
+
readonly 'strip-components': "strip";
|
|
13
|
+
readonly stripComponents: "strip";
|
|
14
|
+
readonly 'keep-newer': "newer";
|
|
15
|
+
readonly keepNewer: "newer";
|
|
16
|
+
readonly 'keep-newer-files': "newer";
|
|
17
|
+
readonly keepNewerFiles: "newer";
|
|
18
|
+
readonly k: "keep";
|
|
19
|
+
readonly 'keep-existing': "keep";
|
|
20
|
+
readonly keepExisting: "keep";
|
|
21
|
+
readonly m: "noMtime";
|
|
22
|
+
readonly 'no-mtime': "noMtime";
|
|
23
|
+
readonly p: "preserveOwner";
|
|
24
|
+
readonly L: "follow";
|
|
25
|
+
readonly h: "follow";
|
|
26
|
+
readonly onentry: "onEntry";
|
|
27
|
+
readonly onReadEntry: "onEntry";
|
|
28
|
+
};
|
|
29
|
+
/** The alias names, and the name of the option of each one. */
|
|
30
|
+
export type Aliases = typeof aliases;
|
|
31
|
+
/** The names of the options that have an alias. */
|
|
32
|
+
export type Aliased = Aliases[keyof Aliases];
|
|
33
|
+
/** The alias names of the option `K`. */
|
|
34
|
+
export type AliasOf<K> = {
|
|
35
|
+
[A in keyof Aliases]: Aliases[A] extends K ? A : never;
|
|
36
|
+
}[keyof Aliases];
|
|
37
|
+
/**
|
|
38
|
+
* For each option `K` of `T`, an object type that requires the option
|
|
39
|
+
* or one of its aliases.
|
|
40
|
+
*/
|
|
41
|
+
export type RequiredOption<T, K extends keyof T> = [
|
|
42
|
+
K
|
|
43
|
+
] extends [never] ? unknown : (K extends unknown ? (x: {
|
|
44
|
+
v: {
|
|
45
|
+
[N in K | AliasOf<K>]: {
|
|
46
|
+
[P in N]: T[K];
|
|
47
|
+
};
|
|
48
|
+
}[K | AliasOf<K>];
|
|
49
|
+
}) => void : never) extends (x: infer I extends {
|
|
50
|
+
v: unknown;
|
|
51
|
+
}) => void ? I['v'] : never;
|
|
52
|
+
/**
|
|
53
|
+
* The option type `T` of a command, and the aliases of its options.
|
|
54
|
+
* An alias has the type of its option. An option that `T` requires
|
|
55
|
+
* can be given with its name or with an alias.
|
|
56
|
+
*/
|
|
57
|
+
export type WithAliases<T> = T extends unknown ? Omit<T, Aliased> & Partial<Pick<T, keyof T & Aliased>> & {
|
|
58
|
+
[A in keyof Aliases as Aliases[A] extends keyof T ? A : never]?: T[Aliases[A] & keyof T];
|
|
59
|
+
} & ('chmod' extends keyof T ? {
|
|
60
|
+
/** `noChmod: false` is `chmod: true`, if `chmod` is not set. */
|
|
61
|
+
noChmod?: boolean;
|
|
62
|
+
} : unknown) & RequiredOption<T, {
|
|
63
|
+
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
|
|
64
|
+
}[keyof T] & Aliased> : never;
|
|
65
|
+
/** The `file` option, with its name or with its alias. */
|
|
66
|
+
export type FileOption = RequiredOption<{
|
|
67
|
+
file: string;
|
|
68
|
+
}, 'file'>;
|
|
69
|
+
/** No `file` option. */
|
|
70
|
+
export type NoFileOption = {
|
|
71
|
+
[N in 'file' | AliasOf<'file'>]?: undefined;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A copy of the options, with no prototype, that has the name of the
|
|
75
|
+
* option in place of each alias. An option that is set wins over its
|
|
76
|
+
* aliases.
|
|
77
|
+
*/
|
|
78
|
+
export declare const dealias: <T extends object>(options: WithAliases<T>) => T;
|
|
79
|
+
//# sourceMappingURL=dealias.d.ts.map
|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,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG;KACnC,CAAC,IAAI,MAAM,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,GACnD,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;CACnC,GAAG,CAAC,OAAO,SAAS,MAAM,CAAC,GAC1B;IACE,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,GACD,OAAO,CAAC,GACV,cAAc,CACZ,CAAC,EAED;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;CACxD,CAAC,MAAM,CAAC,CAAC,GACR,OAAO,CACV,GACH,KAAK,CAAA;AAET,0DAA0D;AAC1D,MAAM,MAAM,UAAU,GAAG,cAAc,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,CAAC,CAAA;AAEjE,wBAAwB;AACxB,MAAM,MAAM,YAAY,GAAG;KAAG,CAAC,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS;CAAE,CAAA;AAE1E;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,KAAG,CAYnE,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The option aliases of the commands: the short names of the tar
|
|
3
|
+
* program, and the long names of version 7. Each alias has the name
|
|
4
|
+
* of its option.
|
|
5
|
+
*/
|
|
6
|
+
export const aliases = {
|
|
7
|
+
C: 'cwd',
|
|
8
|
+
f: 'file',
|
|
9
|
+
z: 'gzip',
|
|
10
|
+
P: 'preservePaths',
|
|
11
|
+
U: 'unlink',
|
|
12
|
+
'strip-components': 'strip',
|
|
13
|
+
stripComponents: 'strip',
|
|
14
|
+
'keep-newer': 'newer',
|
|
15
|
+
keepNewer: 'newer',
|
|
16
|
+
'keep-newer-files': 'newer',
|
|
17
|
+
keepNewerFiles: 'newer',
|
|
18
|
+
k: 'keep',
|
|
19
|
+
'keep-existing': 'keep',
|
|
20
|
+
keepExisting: 'keep',
|
|
21
|
+
m: 'noMtime',
|
|
22
|
+
'no-mtime': 'noMtime',
|
|
23
|
+
p: 'preserveOwner',
|
|
24
|
+
L: 'follow',
|
|
25
|
+
h: 'follow',
|
|
26
|
+
onentry: 'onEntry',
|
|
27
|
+
onReadEntry: 'onEntry',
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A copy of the options, with no prototype, that has the name of the
|
|
31
|
+
* option in place of each alias. An option that is set wins over its
|
|
32
|
+
* aliases.
|
|
33
|
+
*/
|
|
34
|
+
export const dealias = (options) => {
|
|
35
|
+
const opt = Object.assign(Object.create(null), options);
|
|
36
|
+
for (const [alias, name] of Object.entries(aliases)) {
|
|
37
|
+
if (opt[alias] !== undefined)
|
|
38
|
+
opt[name] ??= opt[alias];
|
|
39
|
+
delete opt[alias];
|
|
40
|
+
}
|
|
41
|
+
if (opt.noChmod === false)
|
|
42
|
+
opt.chmod ??= true;
|
|
43
|
+
delete opt.noChmod;
|
|
44
|
+
return opt;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=dealias.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dealias.js","sourceRoot":"","sources":["../../src/dealias.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,MAAM;IACT,CAAC,EAAE,eAAe;IAClB,CAAC,EAAE,QAAQ;IACX,kBAAkB,EAAE,OAAO;IAC3B,eAAe,EAAE,OAAO;IACxB,YAAY,EAAE,OAAO;IACrB,SAAS,EAAE,OAAO;IAClB,kBAAkB,EAAE,OAAO;IAC3B,cAAc,EAAE,OAAO;IACvB,CAAC,EAAE,MAAM;IACT,eAAe,EAAE,MAAM;IACvB,YAAY,EAAE,MAAM;IACpB,CAAC,EAAE,SAAS;IACZ,UAAU,EAAE,SAAS;IACrB,CAAC,EAAE,eAAe;IAClB,CAAC,EAAE,QAAQ;IACX,CAAC,EAAE,QAAQ;IACX,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,SAAS;CACd,CAAA;AAgEV;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAmB,OAAuB,EAAK,EAAE;IACtE,MAAM,GAAG,GAA4B,MAAM,CAAC,MAAM,CAChD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EACnB,OAAO,CACR,CAAA;IACD,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC,CAAA;QACtD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IACD,IAAI,GAAG,CAAC,OAAO,KAAK,KAAK;QAAE,GAAG,CAAC,KAAK,KAAK,IAAI,CAAA;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAA;IAClB,OAAO,GAAQ,CAAA;AACjB,CAAC,CAAA","sourcesContent":["/**\n * The option aliases of the commands: the short names of the tar\n * program, and the long names of version 7. Each alias has the name\n * of its option.\n */\nexport const aliases = {\n C: 'cwd',\n f: 'file',\n z: 'gzip',\n P: 'preservePaths',\n U: 'unlink',\n 'strip-components': 'strip',\n stripComponents: 'strip',\n 'keep-newer': 'newer',\n keepNewer: 'newer',\n 'keep-newer-files': 'newer',\n keepNewerFiles: 'newer',\n k: 'keep',\n 'keep-existing': 'keep',\n keepExisting: 'keep',\n m: 'noMtime',\n 'no-mtime': 'noMtime',\n p: 'preserveOwner',\n L: 'follow',\n h: 'follow',\n onentry: 'onEntry',\n onReadEntry: 'onEntry',\n} as const\n\n/** The alias names, and the name of the option of each one. */\nexport type Aliases = typeof aliases\n\n/** The names of the options that have an alias. */\nexport type Aliased = Aliases[keyof Aliases]\n\n/** The alias names of the option `K`. */\nexport type AliasOf<K> = {\n [A in keyof Aliases]: Aliases[A] extends K ? A : never\n}[keyof Aliases]\n\n/**\n * For each option `K` of `T`, an object type that requires the option\n * or one of its aliases.\n */\nexport type RequiredOption<T, K extends keyof T> =\n [K] extends [never] ? unknown\n : // A function type for each option, to make an intersection.\n (\n K extends unknown ?\n (x: {\n // A union: one object type for each name of the option.\n v: { [N in K | AliasOf<K>]: { [P in N]: T[K] } }[K | AliasOf<K>]\n }) => void\n : never\n ) extends (x: infer I extends { v: unknown }) => void ?\n I['v']\n : never\n\n/**\n * The option type `T` of a command, and the aliases of its options.\n * An alias has the type of its option. An option that `T` requires\n * can be given with its name or with an alias.\n */\nexport type WithAliases<T> =\n T extends unknown ?\n Omit<T, Aliased> &\n Partial<Pick<T, keyof T & Aliased>> & {\n [A in keyof Aliases as Aliases[A] extends keyof T ? A\n : never]?: T[Aliases[A] & keyof T]\n } & ('chmod' extends keyof T ?\n {\n /** `noChmod: false` is `chmod: true`, if `chmod` is not set. */\n noChmod?: boolean\n }\n : unknown) &\n RequiredOption<\n T,\n // The options that `T` must have.\n {\n [K in keyof T]-?: object extends Pick<T, K> ? never : K\n }[keyof T] &\n Aliased\n >\n : never\n\n/** The `file` option, with its name or with its alias. */\nexport type FileOption = RequiredOption<{ file: string }, 'file'>\n\n/** No `file` option. */\nexport type NoFileOption = { [N in 'file' | AliasOf<'file'>]?: undefined }\n\n/**\n * A copy of the options, with no prototype, that has the name of the\n * option in place of each alias. An option that is set wins over its\n * aliases.\n */\nexport const dealias = <T extends object>(options: WithAliases<T>): T => {\n const opt: Record<string, unknown> = Object.assign(\n Object.create(null),\n options,\n )\n for (const [alias, name] of Object.entries(aliases)) {\n if (opt[alias] !== undefined) opt[name] ??= opt[alias]\n delete opt[alias]\n }\n if (opt.noChmod === false) opt.chmod ??= true\n delete opt.noChmod\n return opt as T\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type WithAliases } from './dealias.js';
|
|
2
|
+
import type { DeleteOptions, DeleteOptionsSync } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Remove entries from an archive file. An entry is removed if
|
|
5
|
+
* `files` lists its path or one of its parent directories. With
|
|
6
|
+
* `opt.filter`, only if the filter also returns true. With no
|
|
7
|
+
* `files`, each entry that the filter accepts is removed. A listed
|
|
8
|
+
* path that no entry matches is a warning.
|
|
9
|
+
*
|
|
10
|
+
* The other entries are written to a new file next to the archive,
|
|
11
|
+
* with the compression and the mode of the archive. The new file
|
|
12
|
+
* then gets the path of the archive. The archive does not change if
|
|
13
|
+
* the command fails.
|
|
14
|
+
*/
|
|
15
|
+
declare const del: (options: WithAliases<DeleteOptions>, files?: string[]) => Promise<void>;
|
|
16
|
+
/** The sync form of `delete`. */
|
|
17
|
+
export declare const deleteSync: (options: WithAliases<DeleteOptionsSync>, files?: string[]) => void;
|
|
18
|
+
export { del as delete };
|
|
19
|
+
//# sourceMappingURL=delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../src/delete.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAQxD,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAkCpE;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,GAAG,GACP,SAAS,WAAW,CAAC,aAAa,CAAC,EACnC,QAAQ,MAAM,EAAE,KACf,OAAO,CAAC,IAAI,CAoCd,CAAA;AAED,iCAAiC;AACjC,eAAO,MAAM,UAAU,GACrB,SAAS,WAAW,CAAC,iBAAiB,CAAC,EACvC,QAAQ,MAAM,EAAE,KACf,IA0CF,CAAA;AAED,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { gzip } from './codec.js';
|
|
2
|
+
import { create, createSync } from './create.js';
|
|
3
|
+
import { dealias } from './dealias.js';
|
|
4
|
+
import { findCodec, headLength, TarReader, TarReaderSync, } from './entries.js';
|
|
5
|
+
import { filesFilter } from './list.js';
|
|
6
|
+
import { readFile, readFileSync } from './read-file.js';
|
|
7
|
+
const noop = () => { };
|
|
8
|
+
// The codecs to look for, and the filter and the report of the paths
|
|
9
|
+
// to delete.
|
|
10
|
+
const plan = (opt, files) => {
|
|
11
|
+
if (!opt.file)
|
|
12
|
+
throw new TypeError('file is required');
|
|
13
|
+
if (!opt.fs)
|
|
14
|
+
throw new TypeError('the file option needs the fs option');
|
|
15
|
+
const codecs = [...(opt.codecs ?? []), gzip];
|
|
16
|
+
if (files?.length)
|
|
17
|
+
return [codecs, ...filesFilter(files, opt.filter)];
|
|
18
|
+
if (opt.filter)
|
|
19
|
+
return [codecs, opt.filter];
|
|
20
|
+
throw new TypeError('no paths specified to delete');
|
|
21
|
+
};
|
|
22
|
+
// The path of the new archive, until it gets the path of the old one.
|
|
23
|
+
const tmpName = (file) => `${file}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
24
|
+
/**
|
|
25
|
+
* Remove entries from an archive file. An entry is removed if
|
|
26
|
+
* `files` lists its path or one of its parent directories. With
|
|
27
|
+
* `opt.filter`, only if the filter also returns true. With no
|
|
28
|
+
* `files`, each entry that the filter accepts is removed. A listed
|
|
29
|
+
* path that no entry matches is a warning.
|
|
30
|
+
*
|
|
31
|
+
* The other entries are written to a new file next to the archive,
|
|
32
|
+
* with the compression and the mode of the archive. The new file
|
|
33
|
+
* then gets the path of the archive. The archive does not change if
|
|
34
|
+
* the command fails.
|
|
35
|
+
*/
|
|
36
|
+
const del = async (options, files) => {
|
|
37
|
+
const opt = dealias(options);
|
|
38
|
+
const [codecs, remove, report] = plan(opt, files);
|
|
39
|
+
const { fs, file, filter: _, maxReadSize, ...read } = opt;
|
|
40
|
+
const head = new Uint8Array(headLength(codecs));
|
|
41
|
+
let length = 0;
|
|
42
|
+
const handle = await fs.open(file, 'r');
|
|
43
|
+
try {
|
|
44
|
+
for (let n = 1; n > 0 && length < head.length; length += n) {
|
|
45
|
+
n = (await handle.read(head, length, head.length - length, length))
|
|
46
|
+
.bytesRead;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
await handle.close();
|
|
51
|
+
}
|
|
52
|
+
const { mode } = await fs.stat(file);
|
|
53
|
+
const tmp = tmpName(file);
|
|
54
|
+
try {
|
|
55
|
+
await create({
|
|
56
|
+
...read,
|
|
57
|
+
fs,
|
|
58
|
+
file: tmp,
|
|
59
|
+
mode: mode & 0o777,
|
|
60
|
+
compress: findCodec(codecs, head.subarray(0, length), file),
|
|
61
|
+
preservePaths: true,
|
|
62
|
+
filter: (path, entry) => !remove(path, entry),
|
|
63
|
+
}, [new TarReader(readFile(fs, file, maxReadSize), { ...read, file })]);
|
|
64
|
+
report?.(opt);
|
|
65
|
+
await fs.rename(tmp, file);
|
|
66
|
+
}
|
|
67
|
+
catch (er) {
|
|
68
|
+
await fs.unlink(tmp).catch(noop);
|
|
69
|
+
throw er;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/** The sync form of `delete`. */
|
|
73
|
+
export const deleteSync = (options, files) => {
|
|
74
|
+
const opt = dealias(options);
|
|
75
|
+
const [codecs, remove, report] = plan(opt, files);
|
|
76
|
+
const { fs, file, filter: _, maxReadSize, ...read } = opt;
|
|
77
|
+
const head = new Uint8Array(headLength(codecs));
|
|
78
|
+
let length = 0;
|
|
79
|
+
const fd = fs.openSync(file, 'r');
|
|
80
|
+
try {
|
|
81
|
+
for (let n = 1; n > 0 && length < head.length; length += n) {
|
|
82
|
+
n = fs.readSync(fd, head, length, head.length - length, length);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
fs.closeSync(fd);
|
|
87
|
+
}
|
|
88
|
+
const { mode } = fs.statSync(file);
|
|
89
|
+
const tmp = tmpName(file);
|
|
90
|
+
try {
|
|
91
|
+
createSync({
|
|
92
|
+
...read,
|
|
93
|
+
fs,
|
|
94
|
+
file: tmp,
|
|
95
|
+
mode: mode & 0o777,
|
|
96
|
+
compress: findCodec(codecs, head.subarray(0, length), file),
|
|
97
|
+
preservePaths: true,
|
|
98
|
+
filter: (path, entry) => !remove(path, entry),
|
|
99
|
+
}, [
|
|
100
|
+
new TarReaderSync(readFileSync(fs, file, maxReadSize), {
|
|
101
|
+
...read,
|
|
102
|
+
file,
|
|
103
|
+
}),
|
|
104
|
+
]);
|
|
105
|
+
report?.(opt);
|
|
106
|
+
fs.renameSync(tmp, file);
|
|
107
|
+
}
|
|
108
|
+
catch (er) {
|
|
109
|
+
try {
|
|
110
|
+
fs.unlinkSync(tmp);
|
|
111
|
+
}
|
|
112
|
+
catch { }
|
|
113
|
+
throw er;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export { del as delete };
|
|
117
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAA;AACxD,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAA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CAAA;IAClB,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IAClC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,IAAI,CAAC;QACH,UAAU,CACR;YACE,GAAG,IAAI;YACP,EAAE;YACF,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,IAAI,GAAG,KAAK;YAClB,QAAQ,EAAE,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC;YAC3D,aAAa,EAAE,IAAI;YACnB,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,KAAc,CAAC;SACvD,EACD;YACE,IAAI,aAAa,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,EAAE;gBACrD,GAAG,IAAI;gBACP,IAAI;aACL,CAAC;SACH,CACF,CAAA;QACD,MAAM,EAAE,CAAC,GAAG,CAAC,CAAA;QACb,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC1B,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QACpB,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QACV,MAAM,EAAE,CAAA;IACV,CAAC;AACH,CAAC,CAAA;AAED,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,CAAA","sourcesContent":["import { gzip, type Codec } from './codec.js'\nimport { create, createSync } from './create.js'\nimport { dealias, type WithAliases } from './dealias.js'\nimport {\n findCodec,\n headLength,\n TarReader,\n TarReaderSync,\n} from './entries.js'\nimport { filesFilter } from './list.js'\nimport type { DeleteOptions, DeleteOptionsSync } from './options.js'\nimport { readFile, readFileSync } from './read-file.js'\n\nconst noop = () => {}\n\ntype Filter<E> = (path: string, entry: E) => boolean\n\n// The codecs to look for, and the filter and the report of the paths\n// to delete.\nconst plan = <E>(\n opt: {\n file?: string\n fs?: unknown\n codecs?: Codec[]\n filter?: Filter<E>\n },\n files: string[] | undefined,\n): [\n codecs: Codec[],\n remove: Filter<E>,\n report?: ReturnType<typeof filesFilter>[1],\n] => {\n if (!opt.file) throw new TypeError('file is required')\n if (!opt.fs) throw new TypeError('the file option needs the fs option')\n const codecs = [...(opt.codecs ?? []), gzip]\n if (files?.length) return [codecs, ...filesFilter(files, opt.filter)]\n if (opt.filter) return [codecs, opt.filter]\n throw new TypeError('no paths specified to delete')\n}\n\n// The path of the new archive, until it gets the path of the old one.\nconst tmpName = (file: string) =>\n `${file}.${Math.random().toString(36).slice(2)}.tmp`\n\n/**\n * Remove entries from an archive file. An entry is removed if\n * `files` lists its path or one of its parent directories. With\n * `opt.filter`, only if the filter also returns true. With no\n * `files`, each entry that the filter accepts is removed. A listed\n * path that no entry matches is a warning.\n *\n * The other entries are written to a new file next to the archive,\n * with the compression and the mode of the archive. The new file\n * then gets the path of the archive. The archive does not change if\n * the command fails.\n */\nconst del = async (\n options: WithAliases<DeleteOptions>,\n files?: string[],\n): Promise<void> => {\n const opt = dealias<DeleteOptions>(options)\n const [codecs, remove, report] = plan(opt, files)\n const { fs, file, filter: _, maxReadSize, ...read } = opt\n const head = new Uint8Array(headLength(codecs))\n let length = 0\n const handle = await fs.open(file, 'r')\n try {\n for (let n = 1; n > 0 && length < head.length; length += n) {\n n = (await handle.read(head, length, head.length - length, length))\n .bytesRead\n }\n } finally {\n await handle.close()\n }\n const { mode } = await fs.stat(file)\n const tmp = tmpName(file)\n try {\n await create(\n {\n ...read,\n fs,\n file: tmp,\n mode: mode & 0o777,\n compress: findCodec(codecs, head.subarray(0, length), file),\n preservePaths: true,\n filter: (path, entry) => !remove(path, entry as never),\n },\n [new TarReader(readFile(fs, file, maxReadSize), { ...read, file })],\n )\n report?.(opt)\n await fs.rename(tmp, file)\n } catch (er) {\n await fs.unlink(tmp).catch(noop)\n throw er\n }\n}\n\n/** The sync form of `delete`. */\nexport const deleteSync = (\n options: WithAliases<DeleteOptionsSync>,\n files?: string[],\n): void => {\n const opt = dealias<DeleteOptionsSync>(options)\n const [codecs, remove, report] = plan(opt, files)\n const { fs, file, filter: _, maxReadSize, ...read } = opt\n const head = new Uint8Array(headLength(codecs))\n let length = 0\n const fd = fs.openSync(file, 'r')\n try {\n for (let n = 1; n > 0 && length < head.length; length += n) {\n n = fs.readSync(fd, head, length, head.length - length, length)\n }\n } finally {\n fs.closeSync(fd)\n }\n const { mode } = fs.statSync(file)\n const tmp = tmpName(file)\n try {\n createSync(\n {\n ...read,\n fs,\n file: tmp,\n mode: mode & 0o777,\n compress: findCodec(codecs, head.subarray(0, length), file),\n preservePaths: true,\n filter: (path, entry) => !remove(path, entry as never),\n },\n [\n new TarReaderSync(readFileSync(fs, file, maxReadSize), {\n ...read,\n file,\n }),\n ],\n )\n report?.(opt)\n fs.renameSync(tmp, file)\n } catch (er) {\n try {\n fs.unlinkSync(tmp)\n } catch {}\n throw er\n }\n}\n\nexport { del as delete }\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Codec } from './codec.js';
|
|
2
|
+
import { type ReadOptions, type ReadOptionsSync, type TarInput, type TarInputSync } from './options.js';
|
|
3
|
+
import { Parser } from './parser.js';
|
|
4
|
+
import { ReadEntry, ReadEntrySync, type BodySource, type BodySourceSync, type EntryData } from './read-entry.js';
|
|
5
|
+
export declare const headLength: (codecs: Codec[]) => number;
|
|
6
|
+
export declare const findCodec: (codecs: Codec[], head: Uint8Array, file?: string) => Codec | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Gets entries and the parts of their bodies from a `Parser`. The
|
|
9
|
+
* readers use it. It does not read input.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EntryCursor<E extends EntryData> {
|
|
12
|
+
parser: Parser<E>;
|
|
13
|
+
/** The entry that has a body to read now. */
|
|
14
|
+
current?: E;
|
|
15
|
+
/** True after the end of the archive. */
|
|
16
|
+
ended: boolean;
|
|
17
|
+
constructor(parser: Parser<E>);
|
|
18
|
+
/**
|
|
19
|
+
* The next entry that is not ignored. `null` at the end of the
|
|
20
|
+
* archive. `undefined` if the parser needs more input. The rest of
|
|
21
|
+
* the body of the entry before it is skipped.
|
|
22
|
+
*/
|
|
23
|
+
entry(): E | null | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The next part of the body of `entry`. `null` at the end of the
|
|
26
|
+
* body. `undefined` if the parser needs more input.
|
|
27
|
+
*/
|
|
28
|
+
body(entry: E): Uint8Array | null | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads the entries of an archive from async input. It is the
|
|
32
|
+
* iterator that `entries()` returns.
|
|
33
|
+
*
|
|
34
|
+
* Input is read only when the consumer asks for the next entry or
|
|
35
|
+
* for more of a body. `poll()` and `fill()` do the same work as
|
|
36
|
+
* `next()`, with no promise for an entry that is in memory.
|
|
37
|
+
*/
|
|
38
|
+
export declare class TarReader implements AsyncIterableIterator<ReadEntry, undefined>, BodySource {
|
|
39
|
+
#private;
|
|
40
|
+
parser: Parser<ReadEntry>;
|
|
41
|
+
constructor(input: TarInput, opt?: ReadOptions);
|
|
42
|
+
/**
|
|
43
|
+
* The next entry, if it is in memory. `null` at the end of the
|
|
44
|
+
* archive. `undefined` if more input is needed: then await `fill()`
|
|
45
|
+
* and call this again.
|
|
46
|
+
*/
|
|
47
|
+
poll(): ReadEntry | null | undefined;
|
|
48
|
+
readBody(entry: ReadEntry): Uint8Array | null | undefined;
|
|
49
|
+
/** Read one chunk of input, and give it to the parser. */
|
|
50
|
+
fill(): Promise<void>;
|
|
51
|
+
next(): Promise<IteratorResult<ReadEntry, undefined>>;
|
|
52
|
+
/** Stop reading, and release the input. */
|
|
53
|
+
return(): Promise<IteratorResult<ReadEntry, undefined>>;
|
|
54
|
+
[Symbol.asyncIterator](): this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reads the entries of an archive from sync input. It is the
|
|
58
|
+
* iterator that `entriesSync()` returns.
|
|
59
|
+
*/
|
|
60
|
+
export declare class TarReaderSync implements IterableIterator<ReadEntrySync, undefined>, BodySourceSync {
|
|
61
|
+
#private;
|
|
62
|
+
parser: Parser<ReadEntrySync>;
|
|
63
|
+
constructor(input: TarInputSync, opt?: ReadOptionsSync);
|
|
64
|
+
readBody(entry: ReadEntrySync): Uint8Array | null;
|
|
65
|
+
next(): IteratorResult<ReadEntrySync, undefined>;
|
|
66
|
+
/** Stop reading, and release the input. */
|
|
67
|
+
return(): IteratorResult<ReadEntrySync, undefined>;
|
|
68
|
+
[Symbol.iterator](): this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Read the entries of an archive. Gzip input is decompressed.
|
|
72
|
+
*
|
|
73
|
+
* Read the body of an entry before the next entry: when the iterator
|
|
74
|
+
* moves on, the rest of the body is skipped.
|
|
75
|
+
*/
|
|
76
|
+
export declare const entries: (input: TarInput, opt?: ReadOptions) => AsyncIterableIterator<ReadEntry, undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* Read the entries of an archive with no promises. Compressed input
|
|
79
|
+
* needs a codec with a `decompressSync` function in `opt.codecs`.
|
|
80
|
+
*/
|
|
81
|
+
export declare const entriesSync: (input: TarInputSync, opt?: ReadOptionsSync) => IterableIterator<ReadEntrySync, undefined>;
|
|
82
|
+
//# sourceMappingURL=entries.d.ts.map
|