archiver vs compressing vs tar vs tar-stream vs zip-stream
Node.js Compression Libraries
archivercompressingtartar-streamzip-streamSimilar Packages:

Node.js Compression Libraries

These libraries provide various functionalities for creating and extracting compressed files in different formats. They are essential for managing file sizes, improving transfer speeds, and organizing related files into single archives. Each library has its unique strengths, making them suitable for different use cases in web development, such as packaging files for download, creating backups, or transferring data efficiently over networks.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
archiver02,94543.1 kB1552 years agoMIT
compressing045553.6 kB49a month agoMIT
tar09042.25 MB1010 days agoBlueOak-1.0.0
tar-stream043632 kB172 years agoMIT
zip-stream01669.33 kB27a year agoMIT

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

Supported Formats

  • archiver:

    Archiver supports multiple archive formats including ZIP, TAR, and others, making it a flexible choice for various compression needs.

  • compressing:

    Compressing supports several formats such as ZIP, GZIP, and TAR, providing a wide range of options for file compression.

  • tar:

    Tar is specifically designed for creating and extracting TAR files, making it the go-to choice for handling this particular format.

  • tar-stream:

    Tar-Stream focuses solely on TAR format, allowing for efficient streaming of TAR archives without needing to load the entire archive into memory.

  • zip-stream:

    Zip-Stream is tailored for creating ZIP files, allowing for efficient streaming and dynamic generation of ZIP archives.

Streaming Support

  • archiver:

    Archiver provides streaming capabilities for both input and output, allowing you to create archives on-the-fly, which is beneficial for large files or datasets.

  • compressing:

    Compressing offers streaming support, enabling you to compress and decompress files in a memory-efficient manner, which is essential for handling large data volumes.

  • tar:

    Tar does not inherently support streaming; it focuses on straightforward creation and extraction of TAR files without advanced streaming features.

  • tar-stream:

    Tar-Stream excels in streaming, allowing you to read and write TAR files in a streaming fashion, which is ideal for large files or when working with network streams.

  • zip-stream:

    Zip-Stream is designed for streaming ZIP file creation, allowing you to write files directly to the output stream, minimizing memory usage.

Performance

  • archiver:

    Archiver is optimized for performance, balancing speed and compression ratio, making it suitable for applications that require efficient archiving.

  • compressing:

    Compressing is focused on performance, providing fast compression and decompression speeds, especially beneficial for large files or high-volume data processing.

  • tar:

    Tar is efficient for creating and extracting TAR files, but performance can vary based on the size of the files being processed.

  • tar-stream:

    Tar-Stream is efficient for streaming operations, but overall performance may depend on the complexity and size of the data being streamed.

  • zip-stream:

    Zip-Stream is optimized for performance in ZIP file creation, allowing for quick generation of large ZIP files without excessive memory usage.

Ease of Use

  • archiver:

    Archiver has a user-friendly API that simplifies the process of creating and managing archives, making it accessible for developers of all skill levels.

  • compressing:

    Compressing offers a straightforward API, making it easy to implement compression in your projects without extensive configuration.

  • tar:

    Tar has a simple API for creating and extracting TAR files, making it easy to use for basic archiving needs.

  • tar-stream:

    Tar-Stream has a more complex API due to its streaming nature, which may require a deeper understanding of streams and buffers.

  • zip-stream:

    Zip-Stream provides a simple API for streaming ZIP file creation, making it relatively easy to use for developers familiar with Node.js streams.

Community and Support

  • archiver:

    Archiver has a large community and good documentation, providing ample resources for troubleshooting and support.

  • compressing:

    Compressing has a growing community with decent documentation, though it may not be as extensive as some of the more established libraries.

  • tar:

    Tar is widely used and has a strong community, ensuring good support and resources for users.

  • tar-stream:

    Tar-Stream has a smaller community, but it is well-documented, making it easier to find help when needed.

  • zip-stream:

    Zip-Stream has a moderate community presence and documentation, providing enough resources for most common use cases.

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

  • archiver:

    Choose Archiver if you need a versatile library that supports multiple formats (ZIP, TAR, etc.) and offers a simple API for creating archives. It is ideal for applications that require both compression and streaming capabilities.

  • compressing:

    Select Compressing if you require a library that supports various compression formats and is focused on performance. It is particularly useful for projects that need fast compression and decompression processes, especially with large files.

  • tar:

    Opt for Tar if your primary focus is on handling TAR archives. It is straightforward and efficient for creating and extracting TAR files, making it a great choice for Unix-based environments or when working with tarballs.

  • tar-stream:

    Use Tar-Stream when you need a streaming interface for creating and consuming TAR files. This library is perfect for scenarios where you want to process files on-the-fly without needing to store the entire archive in memory, which is beneficial for large datasets.

  • zip-stream:

    Choose Zip-Stream if you need a library that allows you to create ZIP files in a streaming manner. This is particularly useful for generating large ZIP files dynamically, as it minimizes memory usage by writing data directly to the output stream.

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.