archiver vs compressing vs tar vs tar-stream vs zip-stream
文件压缩与归档库
archivercompressingtartar-streamzip-stream类似的npm包:

文件压缩与归档库

这些库用于在Node.js环境中处理文件的压缩和归档。它们提供了不同的功能和接口,允许开发者以多种格式创建、读取和操作压缩文件。选择合适的库可以帮助提高应用程序的性能和可维护性。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
archiver02,95639.6 kB1529 天前MIT
compressing045756.1 kB511 个月前MIT
tar09142.26 MB99 天前BlueOak-1.0.0
tar-stream043632.5 kB1417 天前MIT
zip-stream01689.33 kB179 天前MIT

功能对比: archiver vs compressing vs tar vs tar-stream vs zip-stream

支持的格式

  • archiver:

    Archiver支持多种压缩格式,包括zip和tar,适合需要多种格式支持的应用。

  • compressing:

    Compressing支持多种格式,包括zip、tar、gzip等,提供了灵活的选择。

  • tar:

    Tar专注于tar格式,适合需要处理tar文件的场景。

  • tar-stream:

    Tar-stream专注于tar格式,提供流式处理功能,适合大文件处理。

  • zip-stream:

    Zip-stream专注于zip格式,支持流式创建zip文件,适合动态生成zip文件的需求。

流式处理能力

  • archiver:

    Archiver支持流式处理,可以在创建压缩文件时逐步写入数据,适合处理大文件。

  • compressing:

    Compressing也支持流式处理,但主要集中在简单的压缩和解压缩操作上。

  • tar:

    Tar本身不支持流式处理,主要用于读取和写入完整的tar文件。

  • tar-stream:

    Tar-stream专为流式处理设计,允许逐块读取和写入tar文件,适合大文件和实时处理。

  • zip-stream:

    Zip-stream支持流式创建zip文件,可以在生成zip文件时逐步添加文件,适合动态内容生成。

易用性

  • archiver:

    Archiver提供了简单易用的API,适合初学者和需要快速开发的项目。

  • compressing:

    Compressing的API设计简单,易于上手,适合快速实现压缩功能。

  • tar:

    Tar的API相对简单,但可能需要更多的配置和理解tar格式。

  • tar-stream:

    Tar-stream的API相对复杂,需要理解流的概念,适合有经验的开发者。

  • zip-stream:

    Zip-stream的API设计直观,适合需要快速生成zip文件的开发者。

性能

  • archiver:

    Archiver在处理大文件时性能良好,但在某些情况下可能会消耗较多内存。

  • compressing:

    Compressing在性能上表现出色,适合需要快速压缩的场景。

  • tar:

    Tar在处理tar文件时性能稳定,但不适合流式操作。

  • tar-stream:

    Tar-stream在流式处理时性能优越,适合大文件和实时处理。

  • zip-stream:

    Zip-stream在动态生成zip文件时性能良好,适合需要高效处理的应用。

社区支持

  • archiver:

    Archiver拥有活跃的社区和良好的文档支持,适合需要社区帮助的开发者。

  • compressing:

    Compressing的社区相对较小,但文档清晰,易于使用。

  • tar:

    Tar是一个成熟的库,拥有广泛的社区支持和丰富的文档。

  • tar-stream:

    Tar-stream的社区较小,但提供了良好的文档和示例。

  • zip-stream:

    Zip-stream的社区活跃,文档详细,适合需要社区支持的开发者。

如何选择: archiver vs compressing vs tar vs tar-stream vs zip-stream

  • archiver:

    选择Archiver如果你需要一个功能全面且易于使用的库,支持多种压缩格式(如zip和tar),并且需要流式处理文件。它适合需要创建复杂压缩文件的场景。

  • compressing:

    选择Compressing如果你需要一个简单且高效的库,专注于压缩功能,支持多种格式,并且希望在性能上有更好的表现。它适合快速压缩和解压缩的任务。

  • tar:

    选择Tar如果你主要处理tar格式的文件,并且需要一个稳定且广泛使用的库。它适合需要处理tar归档文件的传统场景。

  • tar-stream:

    选择Tar-stream如果你需要一个流式处理tar文件的库,适合处理大文件或需要逐块读取和写入的场景。它提供了更大的灵活性和控制。

  • zip-stream:

    选择Zip-stream如果你需要一个专注于流式创建zip文件的库,适合需要动态生成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

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.