# node-tar
[![Build Status](https://travis-ci.org/npm/node-tar.svg?branch=master)](https://travis-ci.org/npm/node-tar)
[Fast](./benchmarks) and full-featured Tar for Node.js
The API is designed to mimic the behavior of `tar(1)` on unix systems.
If you are familiar with how tar works, most of this will hopefully be
straightforward for you. If not, then hopefully this module can teach
you useful unix skills that may come in handy someday :)
## Background
A "tar file" or "tarball" is an archive of file system entries
(directories, files, links, etc.) The name comes from "tape archive".
If you run `man tar` on almost any Unix command line, you'll learn
quite a bit about what it can do, and its history.
Tar has 5 main top-level commands:
* `c` Create an archive
* `r` Replace entries within an archive
* `u` Update entries within an archive (ie, replace if they're newer)
* `t` List out the contents of an archive
* `x` Extract an archive to disk
The other flags and options modify how this top level function works.
## High-Level API
These 5 functions are the high-level API. All of them have a
single-character name (for unix nerds familiar with `tar(1)`) as well
as a long name (for everyone else).
All the high-level functions take the following arguments, all three
of which are optional and may be omitted.
1. `options` - An optional object specifying various options
2. `paths` - An array of paths to add or extract
3. `callback` - Called when the command is completed, if async. (If
sync or no file specified, providing a callback throws a
`TypeError`.)
If the command is sync (ie, if `options.sync=true`), then the
callback is not allowed, since the action will be completed immediately.
If a `file` argument is specified, and the command is async, then a
`Promise` is returned. In this case, if async, a callback may be
provided which is called when the command is completed.
If a `file` option is not specified, then a stream is returned. For
`create`, this is a readable stream of the generated archive. For
`list` and `extract` this is a writable stream that an archive should
be written into. If a file is not specified, then a callback is not
allowed, because you're already getting a stream to work with.
`replace` and `update` only work on existing archives, and so require
a `file` argument.
Sync commands without a file argument return a stream that acts on its
input immediately in the same tick. For readable streams, this means
that all of the data is immediately available by calling
`stream.read()`. For writable streams, it will be acted upon as soon
as it is provided, but this can be at any time.
### Warnings
Some things cause tar to emit a warning, but should usually not cause
the entire operation to fail. There are three ways to handle
warnings:
1. **Ignore them** (default) Invalid entries won't be put in the
archive, and invalid entries won't be unpacked. This is usually
fine, but can hide failures that you might care about.
2. **Notice them** Add an `onwarn` function to the options, or listen
to the `'warn'` event on any tar stream. The function will get
called as `onwarn(message, data)`. Handle as appropriate.
3. **Explode them.** Set `strict: true` in the options object, and
`warn` messages will be emitted as `'error'` events instead. If
there's no `error` handler, this causes the program to crash. If
used with a promise-returning/callback-taking method, then it'll
send the error to the promise/callback.
### Examples
The API mimics the `tar(1)` command line functionality, with aliases
for more human-readable option and function names. The goal is that
if you know how to use `tar(1)` in Unix, then you know how to use
`require('tar')` in JavaScript.
To replicate `tar czf my-tarball.tgz files and folders`, you'd do:
```js
tar.c(
{
gzip: <true|gzip options>,
file: 'my-tarball.tgz'
},
['some', 'files', 'and', 'folders']
).then(_ => { .. tarball has been created .. })
```
To replicate `tar cz files and folders > my-tarball.tgz`, you'd do:
```js
tar.c( // or tar.create
{
gzip: <true|gzip options>
},
['some', 'files', 'and', 'folders']
).pipe(fs.createWriteStream('my-tarball.tgz'))
```
To replicate `tar xf my-tarball.tgz` you'd do:
```js
tar.x( // or tar.extract(
{
file: 'my-tarball.tgz'
}
).then(_=> { .. tarball has been dumped in cwd .. })
```
To replicate `cat my-tarball.tgz | tar x -C some-dir --strip=1`:
```js
fs.createReadStream('my-tarball.tgz').pipe(
tar.x({
strip: 1,
C: 'some-dir' // alias for cwd:'some-dir', also ok
})
)
```
To replicate `tar tf my-tarball.tgz`, do this:
```js
tar.t({
file: 'my-tarball.tgz',
onentry: entry => { .. do whatever with it .. }
})
```
To replicate `cat my-tarball.tgz | tar t` do:
```js
fs.createReadStream('my-tarball.tgz')
.pipe(tar.t())
.on('entry', entry => { .. do whatever with it .. })
```
To do anything synchronous, add `sync: true` to the options. Note
that sync functions don't take a callback and don't return a promise.
When the function returns, it's already done. Sync methods without a
file argument return a sync stream, which flushes immediately. But,
of course, it still won't be done until you `.end()` it.
To filter entries, add `filter: <function>` to the options.
Tar-creating methods call the filter with `filter(path, stat)`.
Tar-reading methods (including extraction) call the filter with
`filter(path, entry)`. The filter is called in the `this`-context of
the `Pack` or `Unpack` stream object.
The arguments list to `tar t` and `tar x` specify a list of filenames
to extract or list, so they're equivalent to a filter that tests if
the file is in the list.
For those who _aren't_ fans of tar's single-character command names:
```
tar.c === tar.create
tar.r === tar.replace (appends to archive, file is required)
tar.u === tar.update (appends if newer, file is required)
tar.x === tar.extract
tar.t === tar.list
```
Keep reading for all the command descriptions and options, as well as
the low-level API that they are built on.
### tar.c(options, fileList, callback) [alias: tar.create]
Create a tarball archive.
The `fileList` is an array of paths to add to the tarball. Adding a
directory also adds its children recursively.
An entry in `fileList` that starts with an `@` symbol is a tar archive
whose entries will be added. To add a file that starts with `@`,
prepend it with `./`.
The following options are supported:
- `file` Write the tarball archive to the specified filename. If this
is specified, then the callback will be fired when the file has been
written, and a promise will be returned that resolves when the file
is written. If a filename is not specified, then a Readable Stream
will be returned which will emit the file data. [Alias: `f`]
- `sync` Act synchronously. If this is set, then any provided file
will be fully written after the call to `tar.c`. If this is set,
and a file is not provided, then the resulting stream will already
have the data ready to `read` or `emit('data')` as soon as you
request it.
- `onwarn` A function that will get called with `(message, data)` for
any warnings encountered.
- `strict` Treat warnings as crash-worthy errors. Default false.
- `cwd` The current working directory for creating the archive.
Defaults to `process.cwd()`. [Alias: `C`]
- `prefix` A path portion to prefix onto the entries in the archive.
- `gzip` Set to any truthy value to create a gzipped archive, or an
object with settings for `zlib.Gzip()` [Alias: `z`]
- `filter` A function that gets called with `(path, stat)` for each
entry being added. Return `true` to add the entry to the archive,
or `false` to omit it.
- `portable` Omit metadata that is system-specific: `ctime`, `atime`,
`uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
that `mtime` is still included, because this is necessary other
time-based operations.
- `prese
没有合适的资源?快使用搜索试试~ 我知道了~
任务发布系统vue+element+node.zip
共2003个文件
js:1570个
md:246个
json:139个
0 下载量 185 浏览量
2024-08-29
10:18:35
上传
评论
收藏 5.03MB ZIP 举报
温馨提示
项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全栈开发),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助 【资源内容】:项目具体内容可查看/点击本页面下方的*资源详情*,包含完整源码+工程文件+说明(若有)等。【若无VIP,此资源可私信获取】 【本人专注IT领域】:有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为您提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【适合场景】:相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可基于此项目来扩展开发出更多功能 #注 1. 本资源仅用于开源学习和技术交流。不可商用等,一切后果由使用者承担 2. 部分字体及插图等来自网络,若是侵权请联系删除,本人不对所涉及的版权问题或内容负法律责任。收取的费用仅用于整理和收集资料耗费时间的酬劳 3. 积分资源不提供使用问题指导/解答
资源推荐
资源详情
资源评论
收起资源包目录
任务发布系统vue+element+node.zip (2003个子文件)
前端小组四项目需求说明书-1565847763391.docx 183KB
.DS_Store 8KB
.DS_Store 8KB
.DS_Store 6KB
nan.h 84KB
nan_callbacks_12_inl.h 17KB
nan_callbacks_pre_12_inl.h 17KB
nan_weak.h 15KB
nan_implementation_12_inl.h 15KB
nan_maybe_43_inl.h 12KB
nan_new.h 9KB
nan_maybe_pre_43_inl.h 8KB
nan_string_bytes.h 8KB
nan_implementation_pre_12_inl.h 8KB
nan_persistent_pre_12_inl.h 6KB
nan_json.h 6KB
node_blf.h 4KB
nan_object_wrap.h 4KB
nan_persistent_12_inl.h 4KB
nan_callbacks.h 3KB
nan_typedarray_contents.h 3KB
nan_converters_43_inl.h 3KB
nan_private.h 2KB
nan_converters.h 2KB
nan_converters_pre_43_inl.h 1KB
nan_define_own_property_helper.h 1KB
index.html 542B
index.html 401B
lodash.js 528KB
bluebird.js 175KB
bluebird.core.js 117KB
core.js 112KB
index.js 93KB
collection.js 92KB
mime-types.js 88KB
mquery.js 80KB
bluebird.min.js 78KB
lodash.min.js 72KB
grid_store.js 64KB
index.js 58KB
bluebird.core.min.js 54KB
collection_ops.js 52KB
replset.js 46KB
db.js 45KB
index.js 42KB
mongos.js 41KB
semver.js 38KB
pool.js 37KB
cursor.js 36KB
db_ops.js 33KB
topology.js 33KB
post_data_spec.js 32KB
sbcs-data-generated.js 31KB
sbcs-data-generated.js 31KB
sbcs-data-generated.js 31KB
replset_state.js 31KB
_stream_readable.js 31KB
common.js 30KB
server.js 29KB
debuggability.js 29KB
needle.js 26KB
debug.js 26KB
promise.js 25KB
mongo_client.js 24KB
cursor.js 23KB
index.js 23KB
response.js 22KB
dbcs-codec.js 21KB
dbcs-codec.js 21KB
dbcs-codec.js 21KB
sessions.js 21KB
index.js 21KB
utils.js 21KB
url_parser.js 20KB
_stream_writable.js 20KB
index.js 20KB
uri_parser.js 20KB
mongo_client_ops.js 19KB
ipaddr.js 19KB
connection.js 18KB
index.js 18KB
unpack.js 16KB
change_stream.js 16KB
_baseConvert.js 16KB
replset.js 16KB
commands.js 16KB
tests.js 15KB
versioning.js 15KB
mongos.js 15KB
server.js 15KB
index.js 14KB
1to2.js 14KB
index.js 14KB
application.js 13KB
parsing_spec.js 13KB
upload.js 13KB
topology_description.js 13KB
index.js 13KB
index.js 13KB
index.js 12KB
共 2003 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
热爱技术。
- 粉丝: 2436
- 资源: 7862
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 1731260448754.jpeg
- 博图 博途1s保护解除DLL Siemens.Automation.AdvancedProtection.dll
- 基于Java和Shell语言的csj_21_08_20_task1设计源码分享
- 基于Typescript和Python的MNIST卷积神经网络模型加载与预测浏览器端设计源码
- 基于Python的RasaTalk语音对话语义分析系统源码
- 基于Vue框架的租车平台前端设计源码
- 基于Java和C/C++的浙江高速反扫优惠券码830主板设计源码
- 基于Java的一站式退休服务项目源码设计
- 基于Java语言实现的鼎鸿餐厅管理系统设计源码
- 基于Java的iText扩展库:简化PDF创建与中文字体应用设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功