@borgar/zip

中文文档
1.1.0发布于 2026/11/08MITTypeScriptESM + CJS近 30 天下载 6998

A library to manipulate zip files, using native implementations for compression where available.

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. API

@borgar/zip

A library for reading and writing ZIP archives, using native platform APIs for compression where available.

  • 🚀 Uses native platform implementations of zlib/deflate where available (which is nearly everywhere!), only falling back to JS when all else fails.

  • 🧠 Keeps zip compressed in memory, rather than expanding all on load.

  • 📦 Reads pretty much any zip file (only known limitation is Zip64 offsets that exceed the largest numbers JS can hold).

  • 💬 Fully typed for your convenience.

Installation

npm install @borgar/zip

Usage

import { ZipArchive } from '@borgar/zip';

// Read an existing archive
const zip = new ZipArchive(arrayBuffer);
const text = await zip.readText('hello.txt'); // "hello world\n"
const data = await zip.read('image.png'); // ArrayBuffer([ 89 50 4E 47 0D 0A 1A 0A... ])

// Create a new archive
const zip = new ZipArchive();
await zip.write('hello.txt', text);
await zip.write('data.bin', data);

// Or write without awaiting each call. Entries are added in call order.
zip.write('a.txt', 'a');
zip.write('b.txt', 'b');
await zip.done(); // waits for all pending writes

const output = zip.toArrayBuffer();

// Trigger a browser download
const zipBlob = new Blob([ output ]);
const urlObject = URL.createObjectURL(zipBlob);
const a = document.createElement('a');
a.href = urlObject;
a.download = 'MyFilename.zip';
a.click();
URL.revokeObjectURL(urlObject);

API

The API is fully documented in API.md.

版本与发布记录

@borgar/zip 共发布 3 个版本,首次发布于 2026/05/04;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.1.0latest2026/11/08今天
1.0.12026/10/2118 天前
1.0.02026/05/046 个月前

关于 @borgar/zip 的常见问题

@borgar/zip 是什么?

A library to manipulate zip files, using native implementations for compression where available.

如何安装 @borgar/zip?

在项目目录运行 npm install @borgar/zip,或使用 pnpm add / yarn add / bun add。

@borgar/zip 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@borgar/zip 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@borgar/zip 可以商用吗?

@borgar/zip 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@borgar/zip 的下载量有多少?

根据 npm 官方下载统计,@borgar/zip 在 2026/10/09 – 2026/11/07 这 30 天内被下载 6,998 次,日均约 233 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@borgar/zip 还在维护吗?

最新版本 1.1.0 发布于 2026/11/08(今天);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/05/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。