source: node_modules/tar/README.md@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 45.0 KB
RevLine 
[81bc7da]1# node-tar
2
3Fast and full-featured Tar for Node.js
4
5The API is designed to mimic the behavior of `tar(1)` on unix systems.
6If you are familiar with how tar works, most of this will hopefully be
7straightforward for you. If not, then hopefully this module can teach
8you useful unix skills that may come in handy someday :)
9
10## Background
11
12A "tar file" or "tarball" is an archive of file system entries
13(directories, files, links, etc.) The name comes from "tape archive".
14If you run `man tar` on almost any Unix command line, you'll learn
15quite a bit about what it can do, and its history.
16
17Tar has 5 main top-level commands:
18
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
25The other flags and options modify how this top level function works.
26
27## High-Level API
28
29These 5 functions are the high-level API. All of them have a
30single-character name (for unix nerds familiar with `tar(1)`) as well
31as a long name (for everyone else).
32
33All the high-level functions take the following arguments, all three
34of which are optional and may be omitted.
35
361. `options` - An optional object specifying various options
372. `paths` - An array of paths to add or extract
383. `callback` - Called when the command is completed, if async. (If
39 sync or no file specified, providing a callback throws a
40 `TypeError`.)
41
42If the command is sync (ie, if `options.sync=true`), then the
43callback is not allowed, since the action will be completed immediately.
44
45If a `file` argument is specified, and the command is async, then a
46`Promise` is returned. In this case, if async, a callback may be
47provided which is called when the command is completed.
48
49If 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`list` and `extract` this is a writable stream that an archive should
52be written into. If a file is not specified, then a callback is not
53allowed, because you're already getting a stream to work with.
54
55`replace` and `update` only work on existing archives, and so require
56a `file` argument.
57
58Sync commands without a file argument return a stream that acts on its
59input immediately in the same tick. For readable streams, this means
60that all of the data is immediately available by calling
61`stream.read()`. For writable streams, it will be acted upon as soon
62as it is provided, but this can be at any time.
63
64### Warnings and Errors
65
66Tar emits warnings and errors for recoverable and unrecoverable situations,
67respectively. In many cases, a warning only affects a single entry in an
68archive, or is simply informing you that it's modifying an entry to comply
69with the settings provided.
70
71Unrecoverable warnings will always raise an error (ie, emit `'error'` on
72streaming actions, throw for non-streaming sync actions, reject the
73returned Promise for non-streaming async operations, or call a provided
74callback with an `Error` as the first argument). Recoverable errors will
75raise an error only if `strict: true` is set in the options.
76
77Respond to (recoverable) warnings by listening to the `warn` event.
78Handlers receive 3 arguments:
79
80- `code` String. One of the error codes below. This may not match
81 `data.code`, which preserves the original error code from 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 contains the following fields, as relevant:
86 - `tarCode` The tar error code.
87 - `code` Either the tar error code, or the error code set by the
88 underlying system.
89 - `file` The archive file being read or written.
90 - `cwd` Working directory for creation and extraction operations.
91 - `entry` The entry object (if it could be created) for `TAR_ENTRY_INFO`,
92 `TAR_ENTRY_INVALID`, and `TAR_ENTRY_ERROR` warnings.
93 - `header` The header object (if it could be created, and the entry could
94 not be created) for `TAR_ENTRY_INFO` and `TAR_ENTRY_INVALID` warnings.
95 - `recoverable` Boolean. If `false`, then the warning will emit an
96 `error`, even in non-strict mode.
97
98#### Error Codes
99
100* `TAR_ENTRY_INFO` An informative error indicating that an entry is being
101 modified, but otherwise processed normally. For example, removing `/` or
102 `C:\` from absolute paths if `preservePaths` is not set.
103
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 - a checksum fails,
107 - a `linkpath` is missing for a link type, or
108 - a `linkpath` is provided for a non-link type.
109
110 If every entry in a parsed archive raises an `TAR_ENTRY_INVALID` error,
111 then the archive is presumed to be unrecoverably broken, and
112 `TAR_BAD_ARCHIVE` will be raised.
113
114* `TAR_ENTRY_ERROR` The entry appears to be a valid tar archive entry, but
115 encountered an error which prevented it from being unpacked. This occurs
116 when:
117 - an unrecoverable fs error happens during unpacking,
118 - an entry is trying to extract into an excessively deep
119 location (by default, limited to 1024 subfolders),
120 - an entry has `..` in the path and `preservePaths` is not set, or
121 - an entry is extracting through a symbolic link, when `preservePaths` is
122 not set.
123
124* `TAR_ENTRY_UNSUPPORTED` An indication that a given entry is
125 a valid archive entry, but of a type that is unsupported, and so will be
126 skipped in archive creation or extracting.
127
128* `TAR_ABORT` When parsing gzipped-encoded archives, the parser will
129 abort the parse process raise a warning for any zlib errors encountered.
130 Aborts are considered unrecoverable for both parsing and unpacking.
131
132* `TAR_BAD_ARCHIVE` The archive file is totally hosed. This can happen for
133 a number of reasons, and always occurs at the end of a parse or extract:
134
135 - An entry body was truncated before seeing the full number of bytes.
136 - The archive contained only invalid entries, indicating that it is
137 likely not an archive, or at least, not an archive this library can
138 parse.
139
140 `TAR_BAD_ARCHIVE` is considered informative for parse operations, but
141 unrecoverable for extraction. Note that, if encountered at the end of an
142 extraction, tar WILL still have extracted as much it could from the
143 archive, so there may be some garbage files to clean up.
144
145Errors that occur deeper in the system (ie, either the filesystem or zlib)
146will have their error codes left intact, and a `tarCode` matching one of
147the above will be added to the warning metadata or the raised error object.
148
149Errors generated by tar will have one of the above codes set as the
150`error.code` field as well, but since errors originating in zlib or fs will
151have their original codes, it's better to read `error.tarCode` if you wish
152to see how tar is handling the issue.
153
154### Examples
155
156The API mimics the `tar(1)` command line functionality, with aliases
157for more human-readable option and function names. The goal is that
158if you know how to use `tar(1)` in Unix, then you know how to use
159`require('tar')` in JavaScript.
160
161To replicate `tar czf my-tarball.tgz files and folders`, you'd do:
162
163```js
164tar.c(
165 {
166 gzip: <true|gzip options>,
167 file: 'my-tarball.tgz'
168 },
169 ['some', 'files', 'and', 'folders']
170).then(_ => { .. tarball has been created .. })
171```
172
173To replicate `tar cz files and folders > my-tarball.tgz`, you'd do:
174
175```js
176tar.c( // or tar.create
177 {
178 gzip: <true|gzip options>
179 },
180 ['some', 'files', 'and', 'folders']
181).pipe(fs.createWriteStream('my-tarball.tgz'))
182```
183
184To replicate `tar xf my-tarball.tgz` you'd do:
185
186```js
187tar.x( // or tar.extract(
188 {
189 file: 'my-tarball.tgz'
190 }
191).then(_=> { .. tarball has been dumped in cwd .. })
192```
193
194To replicate `cat my-tarball.tgz | tar x -C some-dir --strip=1`:
195
196```js
197fs.createReadStream('my-tarball.tgz').pipe(
198 tar.x({
199 strip: 1,
200 C: 'some-dir' // alias for cwd:'some-dir', also ok
201 })
202)
203```
204
205To replicate `tar tf my-tarball.tgz`, do this:
206
207```js
208tar.t({
209 file: 'my-tarball.tgz',
210 onentry: entry => { .. do whatever with it .. }
211})
212```
213
214For example, to just get the list of filenames from an archive:
215
216```js
217const getEntryFilenames = async tarballFilename => {
218 const filenames = []
219 await tar.t({
220 file: tarballFilename,
221 onentry: entry => filenames.push(entry.path),
222 })
223 return filenames
224}
225```
226
227To replicate `cat my-tarball.tgz | tar t` do:
228
229```js
230fs.createReadStream('my-tarball.tgz')
231 .pipe(tar.t())
232 .on('entry', entry => { .. do whatever with it .. })
233```
234
235To do anything synchronous, add `sync: true` to the options. Note
236that sync functions don't take a callback and don't return a promise.
237When the function returns, it's already done. Sync methods without a
238file argument return a sync stream, which flushes immediately. But,
239of course, it still won't be done until you `.end()` it.
240
241```js
242const getEntryFilenamesSync = tarballFilename => {
243 const filenames = []
244 tar.t({
245 file: tarballFilename,
246 onentry: entry => filenames.push(entry.path),
247 sync: true,
248 })
249 return filenames
250}
251```
252
253To filter entries, add `filter: <function>` to the options.
254Tar-creating methods call the filter with `filter(path, stat)`.
255Tar-reading methods (including extraction) call the filter with
256`filter(path, entry)`. The filter is called in the `this`-context of
257the `Pack` or `Unpack` stream object.
258
259The arguments list to `tar t` and `tar x` specify a list of filenames
260to extract or list, so they're equivalent to a filter that tests if
261the file is in the list.
262
263For those who _aren't_ fans of tar's single-character command names:
264
265```
266tar.c === tar.create
267tar.r === tar.replace (appends to archive, file is required)
268tar.u === tar.update (appends if newer, file is required)
269tar.x === tar.extract
270tar.t === tar.list
271```
272
273Keep reading for all the command descriptions and options, as well as
274the low-level API that they are built on.
275
276### tar.c(options, fileList, callback) [alias: tar.create]
277
278Create a tarball archive.
279
280The `fileList` is an array of paths to add to the tarball. Adding a
281directory also adds its children recursively.
282
283An entry in `fileList` that starts with an `@` symbol is a tar archive
284whose entries will be added. To add a file that starts with `@`,
285prepend it with `./`.
286
287The following options are supported:
288
289- `file` Write the tarball archive to the specified filename. If this
290 is specified, then the callback will be fired when the file has been
291 written, and a promise will be returned that resolves when the file
292 is written. If a filename is not specified, then a Readable Stream
293 will be returned which will emit the file data. [Alias: `f`]
294- `sync` Act synchronously. If this is set, then any provided file
295 will be fully written after the call to `tar.c`. If this is set,
296 and a file is not provided, then the resulting stream will already
297 have the data ready to `read` or `emit('data')` as soon as you
298 request it.
299- `onwarn` A function that will get called with `(code, message, data)` for
300 any warnings encountered. (See "Warnings and Errors")
301- `strict` Treat warnings as crash-worthy errors. Default false.
302- `cwd` The current working directory for creating the archive.
303 Defaults to `process.cwd()`. [Alias: `C`]
304- `prefix` A path portion to prefix onto the entries in the archive.
305- `gzip` Set to any truthy value to create a gzipped archive, or an
306 object with settings for `zlib.Gzip()` [Alias: `z`]
307- `filter` A function that gets called with `(path, stat)` for each
308 entry being added. Return `true` to add the entry to the archive,
309 or `false` to omit it.
310- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
311 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
312 that `mtime` is still included, because this is necessary for other
313 time-based operations. Additionally, `mode` is set to a "reasonable
314 default" for most unix systems, based on a `umask` value of `0o22`.
315- `preservePaths` Allow absolute paths. By default, `/` is stripped
316 from absolute paths. [Alias: `P`]
317- `mode` The mode to set on the created file archive
318- `noDirRecurse` Do not recursively archive the contents of
319 directories. [Alias: `n`]
320- `follow` Set to true to pack the targets of symbolic links. Without
321 this option, symbolic links are archived as such. [Alias: `L`, `h`]
322- `noPax` Suppress pax extended headers. Note that this means that
323 long paths and linkpaths will be truncated, and large or negative
324 numeric values may be interpreted incorrectly.
325- `noMtime` Set to true to omit writing `mtime` values for entries.
326 Note that this prevents using other mtime-based features like
327 `tar.update` or the `keepNewer` option with the resulting tar archive.
328 [Alias: `m`, `no-mtime`]
329- `mtime` Set to a `Date` object to force a specific `mtime` for
330 everything added to the archive. Overridden by `noMtime`.
331
332The following options are mostly internal, but can be modified in some
333advanced use cases, such as re-using caches between runs.
334
335- `linkCache` A Map object containing the device and inode value for
336 any file whose nlink is > 1, to identify hard links.
337- `statCache` A Map object that caches calls `lstat`.
338- `readdirCache` A Map object that caches calls to `readdir`.
339- `jobs` A number specifying how many concurrent jobs to run.
340 Defaults to 4.
341- `maxReadSize` The maximum buffer size for `fs.read()` operations.
342 Defaults to 16 MB.
343
344### tar.x(options, fileList, callback) [alias: tar.extract]
345
346Extract a tarball archive.
347
348The `fileList` is an array of paths to extract from the tarball. If
349no paths are provided, then all the entries are extracted.
350
351If the archive is gzipped, then tar will detect this and unzip it.
352
353Note that all directories that are created will be forced to be
354writable, readable, and listable by their owner, to avoid cases where
355a directory prevents extraction of child entries by virtue of its
356mode.
357
358Most extraction errors will cause a `warn` event to be emitted. If
359the `cwd` is missing, or not a directory, then the extraction will
360fail completely.
361
362The following options are supported:
363
364- `cwd` Extract files relative to the specified directory. Defaults
365 to `process.cwd()`. If provided, this must exist and must be a
366 directory. [Alias: `C`]
367- `file` The archive file to extract. If not specified, then a
368 Writable stream is returned where the archive data should be
369 written. [Alias: `f`]
370- `sync` Create files and directories synchronously.
371- `strict` Treat warnings as crash-worthy errors. Default false.
372- `filter` A function that gets called with `(path, entry)` for each
373 entry being unpacked. Return `true` to unpack the entry from the
374 archive, or `false` to skip it.
375- `newer` Set to true to keep the existing file on disk if it's newer
376 than the file in the archive. [Alias: `keep-newer`,
377 `keep-newer-files`]
378- `keep` Do not overwrite existing files. In particular, if a file
379 appears more than once in an archive, later copies will not
380 overwrite earlier copies. [Alias: `k`, `keep-existing`]
381- `preservePaths` Allow absolute paths, paths containing `..`, and
382 extracting through symbolic links. By default, `/` is stripped from
383 absolute paths, `..` paths are not extracted, and any file whose
384 location would be modified by a symbolic link is not extracted.
385 [Alias: `P`]
386- `unlink` Unlink files before creating them. Without this option,
387 tar overwrites existing files, which preserves existing hardlinks.
388 With this option, existing hardlinks will be broken, as will any
389 symlink that would affect the location of an extracted file. [Alias:
390 `U`]
391- `strip` Remove the specified number of leading path elements.
392 Pathnames with fewer elements will be silently skipped. Note that
393 the pathname is edited after applying the filter, but before
394 security checks. [Alias: `strip-components`, `stripComponents`]
395- `onwarn` A function that will get called with `(code, message, data)` for
396 any warnings encountered. (See "Warnings and Errors")
397- `preserveOwner` If true, tar will set the `uid` and `gid` of
398 extracted entries to the `uid` and `gid` fields in the archive.
399 This defaults to true when run as root, and false otherwise. If
400 false, then files and directories will be set with the owner and
401 group of the user running the process. This is similar to `-p` in
402 `tar(1)`, but ACLs and other system-specific data is never unpacked
403 in this implementation, and modes are set by default already.
404 [Alias: `p`]
405- `uid` Set to a number to force ownership of all extracted files and
406 folders, and all implicitly created directories, to be owned by the
407 specified user id, regardless of the `uid` field in the archive.
408 Cannot be used along with `preserveOwner`. Requires also setting a
409 `gid` option.
410- `gid` Set to a number to force ownership of all extracted files and
411 folders, and all implicitly created directories, to be owned by the
412 specified group id, regardless of the `gid` field in the archive.
413 Cannot be used along with `preserveOwner`. Requires also setting a
414 `uid` option.
415- `noMtime` Set to true to omit writing `mtime` value for extracted
416 entries. [Alias: `m`, `no-mtime`]
417- `transform` Provide a function that takes an `entry` object, and
418 returns a stream, or any falsey value. If a stream is provided,
419 then that stream's data will be written instead of the contents of
420 the archive entry. If a falsey value is provided, then the entry is
421 written to disk as normal. (To exclude items from extraction, use
422 the `filter` option described above.)
423- `onentry` A function that gets called with `(entry)` for each entry
424 that passes the filter.
425- `onwarn` A function that will get called with `(code, message, data)` for
426 any warnings encountered. (See "Warnings and Errors")
427- `noChmod` Set to true to omit calling `fs.chmod()` to ensure that the
428 extracted file matches the entry mode. This also suppresses the call to
429 `process.umask()` to determine the default umask value, since tar will
430 extract with whatever mode is provided, and let the process `umask` apply
431 normally.
432- `maxDepth` The maximum depth of subfolders to extract into. This
433 defaults to 1024. Anything deeper than the limit will raise a
434 warning and skip the entry. Set to `Infinity` to remove the
435 limitation.
436
437The following options are mostly internal, but can be modified in some
438advanced use cases, such as re-using caches between runs.
439
440- `maxReadSize` The maximum buffer size for `fs.read()` operations.
441 Defaults to 16 MB.
442- `umask` Filter the modes of entries like `process.umask()`.
443- `dmode` Default mode for directories
444- `fmode` Default mode for files
445- `dirCache` A Map object of which directories exist.
446- `maxMetaEntrySize` The maximum size of meta entries that is
447 supported. Defaults to 1 MB.
448
449Note that using an asynchronous stream type with the `transform`
450option will cause undefined behavior in sync extractions.
451[MiniPass](http://npm.im/minipass)-based streams are designed for this
452use case.
453
454### tar.t(options, fileList, callback) [alias: tar.list]
455
456List the contents of a tarball archive.
457
458The `fileList` is an array of paths to list from the tarball. If
459no paths are provided, then all the entries are listed.
460
461If the archive is gzipped, then tar will detect this and unzip it.
462
463If the `file` option is _not_ provided, then returns an event emitter that
464emits `entry` events with `tar.ReadEntry` objects. However, they don't
465emit `'data'` or `'end'` events. (If you want to get actual readable
466entries, use the `tar.Parse` class instead.)
467
468If a `file` option _is_ provided, then the return value will be a promise
469that resolves when the file has been fully traversed in async mode, or
470`undefined` if `sync: true` is set. Thus, you _must_ specify an `onentry`
471method in order to do anything useful with the data it parses.
472
473The following options are supported:
474
475- `file` The archive file to list. If not specified, then a
476 Writable stream is returned where the archive data should be
477 written. [Alias: `f`]
478- `sync` Read the specified file synchronously. (This has no effect
479 when a file option isn't specified, because entries are emitted as
480 fast as they are parsed from the stream anyway.)
481- `strict` Treat warnings as crash-worthy errors. Default false.
482- `filter` A function that gets called with `(path, entry)` for each
483 entry being listed. Return `true` to emit the entry from the
484 archive, or `false` to skip it.
485- `onentry` A function that gets called with `(entry)` for each entry
486 that passes the filter. This is important for when `file` is set,
487 because there is no other way to do anything useful with this method.
488- `maxReadSize` The maximum buffer size for `fs.read()` operations.
489 Defaults to 16 MB.
490- `noResume` By default, `entry` streams are resumed immediately after
491 the call to `onentry`. Set `noResume: true` to suppress this
492 behavior. Note that by opting into this, the stream will never
493 complete until the entry data is consumed.
494- `onwarn` A function that will get called with `(code, message, data)` for
495 any warnings encountered. (See "Warnings and Errors")
496
497### tar.u(options, fileList, callback) [alias: tar.update]
498
499Add files to an archive if they are newer than the entry already in
500the tarball archive.
501
502The `fileList` is an array of paths to add to the tarball. Adding a
503directory also adds its children recursively.
504
505An entry in `fileList` that starts with an `@` symbol is a tar archive
506whose entries will be added. To add a file that starts with `@`,
507prepend it with `./`.
508
509The following options are supported:
510
511- `file` Required. Write the tarball archive to the specified
512 filename. [Alias: `f`]
513- `sync` Act synchronously. If this is set, then any provided file
514 will be fully written after the call to `tar.c`.
515- `onwarn` A function that will get called with `(code, message, data)` for
516 any warnings encountered. (See "Warnings and Errors")
517- `strict` Treat warnings as crash-worthy errors. Default false.
518- `cwd` The current working directory for adding entries to the
519 archive. Defaults to `process.cwd()`. [Alias: `C`]
520- `prefix` A path portion to prefix onto the entries in the archive.
521- `gzip` Set to any truthy value to create a gzipped archive, or an
522 object with settings for `zlib.Gzip()` [Alias: `z`]
523- `filter` A function that gets called with `(path, stat)` for each
524 entry being added. Return `true` to add the entry to the archive,
525 or `false` to omit it.
526- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
527 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
528 that `mtime` is still included, because this is necessary for other
529 time-based operations. Additionally, `mode` is set to a "reasonable
530 default" for most unix systems, based on a `umask` value of `0o22`.
531- `preservePaths` Allow absolute paths. By default, `/` is stripped
532 from absolute paths. [Alias: `P`]
533- `maxReadSize` The maximum buffer size for `fs.read()` operations.
534 Defaults to 16 MB.
535- `noDirRecurse` Do not recursively archive the contents of
536 directories. [Alias: `n`]
537- `follow` Set to true to pack the targets of symbolic links. Without
538 this option, symbolic links are archived as such. [Alias: `L`, `h`]
539- `noPax` Suppress pax extended headers. Note that this means that
540 long paths and linkpaths will be truncated, and large or negative
541 numeric values may be interpreted incorrectly.
542- `noMtime` Set to true to omit writing `mtime` values for entries.
543 Note that this prevents using other mtime-based features like
544 `tar.update` or the `keepNewer` option with the resulting tar archive.
545 [Alias: `m`, `no-mtime`]
546- `mtime` Set to a `Date` object to force a specific `mtime` for
547 everything added to the archive. Overridden by `noMtime`.
548
549### tar.r(options, fileList, callback) [alias: tar.replace]
550
551Add files to an existing archive. Because later entries override
552earlier entries, this effectively replaces any existing entries.
553
554The `fileList` is an array of paths to add to the tarball. Adding a
555directory also adds its children recursively.
556
557An entry in `fileList` that starts with an `@` symbol is a tar archive
558whose entries will be added. To add a file that starts with `@`,
559prepend it with `./`.
560
561The following options are supported:
562
563- `file` Required. Write the tarball archive to the specified
564 filename. [Alias: `f`]
565- `sync` Act synchronously. If this is set, then any provided file
566 will be fully written after the call to `tar.c`.
567- `onwarn` A function that will get called with `(code, message, data)` for
568 any warnings encountered. (See "Warnings and Errors")
569- `strict` Treat warnings as crash-worthy errors. Default false.
570- `cwd` The current working directory for adding entries to the
571 archive. Defaults to `process.cwd()`. [Alias: `C`]
572- `prefix` A path portion to prefix onto the entries in the archive.
573- `gzip` Set to any truthy value to create a gzipped archive, or an
574 object with settings for `zlib.Gzip()` [Alias: `z`]
575- `filter` A function that gets called with `(path, stat)` for each
576 entry being added. Return `true` to add the entry to the archive,
577 or `false` to omit it.
578- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
579 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
580 that `mtime` is still included, because this is necessary for other
581 time-based operations. Additionally, `mode` is set to a "reasonable
582 default" for most unix systems, based on a `umask` value of `0o22`.
583- `preservePaths` Allow absolute paths. By default, `/` is stripped
584 from absolute paths. [Alias: `P`]
585- `maxReadSize` The maximum buffer size for `fs.read()` operations.
586 Defaults to 16 MB.
587- `noDirRecurse` Do not recursively archive the contents of
588 directories. [Alias: `n`]
589- `follow` Set to true to pack the targets of symbolic links. Without
590 this option, symbolic links are archived as such. [Alias: `L`, `h`]
591- `noPax` Suppress pax extended headers. Note that this means that
592 long paths and linkpaths will be truncated, and large or negative
593 numeric values may be interpreted incorrectly.
594- `noMtime` Set to true to omit writing `mtime` values for entries.
595 Note that this prevents using other mtime-based features like
596 `tar.update` or the `keepNewer` option with the resulting tar archive.
597 [Alias: `m`, `no-mtime`]
598- `mtime` Set to a `Date` object to force a specific `mtime` for
599 everything added to the archive. Overridden by `noMtime`.
600
601
602## Low-Level API
603
604### class tar.Pack
605
606A readable tar stream.
607
608Has all the standard readable stream interface stuff. `'data'` and
609`'end'` events, `read()` method, `pause()` and `resume()`, etc.
610
611#### constructor(options)
612
613The following options are supported:
614
615- `onwarn` A function that will get called with `(code, message, data)` for
616 any warnings encountered. (See "Warnings and Errors")
617- `strict` Treat warnings as crash-worthy errors. Default false.
618- `cwd` The current working directory for creating the archive.
619 Defaults to `process.cwd()`.
620- `prefix` A path portion to prefix onto the entries in the archive.
621- `gzip` Set to any truthy value to create a gzipped archive, or an
622 object with settings for `zlib.Gzip()`
623- `filter` A function that gets called with `(path, stat)` for each
624 entry being added. Return `true` to add the entry to the archive,
625 or `false` to omit it.
626- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
627 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
628 that `mtime` is still included, because this is necessary for other
629 time-based operations. Additionally, `mode` is set to a "reasonable
630 default" for most unix systems, based on a `umask` value of `0o22`.
631- `preservePaths` Allow absolute paths. By default, `/` is stripped
632 from absolute paths.
633- `linkCache` A Map object containing the device and inode value for
634 any file whose nlink is > 1, to identify hard links.
635- `statCache` A Map object that caches calls `lstat`.
636- `readdirCache` A Map object that caches calls to `readdir`.
637- `jobs` A number specifying how many concurrent jobs to run.
638 Defaults to 4.
639- `maxReadSize` The maximum buffer size for `fs.read()` operations.
640 Defaults to 16 MB.
641- `noDirRecurse` Do not recursively archive the contents of
642 directories.
643- `follow` Set to true to pack the targets of symbolic links. Without
644 this option, symbolic links are archived as such.
645- `noPax` Suppress pax extended headers. Note that this means that
646 long paths and linkpaths will be truncated, and large or negative
647 numeric values may be interpreted incorrectly.
648- `noMtime` Set to true to omit writing `mtime` values for entries.
649 Note that this prevents using other mtime-based features like
650 `tar.update` or the `keepNewer` option with the resulting tar archive.
651- `mtime` Set to a `Date` object to force a specific `mtime` for
652 everything added to the archive. Overridden by `noMtime`.
653
654#### add(path)
655
656Adds an entry to the archive. Returns the Pack stream.
657
658#### write(path)
659
660Adds an entry to the archive. Returns true if flushed.
661
662#### end()
663
664Finishes the archive.
665
666### class tar.Pack.Sync
667
668Synchronous version of `tar.Pack`.
669
670### class tar.Unpack
671
672A writable stream that unpacks a tar archive onto the file system.
673
674All the normal writable stream stuff is supported. `write()` and
675`end()` methods, `'drain'` events, etc.
676
677Note that all directories that are created will be forced to be
678writable, readable, and listable by their owner, to avoid cases where
679a directory prevents extraction of child entries by virtue of its
680mode.
681
682`'close'` is emitted when it's done writing stuff to the file system.
683
684Most unpack errors will cause a `warn` event to be emitted. If the
685`cwd` is missing, or not a directory, then an error will be emitted.
686
687#### constructor(options)
688
689- `cwd` Extract files relative to the specified directory. Defaults
690 to `process.cwd()`. If provided, this must exist and must be a
691 directory.
692- `filter` A function that gets called with `(path, entry)` for each
693 entry being unpacked. Return `true` to unpack the entry from the
694 archive, or `false` to skip it.
695- `newer` Set to true to keep the existing file on disk if it's newer
696 than the file in the archive.
697- `keep` Do not overwrite existing files. In particular, if a file
698 appears more than once in an archive, later copies will not
699 overwrite earlier copies.
700- `preservePaths` Allow absolute paths, paths containing `..`, and
701 extracting through symbolic links. By default, `/` is stripped from
702 absolute paths, `..` paths are not extracted, and any file whose
703 location would be modified by a symbolic link is not extracted.
704- `unlink` Unlink files before creating them. Without this option,
705 tar overwrites existing files, which preserves existing hardlinks.
706 With this option, existing hardlinks will be broken, as will any
707 symlink that would affect the location of an extracted file.
708- `strip` Remove the specified number of leading path elements.
709 Pathnames with fewer elements will be silently skipped. Note that
710 the pathname is edited after applying the filter, but before
711 security checks.
712- `onwarn` A function that will get called with `(code, message, data)` for
713 any warnings encountered. (See "Warnings and Errors")
714- `umask` Filter the modes of entries like `process.umask()`.
715- `dmode` Default mode for directories
716- `fmode` Default mode for files
717- `dirCache` A Map object of which directories exist.
718- `maxMetaEntrySize` The maximum size of meta entries that is
719 supported. Defaults to 1 MB.
720- `preserveOwner` If true, tar will set the `uid` and `gid` of
721 extracted entries to the `uid` and `gid` fields in the archive.
722 This defaults to true when run as root, and false otherwise. If
723 false, then files and directories will be set with the owner and
724 group of the user running the process. This is similar to `-p` in
725 `tar(1)`, but ACLs and other system-specific data is never unpacked
726 in this implementation, and modes are set by default already.
727- `win32` True if on a windows platform. Causes behavior where
728 filenames containing `<|>?` chars are converted to
729 windows-compatible values while being unpacked.
730- `uid` Set to a number to force ownership of all extracted files and
731 folders, and all implicitly created directories, to be owned by the
732 specified user id, regardless of the `uid` field in the archive.
733 Cannot be used along with `preserveOwner`. Requires also setting a
734 `gid` option.
735- `gid` Set to a number to force ownership of all extracted files and
736 folders, and all implicitly created directories, to be owned by the
737 specified group id, regardless of the `gid` field in the archive.
738 Cannot be used along with `preserveOwner`. Requires also setting a
739 `uid` option.
740- `noMtime` Set to true to omit writing `mtime` value for extracted
741 entries.
742- `transform` Provide a function that takes an `entry` object, and
743 returns a stream, or any falsey value. If a stream is provided,
744 then that stream's data will be written instead of the contents of
745 the archive entry. If a falsey value is provided, then the entry is
746 written to disk as normal. (To exclude items from extraction, use
747 the `filter` option described above.)
748- `strict` Treat warnings as crash-worthy errors. Default false.
749- `onentry` A function that gets called with `(entry)` for each entry
750 that passes the filter.
751- `onwarn` A function that will get called with `(code, message, data)` for
752 any warnings encountered. (See "Warnings and Errors")
753- `noChmod` Set to true to omit calling `fs.chmod()` to ensure that the
754 extracted file matches the entry mode. This also suppresses the call to
755 `process.umask()` to determine the default umask value, since tar will
756 extract with whatever mode is provided, and let the process `umask` apply
757 normally.
758- `maxDepth` The maximum depth of subfolders to extract into. This
759 defaults to 1024. Anything deeper than the limit will raise a
760 warning and skip the entry. Set to `Infinity` to remove the
761 limitation.
762
763### class tar.Unpack.Sync
764
765Synchronous version of `tar.Unpack`.
766
767Note that using an asynchronous stream type with the `transform`
768option will cause undefined behavior in sync unpack streams.
769[MiniPass](http://npm.im/minipass)-based streams are designed for this
770use case.
771
772### class tar.Parse
773
774A writable stream that parses a tar archive stream. All the standard
775writable stream stuff is supported.
776
777If the archive is gzipped, then tar will detect this and unzip it.
778
779Emits `'entry'` events with `tar.ReadEntry` objects, which are
780themselves readable streams that you can pipe wherever.
781
782Each `entry` will not emit until the one before it is flushed through,
783so make sure to either consume the data (with `on('data', ...)` or
784`.pipe(...)`) or throw it away with `.resume()` to keep the stream
785flowing.
786
787#### constructor(options)
788
789Returns an event emitter that emits `entry` events with
790`tar.ReadEntry` objects.
791
792The following options are supported:
793
794- `strict` Treat warnings as crash-worthy errors. Default false.
795- `filter` A function that gets called with `(path, entry)` for each
796 entry being listed. Return `true` to emit the entry from the
797 archive, or `false` to skip it.
798- `onentry` A function that gets called with `(entry)` for each entry
799 that passes the filter.
800- `onwarn` A function that will get called with `(code, message, data)` for
801 any warnings encountered. (See "Warnings and Errors")
802
803#### abort(error)
804
805Stop all parsing activities. This is called when there are zlib
806errors. It also emits an unrecoverable warning with the error provided.
807
808### class tar.ReadEntry extends [MiniPass](http://npm.im/minipass)
809
810A representation of an entry that is being read out of a tar archive.
811
812It has the following fields:
813
814- `extended` The extended metadata object provided to the constructor.
815- `globalExtended` The global extended metadata object provided to the
816 constructor.
817- `remain` The number of bytes remaining to be written into the
818 stream.
819- `blockRemain` The number of 512-byte blocks remaining to be written
820 into the stream.
821- `ignore` Whether this entry should be ignored.
822- `meta` True if this represents metadata about the next entry, false
823 if it represents a filesystem object.
824- All the fields from the header, extended header, and global extended
825 header are added to the ReadEntry object. So it has `path`, `type`,
826 `size`, `mode`, and so on.
827
828#### constructor(header, extended, globalExtended)
829
830Create a new ReadEntry object with the specified header, extended
831header, and global extended header values.
832
833### class tar.WriteEntry extends [MiniPass](http://npm.im/minipass)
834
835A representation of an entry that is being written from the file
836system into a tar archive.
837
838Emits data for the Header, and for the Pax Extended Header if one is
839required, as well as any body data.
840
841Creating a WriteEntry for a directory does not also create
842WriteEntry objects for all of the directory contents.
843
844It has the following fields:
845
846- `path` The path field that will be written to the archive. By
847 default, this is also the path from the cwd to the file system
848 object.
849- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
850 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
851 that `mtime` is still included, because this is necessary for other
852 time-based operations. Additionally, `mode` is set to a "reasonable
853 default" for most unix systems, based on a `umask` value of `0o22`.
854- `myuid` If supported, the uid of the user running the current
855 process.
856- `myuser` The `env.USER` string if set, or `''`. Set as the entry
857 `uname` field if the file's `uid` matches `this.myuid`.
858- `maxReadSize` The maximum buffer size for `fs.read()` operations.
859 Defaults to 1 MB.
860- `linkCache` A Map object containing the device and inode value for
861 any file whose nlink is > 1, to identify hard links.
862- `statCache` A Map object that caches calls `lstat`.
863- `preservePaths` Allow absolute paths. By default, `/` is stripped
864 from absolute paths.
865- `cwd` The current working directory for creating the archive.
866 Defaults to `process.cwd()`.
867- `absolute` The absolute path to the entry on the filesystem. By
868 default, this is `path.resolve(this.cwd, this.path)`, but it can be
869 overridden explicitly.
870- `strict` Treat warnings as crash-worthy errors. Default false.
871- `win32` True if on a windows platform. Causes behavior where paths
872 replace `\` with `/` and filenames containing the windows-compatible
873 forms of `<|>?:` characters are converted to actual `<|>?:` characters
874 in the archive.
875- `noPax` Suppress pax extended headers. Note that this means that
876 long paths and linkpaths will be truncated, and large or negative
877 numeric values may be interpreted incorrectly.
878- `noMtime` Set to true to omit writing `mtime` values for entries.
879 Note that this prevents using other mtime-based features like
880 `tar.update` or the `keepNewer` option with the resulting tar archive.
881
882
883#### constructor(path, options)
884
885`path` is the path of the entry as it is written in the archive.
886
887The following options are supported:
888
889- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
890 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
891 that `mtime` is still included, because this is necessary for other
892 time-based operations. Additionally, `mode` is set to a "reasonable
893 default" for most unix systems, based on a `umask` value of `0o22`.
894- `maxReadSize` The maximum buffer size for `fs.read()` operations.
895 Defaults to 1 MB.
896- `linkCache` A Map object containing the device and inode value for
897 any file whose nlink is > 1, to identify hard links.
898- `statCache` A Map object that caches calls `lstat`.
899- `preservePaths` Allow absolute paths. By default, `/` is stripped
900 from absolute paths.
901- `cwd` The current working directory for creating the archive.
902 Defaults to `process.cwd()`.
903- `absolute` The absolute path to the entry on the filesystem. By
904 default, this is `path.resolve(this.cwd, this.path)`, but it can be
905 overridden explicitly.
906- `strict` Treat warnings as crash-worthy errors. Default false.
907- `win32` True if on a windows platform. Causes behavior where paths
908 replace `\` with `/`.
909- `onwarn` A function that will get called with `(code, message, data)` for
910 any warnings encountered. (See "Warnings and Errors")
911- `noMtime` Set to true to omit writing `mtime` values for entries.
912 Note that this prevents using other mtime-based features like
913 `tar.update` or the `keepNewer` option with the resulting tar archive.
914- `umask` Set to restrict the modes on the entries in the archive,
915 somewhat like how umask works on file creation. Defaults to
916 `process.umask()` on unix systems, or `0o22` on Windows.
917
918#### warn(message, data)
919
920If strict, emit an error with the provided message.
921
922Othewise, emit a `'warn'` event with the provided message and data.
923
924### class tar.WriteEntry.Sync
925
926Synchronous version of tar.WriteEntry
927
928### class tar.WriteEntry.Tar
929
930A version of tar.WriteEntry that gets its data from a tar.ReadEntry
931instead of from the filesystem.
932
933#### constructor(readEntry, options)
934
935`readEntry` is the entry being read out of another archive.
936
937The following options are supported:
938
939- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
940 `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
941 that `mtime` is still included, because this is necessary for other
942 time-based operations. Additionally, `mode` is set to a "reasonable
943 default" for most unix systems, based on a `umask` value of `0o22`.
944- `preservePaths` Allow absolute paths. By default, `/` is stripped
945 from absolute paths.
946- `strict` Treat warnings as crash-worthy errors. Default false.
947- `onwarn` A function that will get called with `(code, message, data)` for
948 any warnings encountered. (See "Warnings and Errors")
949- `noMtime` Set to true to omit writing `mtime` values for entries.
950 Note that this prevents using other mtime-based features like
951 `tar.update` or the `keepNewer` option with the resulting tar archive.
952
953### class tar.Header
954
955A class for reading and writing header blocks.
956
957It has the following fields:
958
959- `nullBlock` True if decoding a block which is entirely composed of
960 `0x00` null bytes. (Useful because tar files are terminated by
961 at least 2 null blocks.)
962- `cksumValid` True if the checksum in the header is valid, false
963 otherwise.
964- `needPax` True if the values, as encoded, will require a Pax
965 extended header.
966- `path` The path of the entry.
967- `mode` The 4 lowest-order octal digits of the file mode. That is,
968 read/write/execute permissions for world, group, and owner, and the
969 setuid, setgid, and sticky bits.
970- `uid` Numeric user id of the file owner
971- `gid` Numeric group id of the file owner
972- `size` Size of the file in bytes
973- `mtime` Modified time of the file
974- `cksum` The checksum of the header. This is generated by adding all
975 the bytes of the header block, treating the checksum field itself as
976 all ascii space characters (that is, `0x20`).
977- `type` The human-readable name of the type of entry this represents,
978 or the alphanumeric key if unknown.
979- `typeKey` The alphanumeric key for the type of entry this header
980 represents.
981- `linkpath` The target of Link and SymbolicLink entries.
982- `uname` Human-readable user name of the file owner
983- `gname` Human-readable group name of the file owner
984- `devmaj` The major portion of the device number. Always `0` for
985 files, directories, and links.
986- `devmin` The minor portion of the device number. Always `0` for
987 files, directories, and links.
988- `atime` File access time.
989- `ctime` File change time.
990
991#### constructor(data, [offset=0])
992
993`data` is optional. It is either a Buffer that should be interpreted
994as a tar Header starting at the specified offset and continuing for
995512 bytes, or a data object of keys and values to set on the header
996object, and eventually encode as a tar Header.
997
998#### decode(block, offset)
999
1000Decode the provided buffer starting at the specified offset.
1001
1002Buffer length must be greater than 512 bytes.
1003
1004#### set(data)
1005
1006Set the fields in the data object.
1007
1008#### encode(buffer, offset)
1009
1010Encode the header fields into the buffer at the specified offset.
1011
1012Returns `this.needPax` to indicate whether a Pax Extended Header is
1013required to properly encode the specified data.
1014
1015### class tar.Pax
1016
1017An object representing a set of key-value pairs in an Pax extended
1018header entry.
1019
1020It has the following fields. Where the same name is used, they have
1021the same semantics as the tar.Header field of the same name.
1022
1023- `global` True if this represents a global extended header, or false
1024 if it is for a single entry.
1025- `atime`
1026- `charset`
1027- `comment`
1028- `ctime`
1029- `gid`
1030- `gname`
1031- `linkpath`
1032- `mtime`
1033- `path`
1034- `size`
1035- `uid`
1036- `uname`
1037- `dev`
1038- `ino`
1039- `nlink`
1040
1041#### constructor(object, global)
1042
1043Set the fields set in the object. `global` is a boolean that defaults
1044to false.
1045
1046#### encode()
1047
1048Return a Buffer containing the header and body for the Pax extended
1049header entry, or `null` if there is nothing to encode.
1050
1051#### encodeBody()
1052
1053Return a string representing the body of the pax extended header
1054entry.
1055
1056#### encodeField(fieldName)
1057
1058Return a string representing the key/value encoding for the specified
1059fieldName, or `''` if the field is unset.
1060
1061### tar.Pax.parse(string, extended, global)
1062
1063Return a new Pax object created by parsing the contents of the string
1064provided.
1065
1066If the `extended` object is set, then also add the fields from that
1067object. (This is necessary because multiple metadata entries can
1068occur in sequence.)
1069
1070### tar.types
1071
1072A translation table for the `type` field in tar headers.
1073
1074#### tar.types.name.get(code)
1075
1076Get the human-readable name for a given alphanumeric code.
1077
1078#### tar.types.code.get(name)
1079
1080Get the alphanumeric code for a given human-readable name.
Note: See TracBrowser for help on using the repository browser.