archiver vs adm-zip vs zip-local vs jszip
Node.js 压缩库
archiveradm-zipzip-localjszip类似的npm包:

Node.js 压缩库

Node.js 压缩库用于创建、读取和操作 ZIP 文件,提供了多种功能以满足不同的需求。这些库可以帮助开发者轻松地处理文件压缩和解压缩,支持多种格式和选项。选择合适的库可以提高开发效率,简化文件处理流程。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
archiver28,420,8962,95639.6 kB15615 天前MIT
adm-zip16,281,0692,167122 kB1442 个月前MIT
zip-local29,21812157.1 kB13--
jszip010,348762 kB410-(MIT OR GPL-3.0-or-later)

功能对比: archiver vs adm-zip vs zip-local vs jszip

功能丰富性

  • archiver:

    archiver 支持多种压缩格式(如 ZIP、TAR),并提供流式压缩功能,适合需要处理大文件或多文件的场景。

  • adm-zip:

    adm-zip 提供基本的 ZIP 文件创建和读取功能,适合简单的文件操作,但缺乏高级特性。

  • zip-local:

    zip-local 提供简单的压缩和解压功能,适合快速处理本地文件,功能相对简单。

  • jszip:

    jszip 支持创建和读取 ZIP 文件,功能强大,支持多种文件类型,适合需要在浏览器和 Node.js 中使用的项目。

性能

  • archiver:

    archiver 通过流式处理提高了性能,适合处理大文件和高并发场景。

  • adm-zip:

    adm-zip 在处理大型 ZIP 文件时可能会遇到性能瓶颈,适合小型文件的快速处理。

  • zip-local:

    zip-local 性能较好,适合快速处理本地文件,但不支持流式处理。

  • jszip:

    jszip 在内存中处理文件,适合小型文件,处理大型文件时可能会消耗较多内存。

学习曲线

  • archiver:

    archiver 的功能较为复杂,学习曲线稍陡,适合有一定经验的开发者。

  • adm-zip:

    adm-zip 的 API 简单易懂,适合初学者快速上手。

  • zip-local:

    zip-local 的 API 简单明了,适合快速上手,适合初学者。

  • jszip:

    jszip 提供清晰的文档和示例,学习曲线适中,适合大多数开发者。

社区支持

  • archiver:

    archiver 拥有活跃的社区和频繁的更新,适合需要长期维护的项目。

  • adm-zip:

    adm-zip 拥有一定的社区支持,但更新频率较低。

  • zip-local:

    zip-local 的社区支持相对较少,适合简单项目。

  • jszip:

    jszip 拥有广泛的社区支持和活跃的开发,适合需要长期使用的项目。

扩展性

  • archiver:

    archiver 支持多种格式和自定义选项,具有较好的扩展性。

  • adm-zip:

    adm-zip 的扩展性有限,主要用于基本的 ZIP 操作。

  • zip-local:

    zip-local 的扩展性较弱,主要集中在本地文件的处理。

  • jszip:

    jszip 提供丰富的 API,支持多种文件操作,扩展性强。

如何选择: archiver vs adm-zip vs zip-local vs jszip

  • archiver:

    选择 archiver 如果你需要更复杂的功能,如流式压缩和多种压缩格式的支持,适合需要高性能和灵活性的应用。

  • adm-zip:

    选择 adm-zip 如果你需要一个简单易用的库来快速读取和创建 ZIP 文件,适合小型项目或快速原型开发。

  • zip-local:

    选择 zip-local 如果你需要一个轻量级的库,专注于本地文件的压缩和解压,适合简单的文件处理任务。

  • jszip:

    选择 jszip 如果你需要在浏览器和 Node.js 中都能使用的库,支持创建和读取 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.