# node-tar
Fast 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 and Errors
Tar emits warnings and errors for recoverable and unrecoverable situations,
respectively. In many cases, a warning only affects a single entry in an
archive, or is simply informing you that it's modifying an entry to comply
with the settings provided.
Unrecoverable warnings will always raise an error (ie, emit `'error'` on
streaming actions, throw for non-streaming sync actions, reject the
returned Promise for non-streaming async operations, or call a provided
callback with an `Error` as the first argument). Recoverable errors will
raise an error only if `strict: true` is set in the options.
Respond to (recoverable) warnings by listening to the `warn` event.
Handlers receive 3 arguments:
- `code` String. One of the error codes below. This may not match
`data.code`, which preserves the original error code from fs and zlib.
- `message` String. More details about the error.
- `data` Metadata about the error. An `Error` object for errors raised by
fs and zlib. All fields are attached to errors raisd by tar. Typically
contains the following fields, as relevant:
- `tarCode` The tar error code.
- `code` Either the tar error code, or the error code set by the
underlying system.
- `file` The archive file being read or written.
- `cwd` Working directory for creation and extraction operations.
- `entry` The entry object (if it could be created) for `TAR_ENTRY_INFO`,
`TAR_ENTRY_INVALID`, and `TAR_ENTRY_ERROR` warnings.
- `header` The header object (if it could be created, and the entry could
not be created) for `TAR_ENTRY_INFO` and `TAR_ENTRY_INVALID` warnings.
- `recoverable` Boolean. If `false`, then the warning will emit an
`error`, even in non-strict mode.
#### Error Codes
* `TAR_ENTRY_INFO` An informative error indicating that an entry is being
modified, but otherwise processed normally. For example, removing `/` or
`C:\` from absolute paths if `preservePaths` is not set.
* `TAR_ENTRY_INVALID` An indication that a given entry is not a valid tar
archive entry, and will be skipped. This occurs when:
- a checksum fails,
- a `linkpath` is missing for a link type, or
- a `linkpath` is provided for a non-link type.
If every entry in a parsed archive raises an `TAR_ENTRY_INVALID` error,
then the archive is presumed to be unrecoverably broken, and
`TAR_BAD_ARCHIVE` will be raised.
* `TAR_ENTRY_ERROR` The entry appears to be a valid tar archive entry, but
encountered an error which prevented it from being unpacked. This occurs
when:
- an unrecoverable fs error happens during unpacking,
- an entry has `..` in the path and `preservePaths` is not set, or
- an entry is extracting through a symbolic link, when `preservePaths` is
not set.
* `TAR_ENTRY_UNSUPPORTED` An indication that a given entry is
a valid archive entry, but of a type that is unsupported, and so will be
skipped in archive creation or extracting.
* `TAR_ABORT` When parsing gzipped-encoded archives, the parser will
abort the parse process raise a warning for any zlib errors encountered.
Aborts are considered unrecoverable for both parsing and unpacking.
* `TAR_BAD_ARCHIVE` The archive file is totally hosed. This can happen for
a number of reasons, and always occurs at the end of a parse or extract:
- An entry body was truncated before seeing the full number of bytes.
- The archive contained only invalid entries, indicating that it is
likely not an archive, or at least, not an archive this library can
parse.
`TAR_BAD_ARCHIVE` is considered informative for parse operations, but
unrecoverable for extraction. Note that, if encountered at the end of an
extraction, tar WILL still have extracted as much it could from the
archive, so there may be some garbage files to clean up.
Errors that occur deeper in the system (ie, either the filesystem or zlib)
will have their error codes left intact, and a `tarCode` matching one of
the above will be added to the warning metadata or the raised error object.
Errors generated by tar will have one of the above codes set as the
`error.code` field as well, but since errors originating in zlib or fs will
have their original codes, it's better to read `error.tarCode` if you wish
to see how tar is handling the issue.
### 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 thi
没有合适的资源?快使用搜索试试~ 我知道了~
大三实训的企业内部培训系统,springboot+springcloudAlibaba+uniapp的微服务架构zhkt.zip
共2001个文件
js:984个
java:301个
md:290个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 82 浏览量
2024-05-20
23:44:17
上传
评论
收藏 38.04MB ZIP 举报
温馨提示
该项目利用了基于springboot + vue + mysql的开发模式框架实现的课设系统,包括了项目的源码资源、sql文件、相关指引文档等等。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【技术】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes
资源推荐
资源详情
资源评论
收起资源包目录
大三实训的企业内部培训系统,springboot+springcloudAlibaba+uniapp的微服务架构zhkt.zip (2001个子文件)
demo.css 8KB
base.css 5KB
base.css 1KB
prettify.css 676B
iconfont.css 475B
.DS_Store 6KB
nan.h 87KB
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_string_bytes.h 8KB
nan_implementation_pre_12_inl.h 8KB
nan_maybe_pre_43_inl.h 7KB
nan_persistent_pre_12_inl.h 6KB
nan_json.h 6KB
nan_object_wrap.h 4KB
nan_persistent_12_inl.h 4KB
nan_callbacks.h 3KB
nan_typedarray_contents.h 3KB
nan_scriptorigin.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
demo_index.html 10KB
index.html 3KB
index.html 3KB
index.js.html 2KB
index.html 454B
index.html 269B
CourseServiceImpl.java 55KB
ClassServiceImpl.java 28KB
ProgressServiceImpl.java 27KB
Convert.java 24KB
WenDaServiceImpl.java 23KB
TeacherPracticeServiceImpl.java 20KB
CourseController.java 17KB
StudentServiceImpl.java 16KB
InforServiceImpl.java 14KB
WenDaController.java 11KB
StuController.java 10KB
StudentPracticeServiceImpl.java 10KB
StringUtils.java 9KB
AdminServiceImpl.java 9KB
InformationController.java 9KB
StudentClockServiceImpl.java 9KB
ProgressController.java 9KB
ClassController.java 8KB
TeacherChapterServiceImpl.java 7KB
TeaController.java 7KB
TeacherServiceImpl.java 6KB
TeacherPracticeController.java 6KB
FileDataSourceInit.java 6KB
SnowflakeIdWorker.java 6KB
IpUtil.java 5KB
StuLearningProServiceImpl.java 5KB
CourseMapper.java 5KB
GlobalExceptionHandler.java 4KB
AdminController.java 4KB
ProgressMapper.java 4KB
MailServiceImpl.java 4KB
DateUtils.java 4KB
StuCourseProServiceImpl.java 4KB
NoticeServiceImpl.java 4KB
TokenCheckFilter.java 4KB
QiniuService.java 4KB
QiniuService.java 4KB
QiniuService.java 4KB
QiniuService.java 4KB
QiniuService.java 4KB
CartServiceImpl.java 3KB
CourseService.java 3KB
StrFormatter.java 3KB
ServletUtils.java 3KB
CourseDetailedVO.java 3KB
IssueVO.java 3KB
CartController.java 3KB
BaseSwaggerConfig.java 3KB
RemoteUserService.java 3KB
WenDaMapper.java 3KB
RemoteUserFallbackFactory.java 3KB
InterlocutionVO.java 3KB
SpringUtils.java 3KB
InforMapper.java 3KB
StudentClockController.java 3KB
TeacherChapterController.java 3KB
StudentPracticeController.java 3KB
Course.java 3KB
RemoteCourseFallbackFactory.java 3KB
RemoteCourseService.java 3KB
MailController.java 2KB
Interlocution.java 2KB
MyUrlBlockHandler.java 2KB
Durations.java 2KB
CharsetKit.java 2KB
InforVO.java 2KB
共 2001 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
枫蜜柚子茶
- 粉丝: 8978
- 资源: 5351
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功