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

ZIPファイル操作

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

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
adm-zip02,168122 kB1452ヶ月前MIT
archiver02,95839.6 kB15721日前MIT
jszip010,355762 kB410-(MIT OR GPL-3.0-or-later)
node-zip0217-1911年前-
zip-a-folder076212 kB01ヶ月前MIT
zip-local012157.1 kB13--

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

ストリーミングサポート

  • adm-zip:

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

  • archiver:

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

  • jszip:

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

  • node-zip:

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

  • zip-a-folder:

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

  • zip-local:

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

フォルダー圧縮

  • adm-zip:

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

  • archiver:

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

  • jszip:

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

  • node-zip:

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

  • zip-a-folder:

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

  • zip-local:

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

ファイル解凍

  • adm-zip:

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

  • archiver:

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

  • jszip:

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

  • node-zip:

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

  • zip-a-folder:

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

  • zip-local:

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

APIのシンプルさ

  • adm-zip:

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

  • archiver:

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

  • jszip:

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

  • node-zip:

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

  • zip-a-folder:

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

  • zip-local:

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

Ease of Use: Code Examples

  • 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);
    
  • 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();
    
  • 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.'
          });
        });
      });
    });
    
  • 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.'
    
  • zip-a-folder:

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

    const { zip } = require('zip-a-folder');
    
    zip('myFolder', 'example.zip').then(() => {
      console.log('フォルダーが圧縮されました。');
    });
    
  • 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ファイルが解凍されました。');
        });
      });
    });
    

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

  • adm-zip:

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

  • archiver:

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

  • jszip:

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

  • node-zip:

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

  • zip-a-folder:

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

  • zip-local:

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

adm-zip のREADME

ADM-ZIP for NodeJS

ADM-ZIP is a pure JavaScript implementation for zip data compression for NodeJS.

Build Status

Installation

With npm do:

$ npm install adm-zip

Electron file system support described below.

What is it good for?

The library allows you to:

  • decompress zip files directly to disk or in memory buffers
  • compress files and store them to disk in .zip format or in compressed buffers
  • update content of/add new/delete files from an existing .zip

Dependencies

There are no other nodeJS libraries that ADM-ZIP is dependent of

Examples

Basic usage

var AdmZip = require("adm-zip");

// reading archives
var zip = new AdmZip("./my_file.zip");
var password = "1234567890";
var zipEntries = zip.getEntries(); // an array of ZipEntry records - add password parameter if entries are password protected

zipEntries.forEach(function (zipEntry) {
    console.log(zipEntry.toString()); // outputs zip entries information
    if (zipEntry.entryName == "my_file.txt") {
        console.log(zipEntry.getData().toString("utf8"));
    }
});
// outputs the content of some_folder/my_file.txt
console.log(zip.readAsText("some_folder/my_file.txt"));
// extracts the specified file to the specified location
zip.extractEntryTo(/*entry name*/ "some_folder/my_file.txt", /*target path*/ "/home/me/tempfolder", /*maintainEntryPath*/ false, /*overwrite*/ true);
// extracts everything
zip.extractAllTo(/*target path*/ "/home/me/zipcontent/", /*overwrite*/ true);

// creating archives
var zip = new AdmZip();

// add file directly
var content = "inner content of the file";
zip.addFile("test.txt", Buffer.from(content, "utf8"), "entry comment goes here");
// add local file
zip.addLocalFile("/home/me/some_picture.png");
// get everything as a buffer
var willSendthis = zip.toBuffer();
// or write everything to disk
zip.writeZip(/*target file name*/ "/home/me/files.zip");

// ... more examples in the wiki

For more detailed information please check out the wiki.

Electron original-fs

ADM-ZIP has supported electron original-fs for years without any user interractions but it causes problem with bundlers like rollup etc. For continuing support original-fs or any other custom file system module. There is possible specify your module by fs option in ADM-ZIP constructor.

Example:

const AdmZip = require("adm-zip");
const OriginalFs = require("original-fs");

// reading archives
const zip = new AdmZip("./my_file.zip", { fs: OriginalFs });
.
.
.