archiver vs jszip vs adm-zip vs zip-local
File Compression and Decompression Comparison
3 Years
archiverjszipadm-zipzip-localSimilar Packages:
What's File Compression and Decompression?

File compression and decompression libraries in Node.js provide developers with tools to create, read, and manipulate compressed files (like ZIP) programmatically. These libraries are essential for tasks such as reducing file sizes for storage or transmission, packaging multiple files into a single archive, or extracting files from existing archives. They support various compression formats and offer features like streaming, handling large files, and working with in-memory data. Popular libraries include adm-zip, archiver, jszip, and zip-local, each with unique features and use cases.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
archiver11,850,133
2,89943.1 kB153a year agoMIT
jszip10,883,874
10,134762 kB411-(MIT OR GPL-3.0-or-later)
adm-zip7,841,520
2,126121 kB149a year agoMIT
zip-local20,974
11957.1 kB13--
Feature Comparison: archiver vs jszip vs adm-zip vs zip-local

Compression and Decompression

  • archiver:

    archiver is primarily focused on creating ZIP files (compression) and supports streaming data to the archive. It does not provide decompression capabilities, so you would need another library for extracting files from ZIP archives.

  • jszip:

    jszip provides comprehensive support for both compression and decompression. You can create ZIP files, read existing ones, and manipulate their contents, including adding, removing, and modifying files within the archive.

  • adm-zip:

    adm-zip supports both compression (creating ZIP files) and decompression (extracting files from ZIP archives). It allows you to add files and directories to a ZIP archive easily and extract them with a few simple methods.

  • zip-local:

    zip-local offers both compression and decompression functionalities. You can create ZIP files from directories or files and extract their contents with a straightforward API.

Streaming Support

  • archiver:

    archiver supports streaming, making it efficient for creating large ZIP files without consuming excessive memory. It streams data to the archive in chunks, which is ideal for handling large files and directories.

  • jszip:

    jszip does not natively support streaming for writing ZIP files, but it can read ZIP files in a streaming manner. For writing, it requires the entire file data to be available, which can be a limitation for very large files.

  • adm-zip:

    adm-zip does not support streaming; it loads the entire ZIP file into memory, which can be a limitation for handling large files or archives. This makes it less efficient for memory-sensitive applications.

  • zip-local:

    zip-local does not support streaming. It reads and writes files in a non-streaming manner, which may lead to higher memory usage when working with large files or directories.

Ease of Use

  • archiver:

    archiver has a more complex API due to its streaming and customizable nature. While it offers great flexibility, it may require more time to understand and use effectively, especially for developers unfamiliar with streaming concepts.

  • jszip:

    jszip provides a user-friendly API for both creating and manipulating ZIP files. Its documentation is clear, and it supports various use cases, making it easy for developers to integrate ZIP functionality into their applications.

  • adm-zip:

    adm-zip is known for its simplicity and ease of use. Its API is intuitive, making it quick to learn and implement for basic ZIP file operations. It is well-suited for developers who need to perform ZIP operations without a steep learning curve.

  • zip-local:

    zip-local boasts a simple and straightforward API for zipping and unzipping files. Its minimalistic design makes it easy to use for quick tasks without any complicated setup.

Code Examples

  • archiver:

    archiver Example: Streaming ZIP Creation

    const fs = require('fs');
    const archiver = require('archiver');
    
    const output = fs.createWriteStream('output.zip');
    const archive = archiver('zip');
    
    output.on('close', () => {
      console.log(`Archive created: ${archive.pointer()} total bytes`);
    });
    
    archive.pipe(output);
    archive.append('Hello, World!', { name: 'hello.txt' });
    archive.directory('folder/', 'folder');
    archive.finalize();
    
  • jszip:

    jszip Example: Creating and Reading ZIP Files

    const JSZip = require('jszip');
    const fs = require('fs');
    
    const zip = new JSZip();
    zip.file('hello.txt', 'Hello, World!');
    zip.folder('folder').file('file.txt', 'Inside folder');
    
    zip.generateAsync({ type: 'nodebuffer' }).then((content) => {
      fs.writeFileSync('output.zip', content);
      console.log('ZIP file created.');
    
      // Read ZIP file
      JSZip.loadAsync(content).then((zip) => {
        zip.file('hello.txt').async('string').then((data) => {
          console.log('Extracted:', data);
        });
      });
    });
    
  • adm-zip:

    adm-zip Example: Creating and Extracting ZIP Files

    const AdmZip = require('adm-zip');
    
    // Create a new ZIP file
    const zip = new AdmZip();
    zip.addFile('hello.txt', Buffer.from('Hello, World!'));
    zip.addLocalFolder('folder');
    zip.writeZip('output.zip');
    
    // Extract ZIP file
    const extractedZip = new AdmZip('output.zip');
    extractedZip.extractAllTo('extracted/', true);
    
  • zip-local:

    zip-local Example: Simple Zipping and Unzipping

    const zipLocal = require('zip-local');
    const path = require('path');
    
    // Zip a directory
    zipLocal.zip(path.join(__dirname, 'folder'), (err, zip) => {
      if (err) throw err;
      zip.write('output.zip', () => {
        console.log('Directory zipped successfully.');
    
        // Unzip the file
        zipLocal.unzip('output.zip', (err, unzipped) => {
          if (err) throw err;
          console.log('Unzipped:', unzipped);
        });
      });
    });
    
How to Choose: archiver vs jszip vs adm-zip vs zip-local
  • archiver:

    Select archiver if you require a highly customizable and streaming solution for creating ZIP files. It is ideal for handling large files and directories, as it streams data instead of loading everything into memory, which helps reduce memory usage.

  • jszip:

    Opt for jszip if you need a versatile library for both creating and manipulating ZIP files in the browser and Node.js. It supports advanced features like adding files from Buffers, Streams, and Blobs, making it suitable for web applications that require client-side ZIP handling.

  • adm-zip:

    Choose adm-zip if you need a simple and straightforward library for reading and writing ZIP files. It is easy to use for quick tasks and supports in-memory operations, making it suitable for small to medium-sized projects.

  • zip-local:

    Use zip-local if you want a lightweight and easy-to-use library for creating and extracting ZIP files with minimal configuration. It is particularly useful for quick tasks and has a simple API for zipping and unzipping files and directories.

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.