archiver vs adm-zip vs zip-a-folder vs node-zip vs jszip vs zip-local
ZIPファイル操作
archiveradm-zipzip-a-foldernode-zipjszipzip-local類似パッケージ:

ZIPファイル操作

ZIPファイル操作ライブラリは、Node.jsアプリケーション内でZIPファイルを作成、解凍、操作するためのツールを提供します。これらのライブラリは、ファイルやフォルダーを圧縮してZIP形式に変換したり、既存のZIPファイルからファイルを抽出したりする機能を持っています。これにより、データの転送や保存を効率化し、ストレージスペースを節約することができます。特に、ウェブアプリケーションやサーバーサイドアプリケーションでファイルのアップロードやダウンロードを行う際に便利です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
archiver22,417,5812,94743.1 kB1552年前MIT
adm-zip11,717,2992,159121 kB1482年前MIT
zip-a-folder185,6817563 kB54ヶ月前MIT
node-zip85,405217-2011年前-
jszip010,317762 kB409-(MIT OR GPL-3.0-or-later)
zip-local012157.1 kB13--

機能比較: archiver vs adm-zip vs zip-a-folder vs node-zip vs jszip vs zip-local

ストリーミングサポート

  • archiver:

    archiverはストリーミングAPIを提供しており、大きなファイルやフォルダーを効率的に圧縮できます。データを逐次処理するため、メモリ使用量が少なく、パフォーマンスが向上します。

  • adm-zip:

    adm-zipはストリーミング処理をサポートしていません。すべてのファイルをメモリに読み込むため、大きなファイルやフォルダーを扱う際にはメモリ使用量が増加します。

  • zip-a-folder:

    zip-a-folderはストリーミング処理をサポートしていません。フォルダー全体を一度に圧縮するため、大きなフォルダーを扱う際にはメモリ使用量が増加します。

  • node-zip:

    node-zipはストリーミング処理をサポートしていません。ファイルをメモリに読み込んでから圧縮するため、大きなファイルを扱う際にはメモリ制限があります。

  • jszip:

    jszipはストリーミング処理をサポートしていませんが、ZIPファイルをメモリ内で操作します。大きなファイルを扱う際は、メモリ使用量に注意が必要です。

  • zip-local:

    zip-localはストリーミング処理をサポートしていません。ファイルをメモリに読み込んでから圧縮するため、大きなファイルを扱う際にはメモリ制限があります。

フォルダー圧縮

  • archiver:

    archiverはフォルダーを再帰的に圧縮することができ、サブフォルダーやファイルを含めて一度に圧縮できます。ストリーミング圧縮に対応しているため、大きなフォルダーの圧縮も効率的に行えます。

  • adm-zip:

    adm-zipはフォルダーを再帰的に圧縮することができますが、フォルダー全体を一度に圧縮する機能はありません。フォルダー内のファイルを個別に圧縮する必要があります。

  • zip-a-folder:

    zip-a-folderはフォルダー全体を一度に圧縮することができます。フォルダーのパスを指定するだけで、再帰的にすべてのファイルとサブフォルダーを圧縮します。

  • node-zip:

    node-zipはフォルダーを再帰的に圧縮することができますが、フォルダー全体を一度に圧縮する機能はありません。フォルダー内のファイルを個別に圧縮する必要があります。

  • jszip:

    jszipはフォルダーを再帰的に圧縮することができますが、フォルダー全体を一度に圧縮する機能はありません。フォルダー内のファイルを個別に圧縮する必要があります。

  • zip-local:

    zip-localはフォルダーを再帰的に圧縮することができますが、フォルダー全体を一度に圧縮する機能はありません。フォルダー内のファイルを個別に圧縮する必要があります。

ファイル解凍

  • archiver:

    archiverは解凍機能を提供していません。圧縮専用のライブラリです。

  • adm-zip:

    adm-zipはZIPファイルからファイルを解凍する機能を提供しています。特定のファイルを指定して解凍することも、全てのファイルを解凍することも可能です。

  • zip-a-folder:

    zip-a-folderは解凍機能を提供していません。圧縮専用のライブラリです。

  • node-zip:

    node-zipはZIPファイルからファイルを解凍する機能を提供しています。特定のファイルを指定して解凍することも、全てのファイルを解凍することも可能です。

  • jszip:

    jszipはZIPファイルからファイルを解凍する機能を提供しています。特定のファイルを指定して解凍することも、全てのファイルを解凍することも可能です。

  • zip-local:

    zip-localはZIPファイルからファイルを解凍する機能を提供しています。特定のファイルを指定して解凍することも、全てのファイルを解凍することも可能です。

APIのシンプルさ

  • archiver:

    archiverはストリーミングAPIを提供していますが、やや複雑なため、大規模なプロジェクトや専門的な用途に適しています。

  • adm-zip:

    adm-zipはシンプルで直感的なAPIを提供しており、特に小規模なプロジェクトや簡単なZIP操作に適しています。

  • zip-a-folder:

    zip-a-folderは非常にシンプルなAPIを提供しており、フォルダーを圧縮する作業が簡単に行えます。

  • node-zip:

    node-zipはシンプルで直感的なAPIを提供しており、特に小規模なプロジェクトに適しています。

  • jszip:

    jszipはシンプルで使いやすいAPIを提供しており、特にクライアントサイドでのファイル操作に強みがあります。

  • zip-local:

    zip-localはシンプルで直感的なAPIを提供しており、特にローカル環境でのファイル操作に特化しています。

Ease of Use: Code Examples

  • archiver:

    archiverを使用したストリーミングZIPファイルの作成の例

    const fs = require('fs');
    const archiver = require('archiver');
    
    const output = fs.createWriteStream('example.zip');
    const archive = archiver('zip');
    
    output.on('close', () => {
      console.log(`ZIPファイルが作成されました: ${archive.pointer()} バイト`);
    });
    
    archive.pipe(output);
    archive.append('Hello, World!', { name: 'hello.txt' });
    archive.directory('myFolder/', 'myFolder');
    archive.finalize();
    
  • adm-zip:

    adm-zipを使用したZIPファイルの作成と解凍の例

    const AdmZip = require('adm-zip');
    
    // ZIPファイルの作成
    const zip = new AdmZip();
    zip.addFile('hello.txt', Buffer.from('Hello, World!'));
    zip.addLocalFolder('myFolder');
    zip.writeZip('example.zip');
    
    // ZIPファイルの解凍
    const zipFile = new AdmZip('example.zip');
    zipFile.extractAllTo('outputFolder', true);
    
  • zip-a-folder:

    zip-a-folderを使用したフォルダーの圧縮の例

    const { zip } = require('zip-a-folder');
    
    zip('myFolder', 'example.zip').then(() => {
      console.log('フォルダーが圧縮されました。');
    });
    
  • node-zip:

    node-zipを使用したZIPファイルの作成と解凍の例

    const zip = require('node-zip')();
    const fs = require('fs');
    
    // ZIPファイルの作成
    zip.file('hello.txt', 'Hello, World!');
    zip.folder('myFolder').file('file.txt', 'This is a file.');
    const data = zip.generate({ base64: false });
    fs.writeFileSync('example.zip', data, 'binary');
    
    // ZIPファイルの解凍
    const unzip = require('node-zip')();
    const zipData = fs.readFileSync('example.zip', 'binary');
    unzip.load(zipData);
    console.log(unzip.files['hello.txt'].data.toString()); // 'Hello, World!'
    console.log(unzip.files['myFolder/file.txt'].data.toString()); // 'This is a file.'
    
  • jszip:

    jszipを使用したZIPファイルの作成と解凍の例

    const JSZip = require('jszip');
    const fs = require('fs');
    
    const zip = new JSZip();
    zip.file('hello.txt', 'Hello, World!');
    zip.folder('myFolder').file('file.txt', 'This is a file.');
    
    zip.generateAsync({ type: 'nodebuffer' }).then((content) => {
      fs.writeFileSync('example.zip', content);
      console.log('ZIPファイルが作成されました。');
    
      // ZIPファイルの解凍
      const unzip = new JSZip();
      fs.readFile('example.zip', (err, data) => {
        unzip.loadAsync(data).then((zip) => {
          zip.file('hello.txt').async('string').then((content) => {
            console.log(content); // 'Hello, World!'
          });
          zip.folder('myFolder').file('file.txt').async('string').then((content) => {
            console.log(content); // 'This is a file.'
          });
        });
      });
    });
    
  • zip-local:

    zip-localを使用したZIPファイルの作成と解凍の例

    const zipLocal = require('zip-local');
    const fs = require('fs');
    
    // ZIPファイルの作成
    zipLocal.zip('myFolder', (err, zip) => {
      if (err) throw err;
      zip.save('example.zip', () => {
        console.log('ZIPファイルが作成されました。');
    
        // ZIPファイルの解凍
        zip.extract('outputFolder', () => {
          console.log('ZIPファイルが解凍されました。');
        });
      });
    });
    

選び方: archiver vs adm-zip vs zip-a-folder vs node-zip vs jszip vs zip-local

  • archiver:

    archiverは、ストリーミングAPIを提供し、大規模なファイルやフォルダーを効率的に圧縮できます。メモリ使用量が少なく、パフォーマンスが高いため、プロダクション環境に適しています。特に、リアルタイムでデータを圧縮しながら送信するアプリケーションに最適です。

  • adm-zip:

    adm-zipは、シンプルで使いやすいAPIを提供し、特に小規模なプロジェクトや簡単なZIP操作に適しています。ファイルの圧縮、解凍、リスト表示が簡単に行えますが、大規模なデータセットやストリーミング処理には向いていません。

  • zip-a-folder:

    zip-a-folderは、フォルダー全体を簡単にZIPファイルに圧縮するためのライブラリです。シンプルなインターフェースで、フォルダーのパスを指定するだけで圧縮が完了します。特に、フォルダー単位での圧縮作業が多いプロジェクトに便利です。

  • node-zip:

    node-zipは、シンプルなAPIを提供するNode.js専用のZIPライブラリです。ファイルやフォルダーを簡単に圧縮でき、特に小規模なプロジェクトに適しています。ただし、ストリーミングや大規模データの処理には限界があります。

  • jszip:

    jszipは、ブラウザとNode.jsの両方で動作するZIPファイル操作ライブラリです。ZIPファイルの作成、解凍、編集が可能で、特にクライアントサイドでのファイル操作に強みがあります。インターフェースが直感的で、ファイルをプログラムmatically追加したり、抽出したりするのが簡単です。

  • zip-local:

    zip-localは、ローカルファイルシステム内でZIPファイルを作成、解凍するためのシンプルなライブラリです。特に、ローカル環境でのファイル操作に特化しており、使いやすさが特徴です。APIが直感的で、迅速にZIP操作を行いたい開発者に適しています。

archiver のREADME

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.