pako

中文文档
3.0.3发布于 2026/10/27(MIT AND Zlib)TypeScriptESM + CJS零依赖近 30 天下载 5.3亿

zlib port to javascript - fast, modularized, with browser support

原始使用文档
文档目录7 节
  1. Why pako is cool
  2. Benchmarks
  3. Install
  4. Examples / API
  5. Notes
  6. Authors
  7. License

pako

CI NPM version

Very fast zlib-compatible compression for JavaScript.

Why pako is cool

  • Binary-equivalent output. Pako can produce the same deflate/gzip bytes as original zlib (1.3.2) and Node.js' patched zlib.
  • Tiny browser bundles. Full minified bundle is under 15K gzipped. Deflate-only and inflate-only builds are smaller.
  • Very fast. Performance is comparable with native zlib in modern JavaScript engines (see benchmarks).

Benchmarks

node v24, 1 MB input sample:

deflate-pako x 14.27 ops/sec ±3.41% (37 runs sampled)
deflate-pako-zlib-hash x 10.60 ops/sec ±0.50% (29 runs sampled)
deflate-zlib x 30.30 ops/sec ±0.61% (51 runs sampled)
gzip-pako x 13.48 ops/sec ±0.50% (36 runs sampled)
inflate-pako x 138 ops/sec ±1.26% (75 runs sampled)
inflate-zlib x 397 ops/sec ±1.37% (81 runs sampled)
ungzip-pako x 125 ops/sec ±1.46% (73 runs sampled)

Install

npm install pako

[!NOTE] For a quick look at dist/ folder contents, see https://unpkg.com/pako@latest/.

Examples / API

Full docs - http://nodeca.github.io/pako/

import { Deflate, Inflate, deflate, inflate } from 'pako';

// Deflate
//
const input = new Uint8Array();
//... fill input data here
const output = deflate(input);

// Inflate (simple wrapper can throw exception on broken stream)
//
const compressed = new Uint8Array();
//... fill data to uncompress here
try {
  const result = inflate(compressed);
  // ... continue processing
} catch (err) {
  console.log(err);
}

//
// Alternate interface for chunking & without exceptions
//

const deflator = new Deflate();

deflator.push(chunk1, false);
deflator.push(chunk2); // second param is false by default.
...
deflator.push(chunk_last, true); // `true` says this chunk is last

if (deflator.err) {
  console.log(deflator.msg);
}

const output = deflator.result;


const inflator = new Inflate();

inflator.push(chunk1);
inflator.push(chunk2);
...
inflator.push(chunk_last); // no second param because end is auto-detected

if (inflator.err) {
  console.log(inflator.msg);
}

const output = inflator.result;

For CommonJS:

const { deflate, inflate } = require('pako');

If you need the whole API as an object, use namespace import:

import * as pako from 'pako';

Sometimes you may wish to work with strings — for example, to send stringified objects to a server. Pako's deflate detects the input data type and automatically recodes strings to utf-8 prior to compression. High-level inflate helpers can decode utf-8 output back to JavaScript strings with toText: true.

import { deflate, inflate } from 'pako';

const test = { my: 'super', puper: [456, 567], awesome: 'pako' };

const compressed = deflate(JSON.stringify(test));

const restored = JSON.parse(inflate(compressed, { toText: true }));

Notes

Pako does not contain some specific zlib functions:

  • deflate - methods deflateCopy, deflateBound, deflateParams, deflatePending, deflatePrime, deflateTune.
  • inflate - methods inflateCopy, inflateMark, inflatePrime, inflateGetDictionary, inflateSync, inflateSyncPoint, inflateUndermine.
  • High level inflate/deflate wrappers (classes) may not support some flush modes.

Authors

Personal thanks to:

  • Vyacheslav Egorov (@mraleph) for his awesome tutorials about optimising JS code for v8, IRHydra tool and his advices.
  • David Duponchel (@dduponchel) for help with testing.

Original implementation (in C):

  • zlib by Jean-loup Gailly and Mark Adler.

License

  • MIT - all files, except /src/zlib folder
  • ZLIB - /src/zlib content

版本与发布记录

pako 共发布 36 个版本,首次发布于 2014/02/20;过去 12 个月发布了 5 个版本。

版本发布日期距今
3.0.3latest2026/10/2710 天前
3.0.22026/09/121 个月前
3.0.12026/07/064 个月前
3.0.02026/06/264 个月前
2.2.02026/06/234 个月前
2.1.02022/11/073 年前

关于 pako 的常见问题

pako 是什么?

zlib port to javascript - fast, modularized, with browser support

如何安装 pako?

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

pako 支持 TypeScript 吗?

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

pako 支持 ESM 还是 CommonJS?

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

pako 可以商用吗?

pako 使用 (MIT AND Zlib) 许可。声明的许可为 (MIT AND Zlib),请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

pako 的下载量有多少?

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

pako 还在维护吗?

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