archiver vs jszip vs adm-zip vs zip-a-folder vs node-zip vs zip-local
File Compression and Archiving
archiverjszipadm-zipzip-a-foldernode-zipzip-localSimilar Packages:
File Compression and Archiving

File compression and archiving libraries in Node.js provide developers with tools to create, manipulate, and extract compressed files and archives, such as ZIP files. These libraries help optimize storage space, reduce file transfer times, and manage file packaging for applications. They offer various features, including streaming, encryption, and support for different compression algorithms, making them essential for tasks like file uploads, downloads, and data backup.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
archiver15,710,4632,92943.1 kB1552 years agoMIT
jszip15,230,32710,247762 kB410-(MIT OR GPL-3.0-or-later)
adm-zip9,578,0142,143121 kB149a year agoMIT
zip-a-folder176,5687563 kB125 days agoMIT
node-zip76,246216-2011 years ago-
zip-local26,29812057.1 kB13--
Feature Comparison: archiver vs jszip vs adm-zip vs zip-a-folder vs node-zip vs zip-local

Compression Formats

  • archiver:

    archiver supports multiple compression formats, including ZIP, TAR, and GZIP, providing greater flexibility for projects that need to work with various archive types.

  • jszip:

    jszip focuses on the ZIP format but allows for more advanced manipulation of ZIP files, including adding files, folders, and setting compression levels.

  • adm-zip:

    adm-zip supports only the ZIP format, making it a simple choice for projects that require basic ZIP compression and extraction without the need for multiple formats.

  • zip-a-folder:

    zip-a-folder is designed specifically for zipping folders into ZIP files, providing a simple interface for directory compression.

  • node-zip:

    node-zip supports only the ZIP format, making it a lightweight option for creating ZIP files without additional features.

  • zip-local:

    zip-local supports ZIP compression and extraction, offering a straightforward API for working with ZIP files.

Streaming Support

  • archiver:

    archiver supports streaming, allowing for efficient handling of large files and archives without consuming excessive memory. This makes it ideal for applications that need to process large data streams.

  • jszip:

    jszip does not natively support streaming, as it is designed for in-memory manipulation of ZIP files. However, it can be integrated with streaming APIs for more advanced use cases.

  • adm-zip:

    adm-zip does not support streaming, which means it loads entire files into memory during compression and extraction. This can be a limitation for large files or memory-intensive applications.

  • zip-a-folder:

    zip-a-folder does not provide streaming capabilities, as it focuses on simple folder compression. It may not be suitable for very large directories or memory-sensitive applications.

  • node-zip:

    node-zip does not support streaming, which limits its ability to handle large files efficiently. It is best suited for small to medium-sized files.

  • zip-local:

    zip-local does not support streaming, which means it processes files in memory during compression and extraction. This can be a limitation for large files.

Encryption and Password Protection

  • archiver:

    archiver does not have built-in support for encryption, but it allows for customization and integration with other libraries to add encryption features.

  • jszip:

    jszip does not support encryption or password protection natively. However, there are third-party plugins and libraries that can be integrated to add these features.

  • adm-zip:

    adm-zip does not support encryption or password protection, making it unsuitable for projects that require secure ZIP files.

  • zip-a-folder:

    zip-a-folder does not provide encryption or password protection features, as it focuses on simple folder compression.

  • node-zip:

    node-zip does not support encryption or password protection, limiting its use for secure file compression.

  • zip-local:

    zip-local does not support encryption or password protection, making it a basic tool for ZIP file manipulation without security features.

Folder Compression

  • archiver:

    archiver provides robust support for folder compression, allowing developers to easily add entire directories to an archive with a single command. It is highly efficient and supports streaming, making it suitable for large folders.

  • jszip:

    jszip supports folder compression by allowing the creation of nested folder structures within a ZIP file. However, it is primarily designed for in-memory operations and may not be as efficient for large directories compared to streaming-based solutions.

  • adm-zip:

    adm-zip allows for folder compression by adding directories and their contents to a ZIP archive. However, it requires manual handling of folder structures and does not provide a dedicated method for zipping entire folders.

  • zip-a-folder:

    zip-a-folder is specifically designed for folder compression, providing a simple and intuitive API for zipping entire directories with minimal code. It is efficient and easy to use for quick folder compression tasks.

  • node-zip:

    node-zip allows for folder compression by adding files and directories to a ZIP archive. However, it lacks advanced features and may require additional code to handle complex folder structures.

  • zip-local:

    zip-local supports folder compression by allowing users to zip entire directories with a simple API. It is user-friendly and suitable for both small and large folders.

Ease of Use: Code Examples

  • archiver:

    Streaming ZIP Creation with Multiple Formats

    const fs = require('fs');
    const archiver = require('archiver');
    
    const output = fs.createWriteStream('output.zip');
    const archive = archiver('zip', {
      zlib: { level: 9 } // Compression level
    });
    
    output.on('close', () => {
      console.log(`Archive created with ${archive.pointer()} total bytes`);
    });
    
    archive.on('error', (err) => {
      throw err;
    });
    
    archive.pipe(output);
    
    // Add files and folders
    archive.file('path/to/file.txt', { name: 'file.txt' });
    archive.directory('path/to/folder', 'folder');
    
    archive.finalize();
    
  • jszip:

    In-Memory ZIP Creation and Extraction

    const JSZip = require('jszip');
    const fs = require('fs');
    const zip = new JSZip();
    
    // Add files and folders
    zip.file('file.txt', 'Hello, World!');
    const folder = zip.folder('folder');
    folder.file('nested.txt', 'Nested file content');
    
    // Generate ZIP file
    zip.generateAsync({ type: 'nodebuffer' }).then((content) => {
      fs.writeFileSync('output.zip', content);
    });
    
    // Extract ZIP file (example using jszip)
    fs.readFile('output.zip', (err, data) => {
      if (err) throw err;
      JSZip.loadAsync(data).then((zip) => {
        zip.file('file.txt').async('string').then((text) => {
          console.log('Extracted content:', text);
        });
      });
    });
    
  • adm-zip:

    Simple ZIP Creation and Extraction

    const AdmZip = require('adm-zip');
    const zip = new AdmZip();
    
    // Add a file to the ZIP
    zip.addLocalFile('path/to/file.txt');
    
    // Add a folder to the ZIP
    zip.addLocalFolder('path/to/folder');
    
    // Save the ZIP file
    zip.writeZip('output.zip');
    
    // Extract the ZIP file
    const zipToExtract = new AdmZip('output.zip');
    zipToExtract.extractAllTo('extracted_folder', true);
    
  • zip-a-folder:

    Simple Folder Zipping

    const { zip } = require('zip-a-folder');
    
    zip('path/to/folder', 'output.zip')
      .then(() => {
        console.log('Folder zipped successfully');
      })
      .catch((err) => {
        console.error('Error zipping folder:', err);
      });
    
  • node-zip:

    Basic ZIP Creation

    const NodeZip = require('node-zip');
    const fs = require('fs');
    const zip = new NodeZip();
    
    // Add files to the ZIP
    zip.file('file.txt', 'Hello, World!');
    
    // Generate ZIP data
    const data = zip.generate({ base64: false, compression: 'DEFLATE' });
    
    // Save ZIP file
    fs.writeFileSync('output.zip', data, 'binary');
    
  • zip-local:

    Easy ZIP and Unzip

    const { zip, unzip } = require('zip-local');
    
    // Zip a folder
    zip('path/to/folder').compress().save('output.zip');
    
    // Unzip a file
    unzip('output.zip').extract('extracted_folder');
    
How to Choose: archiver vs jszip vs adm-zip vs zip-a-folder vs node-zip vs zip-local
  • archiver:

    Choose archiver if you need a more powerful and flexible solution for creating archives, including support for multiple formats (ZIP, TAR, etc.). It is suitable for applications that require streaming capabilities and more control over the archiving process.

  • jszip:

    Choose jszip if you need a library that works both in Node.js and the browser for creating and manipulating ZIP files. It is great for applications that require client-side zipping and unzipping, as well as server-side functionality.

  • adm-zip:

    Choose adm-zip if you need a simple and straightforward solution for creating and extracting ZIP files with minimal configuration. It is ideal for projects that require basic ZIP functionality without the need for advanced features.

  • zip-a-folder:

    Choose zip-a-folder if you need a straightforward way to zip entire folders with minimal code. It is ideal for applications that need to compress directories quickly and easily without dealing with low-level ZIP operations.

  • node-zip:

    Choose node-zip if you need a lightweight library for creating ZIP files with a simple API. It is suitable for projects that require basic ZIP creation without additional features or complexity.

  • zip-local:

    Choose zip-local if you need a simple and intuitive API for zipping and unzipping files and folders. It is suitable for projects that require easy-to-use compression and extraction functionality with minimal setup.

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.