MCPcopy Index your code
hub / github.com/nodeca/pako

github.com/nodeca/pako @3.0.0 sqlite

repository ↗ · DeepWiki ↗ · release 3.0.0 ↗
145 symbols 436 edges 41 files 17 documented · 12% 29 cross-repo links
README

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

Extension points exported contracts — how you extend this code

InflateOptions (Interface)
(no doc)
src/inflate.ts
DeflateOptions (Interface)
(no doc)
src/deflate.ts

Core symbols most depended-on inside this repo

push
called by 49
src/inflate.ts
createSample
called by 40
support/build_fixtures.mjs
deflate
called by 39
src/deflate.ts
put_byte
called by 31
src/zlib/deflate.mjs
inflate
called by 19
src/inflate.ts
crc32
called by 18
src/zlib/crc32.mjs
send_bits
called by 14
src/zlib/trees.mjs
flush_pending
called by 13
src/zlib/deflate.mjs

Shape

Function 108
Class 18
Method 17
Interface 2

Languages

TypeScript100%

Modules by API surface

src/zlib/deflate.mjs34 symbols
src/zlib/trees.mjs32 symbols
src/zlib/inflate.mjs16 symbols
src/deflate.ts11 symbols
src/inflate.ts10 symbols
benchmark/benchmark.mjs5 symbols
src/zlib/zstream.mjs3 symbols
src/zlib/gzheader.mjs3 symbols
test/zlib/inflate_cover.test.mjs2 symbols
test/zlib/binary_compare.test.mjs2 symbols
test/strings.test.mjs2 symbols
test/helpers.mjs2 symbols

Dependencies from manifests, versioned

@types/node26.0.0 · 1×
ansi0.3.1 · 1×
benchmark2.1.4 · 1×
c811.0.0 · 1×
eslint9.39.4 · 1×
gh-pages6.3.0 · 1×
neostandard0.13.0 · 1×
rollup4.62.2 · 1×
rollup-plugin-dts6.4.1 · 1×
typedoc0.28.19 · 1×
typescript6.0.3 · 1×
vite8.0.14 · 1×

For agents

$ claude mcp add pako \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact