archiver vs tar vs zip-a-folder
アーカイブ作成ライブラリ
archivertarzip-a-folder類似パッケージ:

アーカイブ作成ライブラリ

アーカイブ作成ライブラリは、ファイルやフォルダを圧縮して、ストレージの効率を高めたり、データの転送を容易にしたりするために使用されます。これらのライブラリは、さまざまなフォーマット(ZIP、TARなど)でアーカイブを作成する機能を提供し、開発者がデータを簡単に管理できるようにします。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
archiver02,95639.6 kB15312日前MIT
tar09152.26 MB912日前BlueOak-1.0.0
zip-a-folder076212 kB01ヶ月前MIT

機能比較: archiver vs tar vs zip-a-folder

フォーマットサポート

  • archiver:

    Archiverは、ZIP、TAR、GZIPなど、複数のアーカイブフォーマットをサポートしており、さまざまな用途に対応できます。特に、異なるフォーマット間での変換が必要な場合に便利です。

  • tar:

    tarは、主にTAR形式に特化しており、UNIX系システムでの標準的なアーカイブ形式として広く使用されています。シンプルで効率的なTARアーカイブの作成に最適です。

  • zip-a-folder:

    zip-a-folderは、ZIP形式のアーカイブ作成に特化しており、フォルダ全体を簡単に圧縮できます。特に、ZIP形式が必要な場合に便利です。

ストリーミング機能

  • archiver:

    Archiverは、ストリーミング機能を提供しており、大きなファイルやフォルダをメモリに読み込むことなく、直接ストリームとして処理できます。これにより、大規模なデータの圧縮が効率的に行えます。

  • tar:

    tarは、ストリーミング機能を持たず、ファイルを一度に全て読み込む必要があります。したがって、大きなデータセットを扱う場合には注意が必要です。

  • zip-a-folder:

    zip-a-folderは、ストリーミング機能を提供していませんが、簡単にフォルダを圧縮するためのシンプルなAPIを持っています。

使いやすさ

  • archiver:

    Archiverは、柔軟性が高く、さまざまなオプションを提供していますが、設定が複雑になることがあります。特に、ストリーミングを利用する場合は、ある程度の学習が必要です。

  • tar:

    tarは、シンプルで直感的なコマンドラインインターフェースを持っており、UNIX系システムでの使用に慣れている開発者にとっては使いやすいです。

  • zip-a-folder:

    zip-a-folderは、非常にシンプルで直感的なAPIを提供しており、初心者でも簡単に使用できます。特に、迅速にアーカイブを作成したい場合に適しています。

パフォーマンス

  • archiver:

    Archiverは、ストリーミングを利用することで、大きなデータを効率的に処理できますが、設定によってはパフォーマンスが影響を受けることがあります。

  • tar:

    tarは、シンプルな設計により、特にTAR形式でのアーカイブ作成時に高いパフォーマンスを発揮します。

  • zip-a-folder:

    zip-a-folderは、フォルダ全体を圧縮する際に、シンプルな操作で迅速に処理を行いますが、大きなデータセットではメモリ使用量が増加する可能性があります。

コミュニティとサポート

  • archiver:

    Archiverは、活発なコミュニティと豊富なドキュメントがあり、問題解決や機能追加の際にサポートを受けやすいです。

  • tar:

    tarは、長い歴史を持つツールであり、広く使用されているため、豊富なリソースとサポートが存在します。

  • zip-a-folder:

    zip-a-folderは、比較的新しいライブラリですが、シンプルさから多くのユーザーに支持されており、基本的なサポートが得られます。

選び方: archiver vs tar vs zip-a-folder

  • archiver:

    Archiverは、ZIPやTARなどの複数のフォーマットをサポートし、ストリーミング機能を提供するため、大規模なファイルやフォルダを効率的に圧縮したい場合に適しています。特に、Node.jsのストリームを活用したい場合におすすめです。

  • tar:

    tarは、特にUNIX系システムでの使用に最適化されており、TAR形式のアーカイブを作成するためのシンプルで効率的な方法を提供します。UNIX環境での互換性が重要な場合に選択してください。

  • zip-a-folder:

    zip-a-folderは、フォルダ全体を簡単にZIP形式に圧縮するためのシンプルなAPIを提供します。特に、ユーザーフレンドリーなインターフェースを求める場合や、簡単なタスクを迅速に実行したい場合に適しています。

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

import fs from "fs";
import { ZipArchive } from "archiver";

// create a file to stream archive data to.
const output = fs.createWriteStream(__dirname + "/example.zip");
const archive = new ZipArchive({
  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.