Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/archiverjs/node-archiver
a streaming interface for archive generation
https://github.com/archiverjs/node-archiver
archiver javascript nodejs tar zip
Last synced: 3 days ago
JSON representation
a streaming interface for archive generation
- Host: GitHub
- URL: https://github.com/archiverjs/node-archiver
- Owner: archiverjs
- License: mit
- Created: 2012-10-09T05:00:56.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-10-25T07:32:41.000Z (about 2 months ago)
- Last Synced: 2024-10-29T13:07:19.818Z (about 1 month ago)
- Topics: archiver, javascript, nodejs, tar, zip
- Language: JavaScript
- Homepage: https://www.archiverjs.com
- Size: 1.12 MB
- Stars: 2,816
- Watchers: 29
- Forks: 220
- Open Issues: 148
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nodejs-cn - Archiver - 流式接口的文件归档工具,支持 ZIP 和 TAR 格式 (包 / 压缩)
- awesome-web-cn - node-archiver - 一个用于 node.js 的压缩文件的库,支持 zip 和 rar 压缩 (Uncategorized / Uncategorized)
- awesome-nodejs - Archiver - JavaScript 压缩工具。 ![](https://img.shields.io/github/stars/archiverjs/node-archiver.svg?style=social&label=Star) (GIT 仓库 / 压缩解压)
- awesome-nodejs - Archiver - Streaming interface for archive generation, supporting ZIP and TAR. (Packages / Compression)
- awesome-nodejs - node-archiver - a streaming interface for archive generation - ★ 1395 (Compression)
- awesome-node - Archiver - Streaming interface for archive generation, supporting ZIP and TAR. (Packages / Compression)
- awesome-nodejs-cn - Archiver - 用于生成存档文件的流接口,支持ZIP和TAR. (目录 / 压缩)
- awesome-nodejs-cn - Archiver - **star:2818** 流接口的存档生成,支持ZIP和TAR ![star > 2000][Awesome] (包 / 压缩)
README
# Archiver
A streaming interface for archive generation
Visit the [API documentation](https://www.archiverjs.com/) for a list of all methods available.
## Install
```bash
npm install archiver --save
```## Quick Start
```js
import fs from "fs";
import { ZipArchive } from "archiver";// create a file to stream archive data to.
const output = fs.createWriteStream(__dirname + "/example.zip");
const archive = new ZipArchive({
zlib: { level: 9 }, // Sets the compression level.
});// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(
"archiver has been finalized and the output file descriptor has closed.",
);
});// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on("end", function () {
console.log("Data has been drained");
});// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on("warning", function (err) {
if (err.code === "ENOENT") {
// log warning
} else {
// throw error
throw err;
}
});// good practice to catch this error explicitly
archive.on("error", function (err) {
throw err;
});// pipe archive data to the file
archive.pipe(output);// append a file from stream
const file1 = __dirname + "/file1.txt";
archive.append(fs.createReadStream(file1), { name: "file1.txt" });// append a file from string
archive.append("string cheese!", { name: "file2.txt" });// append a file from buffer
const buffer3 = Buffer.from("buff it!");
archive.append(buffer3, { name: "file3.txt" });// append a file
archive.file("file1.txt", { name: "file4.txt" });// append files from a sub-directory and naming it `new-subdir` within the archive
archive.directory("subdir/", "new-subdir");// append files from a sub-directory, putting its contents at the root of archive
archive.directory("subdir/", false);// append files from a glob pattern
archive.glob("file*.txt", { cwd: __dirname });// finalize the archive (ie we are done appending files but streams have to finish yet)
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
archive.finalize();
```## Formats
Archiver ships with out of the box support for TAR and ZIP archives.