adm-zip vs extract-zip vs unzipper
Node.js ZIPファイル操作ライブラリ
adm-zipextract-zipunzipper類似パッケージ:

Node.js ZIPファイル操作ライブラリ

これらのライブラリは、Node.js環境でZIPファイルの作成、解凍、操作を行うためのツールです。各ライブラリは異なる機能と設計哲学を持ち、特定のユースケースに応じて選択することができます。これにより、開発者はZIPファイルを簡単に扱うことができ、ファイルの圧縮や解凍を効率的に行うことが可能です。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
adm-zip02,168122 kB1452ヶ月前MIT
extract-zip0398-606年前BSD-2-Clause
unzipper047356.6 kB882年前MIT

機能比較: adm-zip vs extract-zip vs unzipper

APIのシンプルさ

  • adm-zip:

    adm-zipは、シンプルで直感的なAPIを提供しており、ファイルの圧縮と解凍を簡単に行うことができます。特に、ファイルの追加や削除が簡単で、少ないコードで操作が可能です。

  • extract-zip:

    extract-zipは、解凍専用の非常にシンプルなAPIを提供しています。使い方が簡単で、特に解凍処理に特化しているため、初心者でも扱いやすいです。

  • unzipper:

    unzipperは、ストリーミングAPIを提供し、非同期処理を重視した設計になっています。APIは少し複雑ですが、ストリーミング処理に慣れている開発者には強力なツールです。

パフォーマンス

  • adm-zip:

    adm-zipは、メモリ内で全てのファイルを処理するため、小規模なZIPファイルの操作には非常に高速です。しかし、大きなファイルではメモリ使用量が増加する可能性があります。

  • extract-zip:

    extract-zipは、ストリーミング解凍を行うため、大きなZIPファイルの解凍においてメモリ効率が良く、パフォーマンスが高いです。

  • unzipper:

    unzipperは、ストリーミング解凍を行うため、非常に大きなファイルを扱う際に優れたパフォーマンスを発揮します。メモリ使用量を抑えつつ、効率的にファイルを処理できます。

エラーハンドリング

  • adm-zip:

    adm-zipは、エラーが発生した場合に詳細なエラーメッセージを提供しますが、エラーハンドリングの柔軟性は他のライブラリに比べて劣ります。

  • extract-zip:

    extract-zipは、解凍中にエラーが発生した場合、シンプルなエラーハンドリングを提供します。エラーをキャッチしやすく、扱いやすいです。

  • unzipper:

    unzipperは、ストリーミング処理中のエラーを柔軟に処理できるため、エラーハンドリングの面で非常に強力です。特に非同期処理において、エラーを適切に管理できます。

ファイルのメタデータ操作

  • adm-zip:

    adm-zipは、ファイルのメタデータ(例:ファイル名、サイズ、作成日など)を操作する機能を提供しており、圧縮ファイルの内容を詳細に管理できます。

  • extract-zip:

    extract-zipは、解凍時にファイルのメタデータを操作する機能は提供していません。解凍専用に特化しているため、メタデータの操作は行えません。

  • unzipper:

    unzipperもメタデータの操作には特化していませんが、ストリーミング処理を通じてファイルの情報を取得することは可能です。

ストリーミングサポート

  • adm-zip:

    adm-zipは、ストリーミング処理をサポートしていません。全てのファイルをメモリに読み込むため、大きなファイルには不向きです。

  • extract-zip:

    extract-zipは、ストリーミング解凍をサポートしており、大きなファイルの解凍に適しています。メモリ消費を抑えつつ、効率的に処理が可能です。

  • unzipper:

    unzipperは、ストリーミング解凍を行うため、特に大きなZIPファイルの処理に優れています。非同期処理が可能で、ファイルを逐次的に処理できます。

選び方: adm-zip vs extract-zip vs unzipper

  • adm-zip:

    大量のファイルを一度に圧縮または解凍する必要がある場合や、シンプルなAPIを求める場合に最適です。特に、ファイルのメタデータを操作する必要がある場合に便利です。

  • extract-zip:

    ZIPファイルの解凍に特化したシンプルなライブラリを求めている場合に適しています。ストリーミングAPIを使用しているため、大きなファイルの解凍に適しています。

  • unzipper:

    ストリーミング解凍を行いたい場合や、非同期処理を重視する場合に選択すべきです。ファイルを逐次的に処理できるため、メモリ効率が良く、大きな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 });
.
.
.