archiver vs tar vs tar-fs vs tar-stream vs zip-stream
アーカイブおよび圧縮ライブラリ
archivertartar-fstar-streamzip-stream類似パッケージ:

アーカイブおよび圧縮ライブラリ

アーカイブおよび圧縮ライブラリは、ファイルやディレクトリを圧縮して保存したり、アーカイブ形式でまとめたりするためのツールです。これらのライブラリは、データの転送や保存を効率的に行うために使用され、特に大規模なデータセットや複数のファイルを扱う際に便利です。これらのライブラリを使用することで、ストレージの節約やデータ転送の高速化が可能になります。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
archiver02,95143.1 kB1562年前MIT
tar09122.24 MB91ヶ月前BlueOak-1.0.0
tar-fs038118.2 kB12ヶ月前MIT
tar-stream043632.5 kB145日前MIT
zip-stream01689.33 kB272年前MIT

機能比較: archiver vs tar vs tar-fs vs tar-stream vs zip-stream

圧縮形式のサポート

  • archiver:

    Archiverは、ZIP、TAR、GZなど、複数の圧縮形式をサポートしています。これにより、さまざまなアプリケーションでの使用が可能です。

  • tar:

    Tarは、主にtarball形式に特化しており、UNIX系システムでの互換性が高いです。

  • tar-fs:

    Tar-fsは、tar形式のアーカイブを作成するためのシンプルなインターフェースを提供します。

  • tar-stream:

    Tar-streamは、ストリーミング形式でtarアーカイブを作成するため、メモリ使用量を抑えつつ効率的に処理できます。

  • zip-stream:

    Zip-streamは、ZIP形式に特化しており、ストリーミングでの圧縮が可能です。

ストリーミングサポート

  • archiver:

    Archiverは、ストリーミングAPIを提供し、ファイルをリアルタイムで圧縮できます。

  • tar:

    Tarは、ストリーミング機能を持たず、全体を一度に処理します。

  • tar-fs:

    Tar-fsは、ストリーミングAPIを提供し、ファイルシステムから直接データを取得できます。

  • tar-stream:

    Tar-streamは、ストリーミングアプローチを採用しており、データを逐次処理できます。

  • zip-stream:

    Zip-streamは、ストリーミングZIPアーカイブを作成するための効率的な方法を提供します。

使用シナリオ

  • archiver:

    Archiverは、さまざまな圧縮形式を必要とするアプリケーションに適しています。

  • tar:

    Tarは、UNIX系システムでのアーカイブ作成に最適です。

  • tar-fs:

    Tar-fsは、ファイルシステムから直接データを取得する必要がある場合に便利です。

  • tar-stream:

    Tar-streamは、リアルタイムでデータを処理する必要がある場合に最適です。

  • zip-stream:

    Zip-streamは、ストリーミングで大きなファイルを圧縮する場合に適しています。

メモリ効率

  • archiver:

    Archiverは、ストリーミングを利用することでメモリ効率が良いです。

  • tar:

    Tarは、全体を一度に処理するため、大きなファイルではメモリ使用量が増加します。

  • tar-fs:

    Tar-fsは、ファイルシステムから直接データを取得するため、メモリ使用量を抑えられます。

  • tar-stream:

    Tar-streamは、ストリーミング処理によりメモリ使用量を最小限に抑えます。

  • zip-stream:

    Zip-streamは、ストリーミングZIPアーカイブを作成するため、メモリ効率が良いです。

APIの使いやすさ

  • archiver:

    Archiverは、シンプルで直感的なAPIを提供しており、使いやすさが高いです。

  • tar:

    Tarは、シンプルなAPIですが、機能は限られています。

  • tar-fs:

    Tar-fsは、ファイルシステムからのデータ取得に特化したAPIを提供します。

  • tar-stream:

    Tar-streamは、ストリーミングAPIを提供し、柔軟性があります。

  • zip-stream:

    Zip-streamは、ストリーミングZIPアーカイブを作成するための簡潔なAPIを提供します。

選び方: archiver vs tar vs tar-fs vs tar-stream vs zip-stream

  • archiver:

    Archiverは、ZIPやTARなどのアーカイブ形式をサポートしており、ストリーミングAPIを提供します。ファイルを簡単に圧縮したい場合や、複数の形式をサポートする必要がある場合に最適です。

  • tar:

    Tarは、UNIX系のシステムで広く使用されているアーカイブ形式で、特にtarballの作成に適しています。シンプルで効率的なアーカイブ作成が必要な場合に選択してください。

  • tar-fs:

    Tar-fsは、ファイルシステムから直接tarアーカイブを作成するためのライブラリです。ファイルシステムのストリーミングを利用したい場合や、ファイルを直接操作する必要がある場合に適しています。

  • tar-stream:

    Tar-streamは、ストリーミングAPIを提供するtarアーカイブ作成用のライブラリです。メモリ効率が良く、リアルタイムでのデータ処理が必要な場合に選択してください。

  • zip-stream:

    Zip-streamは、ストリーミング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.