archiver vs jszip vs adm-zip vs zip-local
Node.jsのZIPライブラリ
archiverjszipadm-zipzip-local類似パッケージ:
Node.jsのZIPライブラリ

これらのライブラリは、Node.js環境でZIPファイルを作成、解凍、操作するためのツールです。各ライブラリは異なる機能や特性を持ち、特定のニーズに応じて選択することができます。これにより、開発者はファイルの圧縮や展開を簡単に行うことができ、アプリケーションのパフォーマンスを向上させることができます。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
archiver15,915,0432,92643.1 kB1552年前MIT
jszip14,980,37210,238762 kB410-(MIT OR GPL-3.0-or-later)
adm-zip9,525,2142,144121 kB1491年前MIT
zip-local30,66712057.1 kB13--
機能比較: archiver vs jszip vs adm-zip vs zip-local

使いやすさ

  • archiver:

    archiverはストリーミングAPIを提供しており、大きなファイルを扱う際に効率的です。設定が少し複雑ですが、柔軟性があります。

  • jszip:

    jszipはブラウザで動作するため、クライアントサイドでのZIP操作が簡単に行えます。APIもシンプルで、すぐに使い始めることができます。

  • adm-zip:

    adm-zipはシンプルなAPIを提供しており、ZIPファイルの作成や解凍が直感的に行えます。特に小規模なプロジェクトや簡単なタスクに最適です。

  • zip-local:

    zip-localは非常にシンプルで、ローカルファイルの圧縮や解凍が簡単に行えます。特に初心者に優しい設計です。

パフォーマンス

  • archiver:

    ストリーミングを利用することで、大きなファイルでも効率的に処理できます。メモリ使用量を抑えつつ、パフォーマンスを維持します。

  • jszip:

    クライアントサイドでの処理に特化しており、ブラウザの性能に依存します。大きなファイルの場合、パフォーマンスが低下することがあります。

  • adm-zip:

    小さなファイルの操作においては非常に高速ですが、大きなファイルを扱う際にはメモリ使用量が増える可能性があります。

  • zip-local:

    シンプルな操作においては良好なパフォーマンスを発揮しますが、大規模なファイル操作には向いていません。

機能の豊富さ

  • archiver:

    ZIPだけでなく、tarやgzipなど多様なフォーマットをサポートしており、機能が豊富です。

  • jszip:

    ZIPファイルの作成と解凍に特化しており、圧縮レベルの設定なども可能です。

  • adm-zip:

    基本的なZIPファイルの作成と解凍機能を提供しますが、他のフォーマットには対応していません。

  • zip-local:

    基本的なZIP操作に特化しており、他のフォーマットには対応していません。

ストリーミングサポート

  • archiver:

    ストリーミングAPIを提供しており、大きなデータを効率的に処理できます。

  • jszip:

    ストリーミング操作には対応していませんが、クライアントサイドでの操作に特化しています。

  • adm-zip:

    ストリーミング操作には対応していません。全てのデータをメモリに読み込む必要があります。

  • zip-local:

    ストリーミング機能はありませんが、シンプルな操作には適しています。

サポートとメンテナンス

  • archiver:

    広く使用されており、コミュニティからのサポートも充実しています。

  • jszip:

    人気のあるライブラリで、ドキュメントも豊富です。

  • adm-zip:

    活発なメンテナンスが行われており、問題があれば迅速に対応されます。

  • zip-local:

    シンプルなライブラリですが、サポートは限られています。

選び方: archiver vs jszip vs adm-zip vs zip-local
  • archiver:

    ストリーミングAPIを使用して大きなファイルを扱う必要がある場合に選択してください。多様なフォーマットをサポートし、柔軟性があります。

  • jszip:

    クライアントサイドでのZIP操作が必要な場合に選択してください。ブラウザで動作し、簡単に使用できます。

  • adm-zip:

    簡単なZIPファイルの作成や解凍が必要な場合に選択してください。シンプルなAPIで、迅速な実装が可能です。

  • zip-local:

    ローカルファイルシステムに対する簡単な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.