archiver vs tar vs tar-fs vs tar-stream vs zip-stream
Node.js Compression Libraries
archivertartar-fstar-streamzip-streamSimilar Packages:

Node.js Compression Libraries

These libraries are used for creating and manipulating archive files in Node.js applications. They provide functionalities to compress and decompress files and directories, allowing developers to efficiently manage file storage and transfer. Each library has its own strengths and use cases, catering to different needs in file handling and archiving processes.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
archiver02,95343.1 kB1562 years agoMIT
tar09092.24 MB102 days agoBlueOak-1.0.0
tar-fs038218.2 kB121 days agoMIT
tar-stream043732.1 kB1825 days agoMIT
zip-stream01669.33 kB27a year agoMIT

Feature Comparison: archiver vs tar vs tar-fs vs tar-stream vs zip-stream

Supported Formats

  • archiver:

    Archiver supports multiple archive formats, including ZIP and TAR, making it a flexible choice for various use cases.

  • tar:

    Tar is specifically designed for creating and extracting TAR archives, focusing solely on this format.

  • tar-fs:

    Tar-fs works with TAR archives and integrates with the file system, allowing for direct file manipulation.

  • tar-stream:

    Tar-stream is tailored for streaming TAR files, providing a way to handle TAR archives in a more efficient manner.

  • zip-stream:

    Zip-stream is dedicated to creating ZIP archives and is optimized for streaming, allowing for efficient memory usage.

Streaming Capability

  • archiver:

    Archiver allows for streaming data into archives, making it suitable for applications that need to create archives on-the-fly without loading everything into memory.

  • tar:

    Tar does not support streaming; it is more suited for batch processing of files into TAR archives.

  • tar-fs:

    Tar-fs provides a file system interface that supports streaming, allowing you to read and write TAR files directly from the filesystem.

  • tar-stream:

    Tar-stream is designed for streaming, enabling you to process files as they are being added to or extracted from a TAR archive, which is beneficial for large files.

  • zip-stream:

    Zip-stream excels in streaming ZIP file creation, making it efficient for generating large ZIP files dynamically.

Ease of Use

  • archiver:

    Archiver has a straightforward API that is easy to use for creating and managing archives, making it beginner-friendly.

  • tar:

    Tar has a simple interface but may require more manual handling compared to higher-level libraries like Archiver.

  • tar-fs:

    Tar-fs offers a familiar file system interface, making it easy to integrate into applications that already work with the filesystem.

  • tar-stream:

    Tar-stream requires a bit more understanding of streams, which may have a steeper learning curve for beginners.

  • zip-stream:

    Zip-stream is user-friendly and designed for quick integration into applications, making it accessible for developers.

Performance

  • archiver:

    Archiver is optimized for performance, especially when handling large datasets or multiple files, due to its streaming capabilities.

  • tar:

    Tar is efficient for creating TAR files but may not be as performant as streaming libraries when dealing with large files.

  • tar-fs:

    Tar-fs provides good performance for filesystem operations but may not match the speed of pure streaming libraries.

  • tar-stream:

    Tar-stream is optimized for performance in streaming scenarios, allowing for efficient processing of large archives without excessive memory usage.

  • zip-stream:

    Zip-stream is designed for performance, particularly in scenarios where ZIP files need to be generated dynamically and efficiently.

Use Cases

  • archiver:

    Archiver is ideal for applications that require flexibility in archive formats and need to create archives on-the-fly, such as web applications that allow users to download multiple files as a single archive.

  • tar:

    Tar is best suited for scenarios where you need to create or extract TAR files, such as backup systems or software distribution.

  • tar-fs:

    Tar-fs is useful for applications that need to read and write TAR files directly from the filesystem, such as file management tools.

  • tar-stream:

    Tar-stream is perfect for applications that need to handle large datasets in a streaming manner, such as data processing pipelines.

  • zip-stream:

    Zip-stream is great for web applications that need to generate ZIP files dynamically for user downloads, ensuring efficient memory usage.

How to Choose: archiver vs tar vs tar-fs vs tar-stream vs zip-stream

  • archiver:

    Choose Archiver if you need a versatile library that supports both ZIP and TAR formats, along with the ability to stream data. It is ideal for creating archives on-the-fly and is well-suited for applications that require flexibility in output formats.

  • tar:

    Select Tar if you specifically need to work with TAR files and prefer a straightforward, no-frills approach. It is a simple library focused on creating and extracting TAR archives without additional features for other formats.

  • tar-fs:

    Opt for Tar-fs if you require a file system interface for TAR archives. This library allows you to work with streams and file systems directly, making it suitable for applications that need to read and write TAR files from the filesystem efficiently.

  • tar-stream:

    Use Tar-stream for a streaming approach to TAR file creation and extraction. It is designed for handling TAR files in a more granular way, allowing you to process files as they are being read or written, which is useful for large datasets.

  • zip-stream:

    Choose Zip-stream if you need a streaming interface for creating ZIP archives. This library is optimized for performance and memory usage, making it ideal for applications that need to generate ZIP files dynamically.

README for archiver

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.