archiver
a streaming interface for archive generation
Last updated 7 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install archiver 
SYNC missed versions from official npm registry.

Archiver

A streaming interface for archive generation

Visit the API documentation for a list of all methods available.

Install

npm install archiver --save

Quick Start

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.

Current Tags

  • 0.15.0-1                                ...           canary (11 years ago)
  • 8.0.0                                ...           latest (7 months ago)

84 Versions

  • 8.0.0                                ...           7 months ago
  • 7.0.1                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.3.2                                ...           3 years ago
  • 5.3.1                                ...           5 years ago
  • 5.3.0                                ...           6 years ago
  • 5.2.0                                ...           6 years ago
  • 5.1.0                                ...           6 years ago
  • 5.0.2                                ...           6 years ago
  • 5.0.1                                ...           6 years ago
  • 5.0.0                                ...           6 years ago
  • 4.0.2                                ...           6 years ago
  • 4.0.1                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.1.1                                ...           7 years ago
  • 3.1.0                                ...           7 years ago
  • 3.0.3                                ...           7 years ago
  • 3.0.1                                ...           7 years ago
  • 3.0.0                                ...           8 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.3                                ...           9 years ago
  • 2.0.2                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           11 years ago
  • 0.21.0                                ...           11 years ago
  • 0.20.0                                ...           11 years ago
  • 0.19.0                                ...           11 years ago
  • 0.18.0                                ...           11 years ago
  • 0.17.0                                ...           11 years ago
  • 0.16.0                                ...           11 years ago
  • 0.15.1                                ...           11 years ago
  • 0.15.0                                ...           11 years ago
  • 0.15.0-1                                ...           11 years ago
  • 0.14.4                                ...           12 years ago
  • 0.14.3                                ...           12 years ago
  • 0.14.2                                ...           12 years ago
  • 0.14.1                                ...           12 years ago
  • 0.14.0                                ...           12 years ago
  • 0.13.1                                ...           12 years ago
  • 0.13.0                                ...           12 years ago
  • 0.12.0                                ...           12 years ago
  • 0.11.0                                ...           12 years ago
  • 0.11.0-alpha                                ...           12 years ago
  • 0.10.1                                ...           12 years ago
  • 0.10.0                                ...           12 years ago
  • 0.10.0-alpha                                ...           13 years ago
  • 0.9.1                                ...           13 years ago
  • 0.9.0                                ...           13 years ago
  • 0.8.1                                ...           13 years ago
  • 0.8.0                                ...           13 years ago
  • 0.7.1                                ...           13 years ago
  • 0.7.0                                ...           13 years ago
  • 0.6.1                                ...           13 years ago
  • 0.6.0                                ...           13 years ago
  • 0.5.2                                ...           13 years ago
  • 0.5.1                                ...           13 years ago
  • 0.5.0                                ...           13 years ago
  • 0.5.0-alpha                                ...           13 years ago
  • 0.4.10                                ...           13 years ago
  • 0.4.9                                ...           13 years ago
  • 0.4.8                                ...           13 years ago
  • 0.4.7                                ...           13 years ago
  • 0.4.6                                ...           13 years ago
  • 0.4.5                                ...           13 years ago
  • 0.4.4                                ...           13 years ago
  • 0.4.3                                ...           14 years ago
  • 0.4.2                                ...           14 years ago
  • 0.4.1                                ...           14 years ago
  • 0.4.0                                ...           14 years ago
  • 0.3.0                                ...           14 years ago
  • 0.2.2                                ...           14 years ago
  • 0.2.1                                ...           14 years ago
  • 0.2.0                                ...           14 years ago
  • 0.1.1                                ...           14 years ago
  • 0.1.0                                ...           14 years ago
Maintainers (1)
Downloads
Total 218
Today 0
This Week 32
This Month 130
Last Day 0
Last Week 4
Last Month 1
Dependencies (9)
Dev Dependencies (10)

© 2010 - cnpmjs.org x YWFE | Home | YWFE