# 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
Vite+vue3+ts 项目初始化底座
需积分: 0 112 浏览量
更新于2023-02-21
收藏 55.49MB ZIP 举报
:“Vite+vue3+ts 项目初始化底座”
在现代Web开发中,开发者经常寻求高效、快速的工具来构建Vue.js应用程序。Vite,由Vue.js作者尤雨溪开发,正逐渐成为这样的首选工具。它利用了最新的浏览器原生特性,提供了热模块替换(HMR)和快速的开发体验。而Vue 3,则是Vue.js框架的最新版本,带来了性能提升、更强大的功能以及优化的API。TypeScript(简称ts)作为JavaScript的超集,为项目增加了静态类型检查,提高了代码质量和可维护性。本文将详细讲解如何使用Vite、Vue 3和TypeScript初始化一个项目底座。
**1. Vite介绍**
Vite是基于ES模块的前端构建工具,它在开发环境中利用浏览器的原生模块加载能力,跳过了传统构建工具的打包步骤,实现了快速启动和热更新。Vite支持Vue单文件组件(SFC)和Vue 3,同时也兼容其他库和框架。
**2. Vue 3新特性**
Vue 3引入了许多改进,如Composition API,它允许开发者更灵活地组织和复用逻辑;Teleport提供了一种将元素渲染到DOM树其他位置的方法;Suspense则用于处理异步组件的加载状态。此外,Vue 3还优化了性能,减少了内存占用,并引入了更多优化工具。
**3. TypeScript整合**
TypeScript与Vue 3的结合使得项目具有更好的类型安全,避免了运行时错误。Vue 3的选项API和Composition API都支持TypeScript,可以自动生成类型定义,帮助开发者编写更可靠的代码。
**4. 初始化Vite项目**
确保安装Node.js和npm。然后,通过npm全局安装Vite:
```
npm install -g create-vite
```
接着,创建一个新的Vue 3项目,同时指定使用TypeScript:
```
create-vite my-vue3-ts-project --template vue
cd my-vue3-ts-project
```
这将生成一个基础的Vue 3 + TypeScript的项目结构。
**5. 配置Vite**
在`vite.config.ts`中,可以配置Vue 3和TypeScript的相关选项,例如设置别名、优化编译设置等。
**6. 开发环境与生产构建**
使用Vite的`dev`命令启动开发服务器:
```
npm run dev
```
完成开发后,通过`build`命令进行生产构建:
```
npm run build
```
Vite会自动处理优化,包括代码分割、压缩等。
**7. 结合Vue 3的特性**
利用Vue 3的Composition API,可以在组件中按需导入和组合逻辑。同时,利用Teleport可以在模板中将部分内容渲染到页面的特定位置。
**8. 测试和调试**
Vite内置了对Jest的支持,可以轻松地为项目添加单元测试。同时,由于Vite的HMR特性,调试过程更加高效。
"Vite+vue3+ts 项目初始化底座"是一个现代前端开发的良好起点,它结合了Vite的快速开发、Vue 3的先进特性以及TypeScript的类型安全性,为开发者提供了高效、稳定且易于维护的项目基础。

小储今天暴富了
- 粉丝: 1801
最新资源
- MPC模型预测控制在Matlab Simulink与Carsim联合仿真的参数配置及应用
- 以太网PHY电路设计详析:基于Gpdk90nm与Gpdk180nm工艺的系统级电路设计及关键模块解析
- MATLAB仿真光伏电池12V升压至48V双闭环Boost电路控制策略及9A电流输出
- 三相全桥型并联APF有源电力滤波器的PI与重复控制及SVPWM调制仿真研究 完整版
- 光伏板太阳能充电MATLAB仿真与双闭环控制Boost电路研究
- 永磁同步电机三矢量模型预测电流控制:基于PI控制器的电流给定与期望电压矢量合成优化
- 基于蜣螂优化算法求解分布式置换流水车间调度问题及其应用 详细版
- 定位助手_202507251.apk
- 基于蜣螂优化算法求解置换流水车间调度问题(PFSP)并绘制甘特图 智能优化算法
- MATLAB环境下振动与声音信号解卷积方法研究:冲击信号提取及工程应用
- 基于MI-UKF多新息无迹卡尔曼滤波的电池电量SOC估算方法与性能研究
- 永磁同步电机双矢量MPC模型预测电流控制:提升动态性能与减少电流波动的技术解析
- 利用星鸦优化算法(NOA)求解FJSP问题及'MK01'算例甘特图演示
- 基于遗传算法求解混合流水车间调度问题的MATLAB实现及甘特图展示
- 基于ADRC控制的半车主动悬架建模及其与PID控制效果对比的研究 - MATLABSimulink v3.5
- PVD真空预压与FLAC3D数值模拟:四根竖向排水板在软土地基处理中的应用研究 - PVD真空预压