archiver
Creates Archives (ZIP) via Node Streams.
Last updated 12 years ago by ctalkington .
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

// require modules
const fs = require('fs');
const archiver = require('archiver');

// create a file to stream archive data to.
const output = fs.createWriteStream(__dirname + '/example.zip');
const archive = archiver('zip', {
  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.

You can register additional formats with registerFormat.

You can check if format already exists before to register a new one with isRegisteredFormat.

Current Tags

  • 0.15.0-1                                ...           canary (10 years ago)
  • 7.0.1                                ...           latest (9 months ago)

83 Versions

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

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