tar 7.0.0 → 7.1.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 +190 -190
- package/dist/commonjs/create.js +4 -7
- package/dist/commonjs/create.js.map +1 -1
- package/dist/commonjs/extract.js +8 -10
- package/dist/commonjs/extract.js.map +1 -1
- package/dist/commonjs/get-write-flag.d.ts.map +1 -1
- package/dist/commonjs/get-write-flag.js +2 -2
- package/dist/commonjs/get-write-flag.js.map +1 -1
- package/dist/commonjs/header.d.ts.map +1 -1
- package/dist/commonjs/header.js +18 -20
- package/dist/commonjs/header.js.map +1 -1
- package/dist/commonjs/large-numbers.d.ts.map +1 -1
- package/dist/commonjs/large-numbers.js.map +1 -1
- package/dist/commonjs/list.js +14 -14
- package/dist/commonjs/list.js.map +1 -1
- package/dist/commonjs/mode-fix.d.ts.map +1 -1
- package/dist/commonjs/mode-fix.js.map +1 -1
- package/dist/commonjs/normalize-windows-path.d.ts.map +1 -1
- package/dist/commonjs/normalize-windows-path.js +2 -2
- package/dist/commonjs/normalize-windows-path.js.map +1 -1
- package/dist/commonjs/pack.d.ts +2 -2
- package/dist/commonjs/pack.d.ts.map +1 -1
- package/dist/commonjs/pack.js.map +1 -1
- package/dist/commonjs/parse.d.ts +5 -2
- package/dist/commonjs/parse.d.ts.map +1 -1
- package/dist/commonjs/parse.js +47 -19
- package/dist/commonjs/parse.js.map +1 -1
- package/dist/commonjs/path-reservations.d.ts.map +1 -1
- package/dist/commonjs/path-reservations.js +7 -6
- package/dist/commonjs/path-reservations.js.map +1 -1
- package/dist/commonjs/pax.js +7 -7
- package/dist/commonjs/pax.js.map +1 -1
- package/dist/commonjs/read-entry.d.ts.map +1 -1
- package/dist/commonjs/read-entry.js +4 -3
- package/dist/commonjs/read-entry.js.map +1 -1
- package/dist/commonjs/replace.js +2 -2
- package/dist/commonjs/replace.js.map +1 -1
- package/dist/commonjs/strip-absolute-path.js +2 -2
- package/dist/commonjs/strip-absolute-path.js.map +1 -1
- package/dist/commonjs/symlink-error.d.ts.map +1 -1
- package/dist/commonjs/symlink-error.js.map +1 -1
- package/dist/commonjs/unpack.d.ts.map +1 -1
- package/dist/commonjs/unpack.js +28 -31
- package/dist/commonjs/unpack.js.map +1 -1
- package/dist/commonjs/update.js +13 -12
- package/dist/commonjs/update.js.map +1 -1
- package/dist/commonjs/warn-method.d.ts +4 -0
- package/dist/commonjs/warn-method.d.ts.map +1 -1
- package/dist/commonjs/warn-method.js.map +1 -1
- package/dist/commonjs/write-entry.d.ts +11 -7
- package/dist/commonjs/write-entry.d.ts.map +1 -1
- package/dist/commonjs/write-entry.js +72 -46
- package/dist/commonjs/write-entry.js.map +1 -1
- package/dist/esm/create.js +4 -7
- package/dist/esm/create.js.map +1 -1
- package/dist/esm/extract.js +8 -10
- package/dist/esm/extract.js.map +1 -1
- package/dist/esm/get-write-flag.d.ts.map +1 -1
- package/dist/esm/get-write-flag.js +2 -2
- package/dist/esm/get-write-flag.js.map +1 -1
- package/dist/esm/header.d.ts.map +1 -1
- package/dist/esm/header.js +18 -20
- package/dist/esm/header.js.map +1 -1
- package/dist/esm/large-numbers.d.ts.map +1 -1
- package/dist/esm/large-numbers.js.map +1 -1
- package/dist/esm/list.js +14 -14
- package/dist/esm/list.js.map +1 -1
- package/dist/esm/mode-fix.d.ts.map +1 -1
- package/dist/esm/mode-fix.js.map +1 -1
- package/dist/esm/normalize-windows-path.d.ts.map +1 -1
- package/dist/esm/normalize-windows-path.js +2 -2
- package/dist/esm/normalize-windows-path.js.map +1 -1
- package/dist/esm/pack.d.ts +2 -2
- package/dist/esm/pack.d.ts.map +1 -1
- package/dist/esm/pack.js.map +1 -1
- package/dist/esm/parse.d.ts +5 -2
- package/dist/esm/parse.d.ts.map +1 -1
- package/dist/esm/parse.js +47 -19
- package/dist/esm/parse.js.map +1 -1
- package/dist/esm/path-reservations.d.ts.map +1 -1
- package/dist/esm/path-reservations.js +7 -6
- package/dist/esm/path-reservations.js.map +1 -1
- package/dist/esm/pax.js +7 -7
- package/dist/esm/pax.js.map +1 -1
- package/dist/esm/read-entry.d.ts.map +1 -1
- package/dist/esm/read-entry.js +4 -3
- package/dist/esm/read-entry.js.map +1 -1
- package/dist/esm/replace.js +2 -2
- package/dist/esm/replace.js.map +1 -1
- package/dist/esm/strip-absolute-path.js +2 -2
- package/dist/esm/strip-absolute-path.js.map +1 -1
- package/dist/esm/symlink-error.d.ts.map +1 -1
- package/dist/esm/symlink-error.js.map +1 -1
- package/dist/esm/unpack.d.ts.map +1 -1
- package/dist/esm/unpack.js +28 -31
- package/dist/esm/unpack.js.map +1 -1
- package/dist/esm/update.js +13 -12
- package/dist/esm/update.js.map +1 -1
- package/dist/esm/warn-method.d.ts +4 -0
- package/dist/esm/warn-method.d.ts.map +1 -1
- package/dist/esm/warn-method.js.map +1 -1
- package/dist/esm/write-entry.d.ts +11 -7
- package/dist/esm/write-entry.d.ts.map +1 -1
- package/dist/esm/write-entry.js +73 -47
- package/dist/esm/write-entry.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -4,29 +4,29 @@ Fast and full-featured Tar for Node.js
|
|
|
4
4
|
|
|
5
5
|
The API is designed to mimic the behavior of `tar(1)` on unix systems.
|
|
6
6
|
If you are familiar with how tar works, most of this will hopefully be
|
|
7
|
-
straightforward for you.
|
|
7
|
+
straightforward for you. If not, then hopefully this module can teach
|
|
8
8
|
you useful unix skills that may come in handy someday :)
|
|
9
9
|
|
|
10
10
|
## Background
|
|
11
11
|
|
|
12
12
|
A "tar file" or "tarball" is an archive of file system entries
|
|
13
|
-
(directories, files, links, etc.)
|
|
13
|
+
(directories, files, links, etc.) The name comes from "tape archive".
|
|
14
14
|
If you run `man tar` on almost any Unix command line, you'll learn
|
|
15
15
|
quite a bit about what it can do, and its history.
|
|
16
16
|
|
|
17
17
|
Tar has 5 main top-level commands:
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
- `c` Create an archive
|
|
20
|
+
- `r` Replace entries within an archive
|
|
21
|
+
- `u` Update entries within an archive (ie, replace if they're newer)
|
|
22
|
+
- `t` List out the contents of an archive
|
|
23
|
+
- `x` Extract an archive to disk
|
|
24
24
|
|
|
25
25
|
The other flags and options modify how this top level function works.
|
|
26
26
|
|
|
27
27
|
## High-Level API
|
|
28
28
|
|
|
29
|
-
These 5 functions are the high-level API.
|
|
29
|
+
These 5 functions are the high-level API. All of them have a
|
|
30
30
|
single-character name (for unix nerds familiar with `tar(1)`) as well
|
|
31
31
|
as a long name (for everyone else).
|
|
32
32
|
|
|
@@ -35,7 +35,7 @@ of which are optional and may be omitted.
|
|
|
35
35
|
|
|
36
36
|
1. `options` - An optional object specifying various options
|
|
37
37
|
2. `paths` - An array of paths to add or extract
|
|
38
|
-
3. `callback` - Called when the command is completed, if async.
|
|
38
|
+
3. `callback` - Called when the command is completed, if async. (If
|
|
39
39
|
sync or no file specified, providing a callback throws a
|
|
40
40
|
`TypeError`.)
|
|
41
41
|
|
|
@@ -43,45 +43,45 @@ If the command is sync (ie, if `options.sync=true`), then the
|
|
|
43
43
|
callback is not allowed, since the action will be completed immediately.
|
|
44
44
|
|
|
45
45
|
If a `file` argument is specified, and the command is async, then a
|
|
46
|
-
`Promise` is returned.
|
|
46
|
+
`Promise` is returned. In this case, if async, a callback may be
|
|
47
47
|
provided which is called when the command is completed.
|
|
48
48
|
|
|
49
|
-
If a `file` option is not specified, then a stream is returned.
|
|
50
|
-
`create`, this is a readable stream of the generated archive.
|
|
49
|
+
If a `file` option is not specified, then a stream is returned. For
|
|
50
|
+
`create`, this is a readable stream of the generated archive. For
|
|
51
51
|
`list` and `extract` this is a writable stream that an archive should
|
|
52
|
-
be written into.
|
|
52
|
+
be written into. If a file is not specified, then a callback is not
|
|
53
53
|
allowed, because you're already getting a stream to work with.
|
|
54
54
|
|
|
55
55
|
`replace` and `update` only work on existing archives, and so require
|
|
56
56
|
a `file` argument.
|
|
57
57
|
|
|
58
58
|
Sync commands without a file argument return a stream that acts on its
|
|
59
|
-
input immediately in the same tick.
|
|
59
|
+
input immediately in the same tick. For readable streams, this means
|
|
60
60
|
that all of the data is immediately available by calling
|
|
61
|
-
`stream.read()`.
|
|
61
|
+
`stream.read()`. For writable streams, it will be acted upon as soon
|
|
62
62
|
as it is provided, but this can be at any time.
|
|
63
63
|
|
|
64
64
|
### Warnings and Errors
|
|
65
65
|
|
|
66
66
|
Tar emits warnings and errors for recoverable and unrecoverable situations,
|
|
67
|
-
respectively.
|
|
67
|
+
respectively. In many cases, a warning only affects a single entry in an
|
|
68
68
|
archive, or is simply informing you that it's modifying an entry to comply
|
|
69
69
|
with the settings provided.
|
|
70
70
|
|
|
71
71
|
Unrecoverable warnings will always raise an error (ie, emit `'error'` on
|
|
72
72
|
streaming actions, throw for non-streaming sync actions, reject the
|
|
73
73
|
returned Promise for non-streaming async operations, or call a provided
|
|
74
|
-
callback with an `Error` as the first argument).
|
|
74
|
+
callback with an `Error` as the first argument). Recoverable errors will
|
|
75
75
|
raise an error only if `strict: true` is set in the options.
|
|
76
76
|
|
|
77
77
|
Respond to (recoverable) warnings by listening to the `warn` event.
|
|
78
78
|
Handlers receive 3 arguments:
|
|
79
79
|
|
|
80
|
-
- `code` String.
|
|
80
|
+
- `code` String. One of the error codes below. This may not match
|
|
81
81
|
`data.code`, which preserves the original error code from fs and zlib.
|
|
82
|
-
- `message` String.
|
|
83
|
-
- `data` Metadata about the error.
|
|
84
|
-
fs and zlib.
|
|
82
|
+
- `message` String. More details about the error.
|
|
83
|
+
- `data` Metadata about the error. An `Error` object for errors raised by
|
|
84
|
+
fs and zlib. All fields are attached to errors raisd by tar. Typically
|
|
85
85
|
contains the following fields, as relevant:
|
|
86
86
|
- `tarCode` The tar error code.
|
|
87
87
|
- `code` Either the tar error code, or the error code set by the
|
|
@@ -92,17 +92,18 @@ Handlers receive 3 arguments:
|
|
|
92
92
|
`TAR_ENTRY_INVALID`, and `TAR_ENTRY_ERROR` warnings.
|
|
93
93
|
- `header` The header object (if it could be created, and the entry could
|
|
94
94
|
not be created) for `TAR_ENTRY_INFO` and `TAR_ENTRY_INVALID` warnings.
|
|
95
|
-
- `recoverable` Boolean.
|
|
95
|
+
- `recoverable` Boolean. If `false`, then the warning will emit an
|
|
96
96
|
`error`, even in non-strict mode.
|
|
97
97
|
|
|
98
98
|
#### Error Codes
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
modified, but otherwise processed normally.
|
|
100
|
+
- `TAR_ENTRY_INFO` An informative error indicating that an entry is being
|
|
101
|
+
modified, but otherwise processed normally. For example, removing `/` or
|
|
102
102
|
`C:\` from absolute paths if `preservePaths` is not set.
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
archive entry, and will be skipped.
|
|
104
|
+
- `TAR_ENTRY_INVALID` An indication that a given entry is not a valid tar
|
|
105
|
+
archive entry, and will be skipped. This occurs when:
|
|
106
|
+
|
|
106
107
|
- a checksum fails,
|
|
107
108
|
- a `linkpath` is missing for a link type, or
|
|
108
109
|
- a `linkpath` is provided for a non-link type.
|
|
@@ -111,9 +112,10 @@ Handlers receive 3 arguments:
|
|
|
111
112
|
then the archive is presumed to be unrecoverably broken, and
|
|
112
113
|
`TAR_BAD_ARCHIVE` will be raised.
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
encountered an error which prevented it from being unpacked.
|
|
115
|
+
- `TAR_ENTRY_ERROR` The entry appears to be a valid tar archive entry, but
|
|
116
|
+
encountered an error which prevented it from being unpacked. This occurs
|
|
116
117
|
when:
|
|
118
|
+
|
|
117
119
|
- an unrecoverable fs error happens during unpacking,
|
|
118
120
|
- an entry is trying to extract into an excessively deep
|
|
119
121
|
location (by default, limited to 1024 subfolders),
|
|
@@ -121,15 +123,15 @@ Handlers receive 3 arguments:
|
|
|
121
123
|
- an entry is extracting through a symbolic link, when `preservePaths` is
|
|
122
124
|
not set.
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
- `TAR_ENTRY_UNSUPPORTED` An indication that a given entry is
|
|
125
127
|
a valid archive entry, but of a type that is unsupported, and so will be
|
|
126
128
|
skipped in archive creation or extracting.
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
- `TAR_ABORT` When parsing gzipped-encoded archives, the parser will
|
|
129
131
|
abort the parse process raise a warning for any zlib errors encountered.
|
|
130
132
|
Aborts are considered unrecoverable for both parsing and unpacking.
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
- `TAR_BAD_ARCHIVE` The archive file is totally hosed. This can happen for
|
|
133
135
|
a number of reasons, and always occurs at the end of a parse or extract:
|
|
134
136
|
|
|
135
137
|
- An entry body was truncated before seeing the full number of bytes.
|
|
@@ -138,7 +140,7 @@ Handlers receive 3 arguments:
|
|
|
138
140
|
parse.
|
|
139
141
|
|
|
140
142
|
`TAR_BAD_ARCHIVE` is considered informative for parse operations, but
|
|
141
|
-
unrecoverable for extraction.
|
|
143
|
+
unrecoverable for extraction. Note that, if encountered at the end of an
|
|
142
144
|
extraction, tar WILL still have extracted as much it could from the
|
|
143
145
|
archive, so there may be some garbage files to clean up.
|
|
144
146
|
|
|
@@ -154,7 +156,7 @@ to see how tar is handling the issue.
|
|
|
154
156
|
### Examples
|
|
155
157
|
|
|
156
158
|
The API mimics the `tar(1)` command line functionality, with aliases
|
|
157
|
-
for more human-readable option and function names.
|
|
159
|
+
for more human-readable option and function names. The goal is that
|
|
158
160
|
if you know how to use `tar(1)` in Unix, then you know how to use
|
|
159
161
|
`import('tar')` in JavaScript.
|
|
160
162
|
|
|
@@ -202,8 +204,8 @@ To replicate `cat my-tarball.tgz | tar x -C some-dir --strip=1`:
|
|
|
202
204
|
fs.createReadStream('my-tarball.tgz').pipe(
|
|
203
205
|
tar.x({
|
|
204
206
|
strip: 1,
|
|
205
|
-
C: 'some-dir' // alias for cwd:'some-dir', also ok
|
|
206
|
-
})
|
|
207
|
+
C: 'some-dir', // alias for cwd:'some-dir', also ok
|
|
208
|
+
}),
|
|
207
209
|
)
|
|
208
210
|
```
|
|
209
211
|
|
|
@@ -237,10 +239,10 @@ fs.createReadStream('my-tarball.tgz')
|
|
|
237
239
|
.on('entry', entry => { .. do whatever with it .. })
|
|
238
240
|
```
|
|
239
241
|
|
|
240
|
-
To do anything synchronous, add `sync: true` to the options.
|
|
242
|
+
To do anything synchronous, add `sync: true` to the options. Note
|
|
241
243
|
that sync functions don't take a callback and don't return a promise.
|
|
242
|
-
When the function returns, it's already done.
|
|
243
|
-
file argument return a sync stream, which flushes immediately.
|
|
244
|
+
When the function returns, it's already done. Sync methods without a
|
|
245
|
+
file argument return a sync stream, which flushes immediately. But,
|
|
244
246
|
of course, it still won't be done until you `.end()` it.
|
|
245
247
|
|
|
246
248
|
```js
|
|
@@ -258,7 +260,7 @@ const getEntryFilenamesSync = tarballFilename => {
|
|
|
258
260
|
To filter entries, add `filter: <function>` to the options.
|
|
259
261
|
Tar-creating methods call the filter with `filter(path, stat)`.
|
|
260
262
|
Tar-reading methods (including extraction) call the filter with
|
|
261
|
-
`filter(path, entry)`.
|
|
263
|
+
`filter(path, entry)`. The filter is called in the `this`-context of
|
|
262
264
|
the `Pack` or `Unpack` stream object.
|
|
263
265
|
|
|
264
266
|
The arguments list to `tar t` and `tar x` specify a list of filenames
|
|
@@ -282,49 +284,49 @@ the low-level API that they are built on.
|
|
|
282
284
|
|
|
283
285
|
Create a tarball archive.
|
|
284
286
|
|
|
285
|
-
The `fileList` is an array of paths to add to the tarball.
|
|
287
|
+
The `fileList` is an array of paths to add to the tarball. Adding a
|
|
286
288
|
directory also adds its children recursively.
|
|
287
289
|
|
|
288
290
|
An entry in `fileList` that starts with an `@` symbol is a tar archive
|
|
289
|
-
whose entries will be added.
|
|
291
|
+
whose entries will be added. To add a file that starts with `@`,
|
|
290
292
|
prepend it with `./`.
|
|
291
293
|
|
|
292
294
|
The following options are supported:
|
|
293
295
|
|
|
294
|
-
- `file` Write the tarball archive to the specified filename.
|
|
296
|
+
- `file` Write the tarball archive to the specified filename. If this
|
|
295
297
|
is specified, then the callback will be fired when the file has been
|
|
296
298
|
written, and a promise will be returned that resolves when the file
|
|
297
|
-
is written.
|
|
299
|
+
is written. If a filename is not specified, then a Readable Stream
|
|
298
300
|
will be returned which will emit the file data. [Alias: `f`]
|
|
299
|
-
- `sync` Act synchronously.
|
|
300
|
-
will be fully written after the call to `tar.c`.
|
|
301
|
+
- `sync` Act synchronously. If this is set, then any provided file
|
|
302
|
+
will be fully written after the call to `tar.c`. If this is set,
|
|
301
303
|
and a file is not provided, then the resulting stream will already
|
|
302
304
|
have the data ready to `read` or `emit('data')` as soon as you
|
|
303
305
|
request it.
|
|
304
306
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
305
|
-
any warnings encountered.
|
|
306
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
307
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
308
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
307
309
|
- `cwd` The current working directory for creating the archive.
|
|
308
|
-
Defaults to `process.cwd()`.
|
|
310
|
+
Defaults to `process.cwd()`. [Alias: `C`]
|
|
309
311
|
- `prefix` A path portion to prefix onto the entries in the archive.
|
|
310
312
|
- `gzip` Set to any truthy value to create a gzipped archive, or an
|
|
311
313
|
object with settings for `zlib.Gzip()` [Alias: `z`]
|
|
312
314
|
- `filter` A function that gets called with `(path, stat)` for each
|
|
313
|
-
entry being added.
|
|
315
|
+
entry being added. Return `true` to add the entry to the archive,
|
|
314
316
|
or `false` to omit it.
|
|
315
317
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
316
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
318
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
317
319
|
that `mtime` is still included, because this is necessary for other
|
|
318
|
-
time-based operations.
|
|
320
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
319
321
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
320
|
-
- `preservePaths` Allow absolute paths.
|
|
322
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
321
323
|
from absolute paths. [Alias: `P`]
|
|
322
324
|
- `mode` The mode to set on the created file archive
|
|
323
325
|
- `noDirRecurse` Do not recursively archive the contents of
|
|
324
326
|
directories. [Alias: `n`]
|
|
325
|
-
- `follow` Set to true to pack the targets of symbolic links.
|
|
327
|
+
- `follow` Set to true to pack the targets of symbolic links. Without
|
|
326
328
|
this option, symbolic links are archived as such. [Alias: `L`, `h`]
|
|
327
|
-
- `noPax` Suppress pax extended headers.
|
|
329
|
+
- `noPax` Suppress pax extended headers. Note that this means that
|
|
328
330
|
long paths and linkpaths will be truncated, and large or negative
|
|
329
331
|
numeric values may be interpreted incorrectly.
|
|
330
332
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
@@ -332,7 +334,7 @@ The following options are supported:
|
|
|
332
334
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
333
335
|
[Alias: `m`, `no-mtime`]
|
|
334
336
|
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
335
|
-
everything added to the archive.
|
|
337
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
336
338
|
|
|
337
339
|
The following options are mostly internal, but can be modified in some
|
|
338
340
|
advanced use cases, such as re-using caches between runs.
|
|
@@ -350,7 +352,7 @@ advanced use cases, such as re-using caches between runs.
|
|
|
350
352
|
|
|
351
353
|
Extract a tarball archive.
|
|
352
354
|
|
|
353
|
-
The `fileList` is an array of paths to extract from the tarball.
|
|
355
|
+
The `fileList` is an array of paths to extract from the tarball. If
|
|
354
356
|
no paths are provided, then all the entries are extracted.
|
|
355
357
|
|
|
356
358
|
If the archive is gzipped, then tar will detect this and unzip it.
|
|
@@ -360,77 +362,77 @@ writable, readable, and listable by their owner, to avoid cases where
|
|
|
360
362
|
a directory prevents extraction of child entries by virtue of its
|
|
361
363
|
mode.
|
|
362
364
|
|
|
363
|
-
Most extraction errors will cause a `warn` event to be emitted.
|
|
365
|
+
Most extraction errors will cause a `warn` event to be emitted. If
|
|
364
366
|
the `cwd` is missing, or not a directory, then the extraction will
|
|
365
367
|
fail completely.
|
|
366
368
|
|
|
367
369
|
The following options are supported:
|
|
368
370
|
|
|
369
|
-
- `cwd` Extract files relative to the specified directory.
|
|
370
|
-
to `process.cwd()`.
|
|
371
|
+
- `cwd` Extract files relative to the specified directory. Defaults
|
|
372
|
+
to `process.cwd()`. If provided, this must exist and must be a
|
|
371
373
|
directory. [Alias: `C`]
|
|
372
|
-
- `file` The archive file to extract.
|
|
374
|
+
- `file` The archive file to extract. If not specified, then a
|
|
373
375
|
Writable stream is returned where the archive data should be
|
|
374
376
|
written. [Alias: `f`]
|
|
375
377
|
- `sync` Create files and directories synchronously.
|
|
376
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
378
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
377
379
|
- `filter` A function that gets called with `(path, entry)` for each
|
|
378
|
-
entry being unpacked.
|
|
380
|
+
entry being unpacked. Return `true` to unpack the entry from the
|
|
379
381
|
archive, or `false` to skip it.
|
|
380
382
|
- `newer` Set to true to keep the existing file on disk if it's newer
|
|
381
383
|
than the file in the archive. [Alias: `keep-newer`,
|
|
382
384
|
`keep-newer-files`]
|
|
383
|
-
- `keep` Do not overwrite existing files.
|
|
385
|
+
- `keep` Do not overwrite existing files. In particular, if a file
|
|
384
386
|
appears more than once in an archive, later copies will not
|
|
385
387
|
overwrite earlier copies. [Alias: `k`, `keep-existing`]
|
|
386
388
|
- `preservePaths` Allow absolute paths, paths containing `..`, and
|
|
387
|
-
extracting through symbolic links.
|
|
389
|
+
extracting through symbolic links. By default, `/` is stripped from
|
|
388
390
|
absolute paths, `..` paths are not extracted, and any file whose
|
|
389
391
|
location would be modified by a symbolic link is not extracted.
|
|
390
392
|
[Alias: `P`]
|
|
391
|
-
- `unlink` Unlink files before creating them.
|
|
393
|
+
- `unlink` Unlink files before creating them. Without this option,
|
|
392
394
|
tar overwrites existing files, which preserves existing hardlinks.
|
|
393
395
|
With this option, existing hardlinks will be broken, as will any
|
|
394
396
|
symlink that would affect the location of an extracted file. [Alias:
|
|
395
397
|
`U`]
|
|
396
398
|
- `strip` Remove the specified number of leading path elements.
|
|
397
|
-
Pathnames with fewer elements will be silently skipped.
|
|
399
|
+
Pathnames with fewer elements will be silently skipped. Note that
|
|
398
400
|
the pathname is edited after applying the filter, but before
|
|
399
401
|
security checks. [Alias: `strip-components`, `stripComponents`]
|
|
400
402
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
401
|
-
any warnings encountered.
|
|
403
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
402
404
|
- `preserveOwner` If true, tar will set the `uid` and `gid` of
|
|
403
405
|
extracted entries to the `uid` and `gid` fields in the archive.
|
|
404
|
-
This defaults to true when run as root, and false otherwise.
|
|
406
|
+
This defaults to true when run as root, and false otherwise. If
|
|
405
407
|
false, then files and directories will be set with the owner and
|
|
406
|
-
group of the user running the process.
|
|
408
|
+
group of the user running the process. This is similar to `-p` in
|
|
407
409
|
`tar(1)`, but ACLs and other system-specific data is never unpacked
|
|
408
410
|
in this implementation, and modes are set by default already.
|
|
409
411
|
[Alias: `p`]
|
|
410
412
|
- `uid` Set to a number to force ownership of all extracted files and
|
|
411
413
|
folders, and all implicitly created directories, to be owned by the
|
|
412
414
|
specified user id, regardless of the `uid` field in the archive.
|
|
413
|
-
Cannot be used along with `preserveOwner`.
|
|
415
|
+
Cannot be used along with `preserveOwner`. Requires also setting a
|
|
414
416
|
`gid` option.
|
|
415
417
|
- `gid` Set to a number to force ownership of all extracted files and
|
|
416
418
|
folders, and all implicitly created directories, to be owned by the
|
|
417
419
|
specified group id, regardless of the `gid` field in the archive.
|
|
418
|
-
Cannot be used along with `preserveOwner`.
|
|
420
|
+
Cannot be used along with `preserveOwner`. Requires also setting a
|
|
419
421
|
`uid` option.
|
|
420
422
|
- `noMtime` Set to true to omit writing `mtime` value for extracted
|
|
421
423
|
entries. [Alias: `m`, `no-mtime`]
|
|
422
424
|
- `transform` Provide a function that takes an `entry` object, and
|
|
423
|
-
returns a stream, or any falsey value.
|
|
425
|
+
returns a stream, or any falsey value. If a stream is provided,
|
|
424
426
|
then that stream's data will be written instead of the contents of
|
|
425
|
-
the archive entry.
|
|
426
|
-
written to disk as normal.
|
|
427
|
+
the archive entry. If a falsey value is provided, then the entry is
|
|
428
|
+
written to disk as normal. (To exclude items from extraction, use
|
|
427
429
|
the `filter` option described above.)
|
|
428
430
|
- `onentry` A function that gets called with `(entry)` for each entry
|
|
429
431
|
that passes the filter.
|
|
430
432
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
431
|
-
any warnings encountered.
|
|
433
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
432
434
|
- `chmod` Set to true to call `fs.chmod()` to ensure that the
|
|
433
|
-
extracted file matches the entry mode.
|
|
435
|
+
extracted file matches the entry mode. This may necessitate a
|
|
434
436
|
call to the deprecated and thread-unsafe `process.umask()`
|
|
435
437
|
method to determine the default umask value, unless a
|
|
436
438
|
`processUmask` options is also provided. Otherwise tar will
|
|
@@ -453,7 +455,7 @@ advanced use cases, such as re-using caches between runs.
|
|
|
453
455
|
- `fmode` Default mode for files
|
|
454
456
|
- `dirCache` A Map object of which directories exist.
|
|
455
457
|
- `maxMetaEntrySize` The maximum size of meta entries that is
|
|
456
|
-
supported.
|
|
458
|
+
supported. Defaults to 1 MB.
|
|
457
459
|
|
|
458
460
|
Note that using an asynchronous stream type with the `transform`
|
|
459
461
|
option will cause undefined behavior in sync extractions.
|
|
@@ -464,88 +466,88 @@ use case.
|
|
|
464
466
|
|
|
465
467
|
List the contents of a tarball archive.
|
|
466
468
|
|
|
467
|
-
The `fileList` is an array of paths to list from the tarball.
|
|
469
|
+
The `fileList` is an array of paths to list from the tarball. If
|
|
468
470
|
no paths are provided, then all the entries are listed.
|
|
469
471
|
|
|
470
472
|
If the archive is gzipped, then tar will detect this and unzip it.
|
|
471
473
|
|
|
472
474
|
If the `file` option is _not_ provided, then returns an event emitter that
|
|
473
|
-
emits `entry` events with `tar.ReadEntry` objects.
|
|
474
|
-
emit `'data'` or `'end'` events.
|
|
475
|
+
emits `entry` events with `tar.ReadEntry` objects. However, they don't
|
|
476
|
+
emit `'data'` or `'end'` events. (If you want to get actual readable
|
|
475
477
|
entries, use the `tar.Parse` class instead.)
|
|
476
478
|
|
|
477
479
|
If a `file` option _is_ provided, then the return value will be a promise
|
|
478
480
|
that resolves when the file has been fully traversed in async mode, or
|
|
479
|
-
`undefined` if `sync: true` is set.
|
|
481
|
+
`undefined` if `sync: true` is set. Thus, you _must_ specify an `onentry`
|
|
480
482
|
method in order to do anything useful with the data it parses.
|
|
481
483
|
|
|
482
484
|
The following options are supported:
|
|
483
485
|
|
|
484
|
-
- `file` The archive file to list.
|
|
486
|
+
- `file` The archive file to list. If not specified, then a
|
|
485
487
|
Writable stream is returned where the archive data should be
|
|
486
488
|
written. [Alias: `f`]
|
|
487
|
-
- `sync` Read the specified file synchronously.
|
|
489
|
+
- `sync` Read the specified file synchronously. (This has no effect
|
|
488
490
|
when a file option isn't specified, because entries are emitted as
|
|
489
491
|
fast as they are parsed from the stream anyway.)
|
|
490
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
492
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
491
493
|
- `filter` A function that gets called with `(path, entry)` for each
|
|
492
|
-
entry being listed.
|
|
494
|
+
entry being listed. Return `true` to emit the entry from the
|
|
493
495
|
archive, or `false` to skip it.
|
|
494
496
|
- `onentry` A function that gets called with `(entry)` for each entry
|
|
495
|
-
that passes the filter.
|
|
497
|
+
that passes the filter. This is important for when `file` is set,
|
|
496
498
|
because there is no other way to do anything useful with this method.
|
|
497
499
|
- `maxReadSize` The maximum buffer size for `fs.read()` operations.
|
|
498
500
|
Defaults to 16 MB.
|
|
499
501
|
- `noResume` By default, `entry` streams are resumed immediately after
|
|
500
|
-
the call to `onentry`.
|
|
501
|
-
behavior.
|
|
502
|
+
the call to `onentry`. Set `noResume: true` to suppress this
|
|
503
|
+
behavior. Note that by opting into this, the stream will never
|
|
502
504
|
complete until the entry data is consumed.
|
|
503
505
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
504
|
-
any warnings encountered.
|
|
506
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
505
507
|
|
|
506
508
|
### tar.u(options, fileList, callback) [alias: tar.update]
|
|
507
509
|
|
|
508
510
|
Add files to an archive if they are newer than the entry already in
|
|
509
511
|
the tarball archive.
|
|
510
512
|
|
|
511
|
-
The `fileList` is an array of paths to add to the tarball.
|
|
513
|
+
The `fileList` is an array of paths to add to the tarball. Adding a
|
|
512
514
|
directory also adds its children recursively.
|
|
513
515
|
|
|
514
516
|
An entry in `fileList` that starts with an `@` symbol is a tar archive
|
|
515
|
-
whose entries will be added.
|
|
517
|
+
whose entries will be added. To add a file that starts with `@`,
|
|
516
518
|
prepend it with `./`.
|
|
517
519
|
|
|
518
520
|
The following options are supported:
|
|
519
521
|
|
|
520
522
|
- `file` Required. Write the tarball archive to the specified
|
|
521
523
|
filename. [Alias: `f`]
|
|
522
|
-
- `sync` Act synchronously.
|
|
524
|
+
- `sync` Act synchronously. If this is set, then any provided file
|
|
523
525
|
will be fully written after the call to `tar.c`.
|
|
524
526
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
525
|
-
any warnings encountered.
|
|
526
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
527
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
528
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
527
529
|
- `cwd` The current working directory for adding entries to the
|
|
528
|
-
archive.
|
|
530
|
+
archive. Defaults to `process.cwd()`. [Alias: `C`]
|
|
529
531
|
- `prefix` A path portion to prefix onto the entries in the archive.
|
|
530
532
|
- `gzip` Set to any truthy value to create a gzipped archive, or an
|
|
531
533
|
object with settings for `zlib.Gzip()` [Alias: `z`]
|
|
532
534
|
- `filter` A function that gets called with `(path, stat)` for each
|
|
533
|
-
entry being added.
|
|
535
|
+
entry being added. Return `true` to add the entry to the archive,
|
|
534
536
|
or `false` to omit it.
|
|
535
537
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
536
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
538
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
537
539
|
that `mtime` is still included, because this is necessary for other
|
|
538
|
-
time-based operations.
|
|
540
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
539
541
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
540
|
-
- `preservePaths` Allow absolute paths.
|
|
542
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
541
543
|
from absolute paths. [Alias: `P`]
|
|
542
544
|
- `maxReadSize` The maximum buffer size for `fs.read()` operations.
|
|
543
545
|
Defaults to 16 MB.
|
|
544
546
|
- `noDirRecurse` Do not recursively archive the contents of
|
|
545
547
|
directories. [Alias: `n`]
|
|
546
|
-
- `follow` Set to true to pack the targets of symbolic links.
|
|
548
|
+
- `follow` Set to true to pack the targets of symbolic links. Without
|
|
547
549
|
this option, symbolic links are archived as such. [Alias: `L`, `h`]
|
|
548
|
-
- `noPax` Suppress pax extended headers.
|
|
550
|
+
- `noPax` Suppress pax extended headers. Note that this means that
|
|
549
551
|
long paths and linkpaths will be truncated, and large or negative
|
|
550
552
|
numeric values may be interpreted incorrectly.
|
|
551
553
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
@@ -553,51 +555,51 @@ The following options are supported:
|
|
|
553
555
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
554
556
|
[Alias: `m`, `no-mtime`]
|
|
555
557
|
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
556
|
-
everything added to the archive.
|
|
558
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
557
559
|
|
|
558
560
|
### tar.r(options, fileList, callback) [alias: tar.replace]
|
|
559
561
|
|
|
560
|
-
Add files to an existing archive.
|
|
562
|
+
Add files to an existing archive. Because later entries override
|
|
561
563
|
earlier entries, this effectively replaces any existing entries.
|
|
562
564
|
|
|
563
|
-
The `fileList` is an array of paths to add to the tarball.
|
|
565
|
+
The `fileList` is an array of paths to add to the tarball. Adding a
|
|
564
566
|
directory also adds its children recursively.
|
|
565
567
|
|
|
566
568
|
An entry in `fileList` that starts with an `@` symbol is a tar archive
|
|
567
|
-
whose entries will be added.
|
|
569
|
+
whose entries will be added. To add a file that starts with `@`,
|
|
568
570
|
prepend it with `./`.
|
|
569
571
|
|
|
570
572
|
The following options are supported:
|
|
571
573
|
|
|
572
574
|
- `file` Required. Write the tarball archive to the specified
|
|
573
575
|
filename. [Alias: `f`]
|
|
574
|
-
- `sync` Act synchronously.
|
|
576
|
+
- `sync` Act synchronously. If this is set, then any provided file
|
|
575
577
|
will be fully written after the call to `tar.c`.
|
|
576
578
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
577
|
-
any warnings encountered.
|
|
578
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
579
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
580
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
579
581
|
- `cwd` The current working directory for adding entries to the
|
|
580
|
-
archive.
|
|
582
|
+
archive. Defaults to `process.cwd()`. [Alias: `C`]
|
|
581
583
|
- `prefix` A path portion to prefix onto the entries in the archive.
|
|
582
584
|
- `gzip` Set to any truthy value to create a gzipped archive, or an
|
|
583
585
|
object with settings for `zlib.Gzip()` [Alias: `z`]
|
|
584
586
|
- `filter` A function that gets called with `(path, stat)` for each
|
|
585
|
-
entry being added.
|
|
587
|
+
entry being added. Return `true` to add the entry to the archive,
|
|
586
588
|
or `false` to omit it.
|
|
587
589
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
588
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
590
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
589
591
|
that `mtime` is still included, because this is necessary for other
|
|
590
|
-
time-based operations.
|
|
592
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
591
593
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
592
|
-
- `preservePaths` Allow absolute paths.
|
|
594
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
593
595
|
from absolute paths. [Alias: `P`]
|
|
594
596
|
- `maxReadSize` The maximum buffer size for `fs.read()` operations.
|
|
595
597
|
Defaults to 16 MB.
|
|
596
598
|
- `noDirRecurse` Do not recursively archive the contents of
|
|
597
599
|
directories. [Alias: `n`]
|
|
598
|
-
- `follow` Set to true to pack the targets of symbolic links.
|
|
600
|
+
- `follow` Set to true to pack the targets of symbolic links. Without
|
|
599
601
|
this option, symbolic links are archived as such. [Alias: `L`, `h`]
|
|
600
|
-
- `noPax` Suppress pax extended headers.
|
|
602
|
+
- `noPax` Suppress pax extended headers. Note that this means that
|
|
601
603
|
long paths and linkpaths will be truncated, and large or negative
|
|
602
604
|
numeric values may be interpreted incorrectly.
|
|
603
605
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
@@ -605,8 +607,7 @@ The following options are supported:
|
|
|
605
607
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
606
608
|
[Alias: `m`, `no-mtime`]
|
|
607
609
|
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
608
|
-
everything added to the archive.
|
|
609
|
-
|
|
610
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
610
611
|
|
|
611
612
|
## Low-Level API
|
|
612
613
|
|
|
@@ -614,7 +615,7 @@ The following options are supported:
|
|
|
614
615
|
|
|
615
616
|
A readable tar stream.
|
|
616
617
|
|
|
617
|
-
Has all the standard readable stream interface stuff.
|
|
618
|
+
Has all the standard readable stream interface stuff. `'data'` and
|
|
618
619
|
`'end'` events, `read()` method, `pause()` and `resume()`, etc.
|
|
619
620
|
|
|
620
621
|
#### constructor(options)
|
|
@@ -622,22 +623,22 @@ Has all the standard readable stream interface stuff. `'data'` and
|
|
|
622
623
|
The following options are supported:
|
|
623
624
|
|
|
624
625
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
625
|
-
any warnings encountered.
|
|
626
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
626
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
627
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
627
628
|
- `cwd` The current working directory for creating the archive.
|
|
628
629
|
Defaults to `process.cwd()`.
|
|
629
630
|
- `prefix` A path portion to prefix onto the entries in the archive.
|
|
630
631
|
- `gzip` Set to any truthy value to create a gzipped archive, or an
|
|
631
632
|
object with settings for `zlib.Gzip()`
|
|
632
633
|
- `filter` A function that gets called with `(path, stat)` for each
|
|
633
|
-
entry being added.
|
|
634
|
+
entry being added. Return `true` to add the entry to the archive,
|
|
634
635
|
or `false` to omit it.
|
|
635
636
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
636
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
637
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
637
638
|
that `mtime` is still included, because this is necessary for other
|
|
638
|
-
time-based operations.
|
|
639
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
639
640
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
640
|
-
- `preservePaths` Allow absolute paths.
|
|
641
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
641
642
|
from absolute paths.
|
|
642
643
|
|
|
643
644
|
- `linkCache` A Map object containing the device and inode value for
|
|
@@ -650,24 +651,24 @@ The following options are supported:
|
|
|
650
651
|
Defaults to 16 MB.
|
|
651
652
|
- `noDirRecurse` Do not recursively archive the contents of
|
|
652
653
|
directories.
|
|
653
|
-
- `follow` Set to true to pack the targets of symbolic links.
|
|
654
|
+
- `follow` Set to true to pack the targets of symbolic links. Without
|
|
654
655
|
this option, symbolic links are archived as such.
|
|
655
|
-
- `noPax` Suppress pax extended headers.
|
|
656
|
+
- `noPax` Suppress pax extended headers. Note that this means that
|
|
656
657
|
long paths and linkpaths will be truncated, and large or negative
|
|
657
658
|
numeric values may be interpreted incorrectly.
|
|
658
659
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
659
660
|
Note that this prevents using other mtime-based features like
|
|
660
661
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
661
662
|
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
662
|
-
everything added to the archive.
|
|
663
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
663
664
|
|
|
664
665
|
#### add(path)
|
|
665
666
|
|
|
666
|
-
Adds an entry to the archive.
|
|
667
|
+
Adds an entry to the archive. Returns the Pack stream.
|
|
667
668
|
|
|
668
669
|
#### write(path)
|
|
669
670
|
|
|
670
|
-
Adds an entry to the archive.
|
|
671
|
+
Adds an entry to the archive. Returns true if flushed.
|
|
671
672
|
|
|
672
673
|
#### end()
|
|
673
674
|
|
|
@@ -681,7 +682,7 @@ Synchronous version of `tar.Pack`.
|
|
|
681
682
|
|
|
682
683
|
A writable stream that unpacks a tar archive onto the file system.
|
|
683
684
|
|
|
684
|
-
All the normal writable stream stuff is supported.
|
|
685
|
+
All the normal writable stream stuff is supported. `write()` and
|
|
685
686
|
`end()` methods, `'drain'` events, etc.
|
|
686
687
|
|
|
687
688
|
Note that all directories that are created will be forced to be
|
|
@@ -691,77 +692,77 @@ mode.
|
|
|
691
692
|
|
|
692
693
|
`'close'` is emitted when it's done writing stuff to the file system.
|
|
693
694
|
|
|
694
|
-
Most unpack errors will cause a `warn` event to be emitted.
|
|
695
|
+
Most unpack errors will cause a `warn` event to be emitted. If the
|
|
695
696
|
`cwd` is missing, or not a directory, then an error will be emitted.
|
|
696
697
|
|
|
697
698
|
#### constructor(options)
|
|
698
699
|
|
|
699
|
-
- `cwd` Extract files relative to the specified directory.
|
|
700
|
-
to `process.cwd()`.
|
|
700
|
+
- `cwd` Extract files relative to the specified directory. Defaults
|
|
701
|
+
to `process.cwd()`. If provided, this must exist and must be a
|
|
701
702
|
directory.
|
|
702
703
|
- `filter` A function that gets called with `(path, entry)` for each
|
|
703
|
-
entry being unpacked.
|
|
704
|
+
entry being unpacked. Return `true` to unpack the entry from the
|
|
704
705
|
archive, or `false` to skip it.
|
|
705
706
|
- `newer` Set to true to keep the existing file on disk if it's newer
|
|
706
707
|
than the file in the archive.
|
|
707
|
-
- `keep` Do not overwrite existing files.
|
|
708
|
+
- `keep` Do not overwrite existing files. In particular, if a file
|
|
708
709
|
appears more than once in an archive, later copies will not
|
|
709
710
|
overwrite earlier copies.
|
|
710
711
|
- `preservePaths` Allow absolute paths, paths containing `..`, and
|
|
711
|
-
extracting through symbolic links.
|
|
712
|
+
extracting through symbolic links. By default, `/` is stripped from
|
|
712
713
|
absolute paths, `..` paths are not extracted, and any file whose
|
|
713
714
|
location would be modified by a symbolic link is not extracted.
|
|
714
|
-
- `unlink` Unlink files before creating them.
|
|
715
|
+
- `unlink` Unlink files before creating them. Without this option,
|
|
715
716
|
tar overwrites existing files, which preserves existing hardlinks.
|
|
716
717
|
With this option, existing hardlinks will be broken, as will any
|
|
717
718
|
symlink that would affect the location of an extracted file.
|
|
718
719
|
- `strip` Remove the specified number of leading path elements.
|
|
719
|
-
Pathnames with fewer elements will be silently skipped.
|
|
720
|
+
Pathnames with fewer elements will be silently skipped. Note that
|
|
720
721
|
the pathname is edited after applying the filter, but before
|
|
721
722
|
security checks.
|
|
722
723
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
723
|
-
any warnings encountered.
|
|
724
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
724
725
|
- `umask` Filter the modes of entries like `process.umask()`.
|
|
725
726
|
- `dmode` Default mode for directories
|
|
726
727
|
- `fmode` Default mode for files
|
|
727
728
|
- `dirCache` A Map object of which directories exist.
|
|
728
729
|
- `maxMetaEntrySize` The maximum size of meta entries that is
|
|
729
|
-
supported.
|
|
730
|
+
supported. Defaults to 1 MB.
|
|
730
731
|
- `preserveOwner` If true, tar will set the `uid` and `gid` of
|
|
731
732
|
extracted entries to the `uid` and `gid` fields in the archive.
|
|
732
|
-
This defaults to true when run as root, and false otherwise.
|
|
733
|
+
This defaults to true when run as root, and false otherwise. If
|
|
733
734
|
false, then files and directories will be set with the owner and
|
|
734
|
-
group of the user running the process.
|
|
735
|
+
group of the user running the process. This is similar to `-p` in
|
|
735
736
|
`tar(1)`, but ACLs and other system-specific data is never unpacked
|
|
736
737
|
in this implementation, and modes are set by default already.
|
|
737
|
-
- `win32` True if on a windows platform.
|
|
738
|
+
- `win32` True if on a windows platform. Causes behavior where
|
|
738
739
|
filenames containing `<|>?` chars are converted to
|
|
739
740
|
windows-compatible values while being unpacked.
|
|
740
741
|
- `uid` Set to a number to force ownership of all extracted files and
|
|
741
742
|
folders, and all implicitly created directories, to be owned by the
|
|
742
743
|
specified user id, regardless of the `uid` field in the archive.
|
|
743
|
-
Cannot be used along with `preserveOwner`.
|
|
744
|
+
Cannot be used along with `preserveOwner`. Requires also setting a
|
|
744
745
|
`gid` option.
|
|
745
746
|
- `gid` Set to a number to force ownership of all extracted files and
|
|
746
747
|
folders, and all implicitly created directories, to be owned by the
|
|
747
748
|
specified group id, regardless of the `gid` field in the archive.
|
|
748
|
-
Cannot be used along with `preserveOwner`.
|
|
749
|
+
Cannot be used along with `preserveOwner`. Requires also setting a
|
|
749
750
|
`uid` option.
|
|
750
751
|
- `noMtime` Set to true to omit writing `mtime` value for extracted
|
|
751
752
|
entries.
|
|
752
753
|
- `transform` Provide a function that takes an `entry` object, and
|
|
753
|
-
returns a stream, or any falsey value.
|
|
754
|
+
returns a stream, or any falsey value. If a stream is provided,
|
|
754
755
|
then that stream's data will be written instead of the contents of
|
|
755
|
-
the archive entry.
|
|
756
|
-
written to disk as normal.
|
|
756
|
+
the archive entry. If a falsey value is provided, then the entry is
|
|
757
|
+
written to disk as normal. (To exclude items from extraction, use
|
|
757
758
|
the `filter` option described above.)
|
|
758
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
759
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
759
760
|
- `onentry` A function that gets called with `(entry)` for each entry
|
|
760
761
|
that passes the filter.
|
|
761
762
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
762
|
-
any warnings encountered.
|
|
763
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
763
764
|
- `chmod` Set to true to call `fs.chmod()` to ensure that the
|
|
764
|
-
extracted file matches the entry mode.
|
|
765
|
+
extracted file matches the entry mode. This may necessitate a
|
|
765
766
|
call to the deprecated and thread-unsafe `process.umask()`
|
|
766
767
|
method to determine the default umask value, unless a
|
|
767
768
|
`processUmask` options is also provided. Otherwise tar will
|
|
@@ -785,7 +786,7 @@ use case.
|
|
|
785
786
|
|
|
786
787
|
### class tar.Parse
|
|
787
788
|
|
|
788
|
-
A writable stream that parses a tar archive stream.
|
|
789
|
+
A writable stream that parses a tar archive stream. All the standard
|
|
789
790
|
writable stream stuff is supported.
|
|
790
791
|
|
|
791
792
|
If the archive is gzipped, then tar will detect this and unzip it.
|
|
@@ -805,19 +806,19 @@ Returns an event emitter that emits `entry` events with
|
|
|
805
806
|
|
|
806
807
|
The following options are supported:
|
|
807
808
|
|
|
808
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
809
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
809
810
|
- `filter` A function that gets called with `(path, entry)` for each
|
|
810
|
-
entry being listed.
|
|
811
|
+
entry being listed. Return `true` to emit the entry from the
|
|
811
812
|
archive, or `false` to skip it.
|
|
812
813
|
- `onentry` A function that gets called with `(entry)` for each entry
|
|
813
814
|
that passes the filter.
|
|
814
815
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
815
|
-
any warnings encountered.
|
|
816
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
816
817
|
|
|
817
818
|
#### abort(error)
|
|
818
819
|
|
|
819
|
-
Stop all parsing activities.
|
|
820
|
-
errors.
|
|
820
|
+
Stop all parsing activities. This is called when there are zlib
|
|
821
|
+
errors. It also emits an unrecoverable warning with the error provided.
|
|
821
822
|
|
|
822
823
|
### class tar.ReadEntry extends [MiniPass](http://npm.im/minipass)
|
|
823
824
|
|
|
@@ -836,7 +837,7 @@ It has the following fields:
|
|
|
836
837
|
- `meta` True if this represents metadata about the next entry, false
|
|
837
838
|
if it represents a filesystem object.
|
|
838
839
|
- All the fields from the header, extended header, and global extended
|
|
839
|
-
header are added to the ReadEntry object.
|
|
840
|
+
header are added to the ReadEntry object. So it has `path`, `type`,
|
|
840
841
|
`size`, `mode`, and so on.
|
|
841
842
|
|
|
842
843
|
#### constructor(header, extended, globalExtended)
|
|
@@ -857,43 +858,42 @@ WriteEntry objects for all of the directory contents.
|
|
|
857
858
|
|
|
858
859
|
It has the following fields:
|
|
859
860
|
|
|
860
|
-
- `path` The path field that will be written to the archive.
|
|
861
|
+
- `path` The path field that will be written to the archive. By
|
|
861
862
|
default, this is also the path from the cwd to the file system
|
|
862
863
|
object.
|
|
863
864
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
864
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
865
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
865
866
|
that `mtime` is still included, because this is necessary for other
|
|
866
|
-
time-based operations.
|
|
867
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
867
868
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
868
869
|
- `myuid` If supported, the uid of the user running the current
|
|
869
870
|
process.
|
|
870
|
-
- `myuser` The `env.USER` string if set, or `''`.
|
|
871
|
+
- `myuser` The `env.USER` string if set, or `''`. Set as the entry
|
|
871
872
|
`uname` field if the file's `uid` matches `this.myuid`.
|
|
872
873
|
- `maxReadSize` The maximum buffer size for `fs.read()` operations.
|
|
873
874
|
Defaults to 1 MB.
|
|
874
875
|
- `linkCache` A Map object containing the device and inode value for
|
|
875
876
|
any file whose nlink is > 1, to identify hard links.
|
|
876
877
|
- `statCache` A Map object that caches calls `lstat`.
|
|
877
|
-
- `preservePaths` Allow absolute paths.
|
|
878
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
878
879
|
from absolute paths.
|
|
879
880
|
- `cwd` The current working directory for creating the archive.
|
|
880
881
|
Defaults to `process.cwd()`.
|
|
881
|
-
- `absolute` The absolute path to the entry on the filesystem.
|
|
882
|
+
- `absolute` The absolute path to the entry on the filesystem. By
|
|
882
883
|
default, this is `path.resolve(this.cwd, this.path)`, but it can be
|
|
883
884
|
overridden explicitly.
|
|
884
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
885
|
-
- `win32` True if on a windows platform.
|
|
885
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
886
|
+
- `win32` True if on a windows platform. Causes behavior where paths
|
|
886
887
|
replace `\` with `/` and filenames containing the windows-compatible
|
|
887
888
|
forms of `<|>?:` characters are converted to actual `<|>?:` characters
|
|
888
889
|
in the archive.
|
|
889
|
-
- `noPax` Suppress pax extended headers.
|
|
890
|
+
- `noPax` Suppress pax extended headers. Note that this means that
|
|
890
891
|
long paths and linkpaths will be truncated, and large or negative
|
|
891
892
|
numeric values may be interpreted incorrectly.
|
|
892
893
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
893
894
|
Note that this prevents using other mtime-based features like
|
|
894
895
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
895
896
|
|
|
896
|
-
|
|
897
897
|
#### constructor(path, options)
|
|
898
898
|
|
|
899
899
|
`path` is the path of the entry as it is written in the archive.
|
|
@@ -901,32 +901,32 @@ It has the following fields:
|
|
|
901
901
|
The following options are supported:
|
|
902
902
|
|
|
903
903
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
904
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
904
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
905
905
|
that `mtime` is still included, because this is necessary for other
|
|
906
|
-
time-based operations.
|
|
906
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
907
907
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
908
908
|
- `maxReadSize` The maximum buffer size for `fs.read()` operations.
|
|
909
909
|
Defaults to 1 MB.
|
|
910
910
|
- `linkCache` A Map object containing the device and inode value for
|
|
911
911
|
any file whose nlink is > 1, to identify hard links.
|
|
912
912
|
- `statCache` A Map object that caches calls `lstat`.
|
|
913
|
-
- `preservePaths` Allow absolute paths.
|
|
913
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
914
914
|
from absolute paths.
|
|
915
915
|
- `cwd` The current working directory for creating the archive.
|
|
916
916
|
Defaults to `process.cwd()`.
|
|
917
|
-
- `absolute` The absolute path to the entry on the filesystem.
|
|
917
|
+
- `absolute` The absolute path to the entry on the filesystem. By
|
|
918
918
|
default, this is `path.resolve(this.cwd, this.path)`, but it can be
|
|
919
919
|
overridden explicitly.
|
|
920
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
921
|
-
- `win32` True if on a windows platform.
|
|
920
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
921
|
+
- `win32` True if on a windows platform. Causes behavior where paths
|
|
922
922
|
replace `\` with `/`.
|
|
923
923
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
924
|
-
any warnings encountered.
|
|
924
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
925
925
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
926
926
|
Note that this prevents using other mtime-based features like
|
|
927
927
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
928
928
|
- `umask` Set to restrict the modes on the entries in the archive,
|
|
929
|
-
somewhat like how umask works on file creation.
|
|
929
|
+
somewhat like how umask works on file creation. Defaults to
|
|
930
930
|
`process.umask()` on unix systems, or `0o22` on Windows.
|
|
931
931
|
|
|
932
932
|
#### warn(message, data)
|
|
@@ -951,15 +951,15 @@ instead of from the filesystem.
|
|
|
951
951
|
The following options are supported:
|
|
952
952
|
|
|
953
953
|
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
|
|
954
|
-
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`.
|
|
954
|
+
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
|
|
955
955
|
that `mtime` is still included, because this is necessary for other
|
|
956
|
-
time-based operations.
|
|
956
|
+
time-based operations. Additionally, `mode` is set to a "reasonable
|
|
957
957
|
default" for most unix systems, based on a `umask` value of `0o22`.
|
|
958
|
-
- `preservePaths` Allow absolute paths.
|
|
958
|
+
- `preservePaths` Allow absolute paths. By default, `/` is stripped
|
|
959
959
|
from absolute paths.
|
|
960
|
-
- `strict` Treat warnings as crash-worthy errors.
|
|
960
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
961
961
|
- `onwarn` A function that will get called with `(code, message, data)` for
|
|
962
|
-
any warnings encountered.
|
|
962
|
+
any warnings encountered. (See "Warnings and Errors")
|
|
963
963
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
964
964
|
Note that this prevents using other mtime-based features like
|
|
965
965
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
@@ -971,21 +971,21 @@ A class for reading and writing header blocks.
|
|
|
971
971
|
It has the following fields:
|
|
972
972
|
|
|
973
973
|
- `nullBlock` True if decoding a block which is entirely composed of
|
|
974
|
-
`0x00` null bytes.
|
|
974
|
+
`0x00` null bytes. (Useful because tar files are terminated by
|
|
975
975
|
at least 2 null blocks.)
|
|
976
976
|
- `cksumValid` True if the checksum in the header is valid, false
|
|
977
977
|
otherwise.
|
|
978
978
|
- `needPax` True if the values, as encoded, will require a Pax
|
|
979
979
|
extended header.
|
|
980
980
|
- `path` The path of the entry.
|
|
981
|
-
- `mode` The 4 lowest-order octal digits of the file mode.
|
|
981
|
+
- `mode` The 4 lowest-order octal digits of the file mode. That is,
|
|
982
982
|
read/write/execute permissions for world, group, and owner, and the
|
|
983
983
|
setuid, setgid, and sticky bits.
|
|
984
984
|
- `uid` Numeric user id of the file owner
|
|
985
985
|
- `gid` Numeric group id of the file owner
|
|
986
986
|
- `size` Size of the file in bytes
|
|
987
987
|
- `mtime` Modified time of the file
|
|
988
|
-
- `cksum` The checksum of the header.
|
|
988
|
+
- `cksum` The checksum of the header. This is generated by adding all
|
|
989
989
|
the bytes of the header block, treating the checksum field itself as
|
|
990
990
|
all ascii space characters (that is, `0x20`).
|
|
991
991
|
- `type` The human-readable name of the type of entry this represents,
|
|
@@ -995,16 +995,16 @@ It has the following fields:
|
|
|
995
995
|
- `linkpath` The target of Link and SymbolicLink entries.
|
|
996
996
|
- `uname` Human-readable user name of the file owner
|
|
997
997
|
- `gname` Human-readable group name of the file owner
|
|
998
|
-
- `devmaj` The major portion of the device number.
|
|
998
|
+
- `devmaj` The major portion of the device number. Always `0` for
|
|
999
999
|
files, directories, and links.
|
|
1000
|
-
- `devmin` The minor portion of the device number.
|
|
1000
|
+
- `devmin` The minor portion of the device number. Always `0` for
|
|
1001
1001
|
files, directories, and links.
|
|
1002
1002
|
- `atime` File access time.
|
|
1003
1003
|
- `ctime` File change time.
|
|
1004
1004
|
|
|
1005
1005
|
#### constructor(data, [offset=0])
|
|
1006
1006
|
|
|
1007
|
-
`data` is optional.
|
|
1007
|
+
`data` is optional. It is either a Buffer that should be interpreted
|
|
1008
1008
|
as a tar Header starting at the specified offset and continuing for
|
|
1009
1009
|
512 bytes, or a data object of keys and values to set on the header
|
|
1010
1010
|
object, and eventually encode as a tar Header.
|
|
@@ -1031,7 +1031,7 @@ required to properly encode the specified data.
|
|
|
1031
1031
|
An object representing a set of key-value pairs in an Pax extended
|
|
1032
1032
|
header entry.
|
|
1033
1033
|
|
|
1034
|
-
It has the following fields.
|
|
1034
|
+
It has the following fields. Where the same name is used, they have
|
|
1035
1035
|
the same semantics as the tar.Header field of the same name.
|
|
1036
1036
|
|
|
1037
1037
|
- `global` True if this represents a global extended header, or false
|
|
@@ -1054,7 +1054,7 @@ the same semantics as the tar.Header field of the same name.
|
|
|
1054
1054
|
|
|
1055
1055
|
#### constructor(object, global)
|
|
1056
1056
|
|
|
1057
|
-
Set the fields set in the object.
|
|
1057
|
+
Set the fields set in the object. `global` is a boolean that defaults
|
|
1058
1058
|
to false.
|
|
1059
1059
|
|
|
1060
1060
|
#### encode()
|
|
@@ -1078,7 +1078,7 @@ Return a new Pax object created by parsing the contents of the string
|
|
|
1078
1078
|
provided.
|
|
1079
1079
|
|
|
1080
1080
|
If the `extended` object is set, then also add the fields from that
|
|
1081
|
-
object.
|
|
1081
|
+
object. (This is necessary because multiple metadata entries can
|
|
1082
1082
|
occur in sequence.)
|
|
1083
1083
|
|
|
1084
1084
|
### tar.types
|