pako deflate and gzip roundtrips: working versions (tested 2026-10-16)
Compress and decompress Uint8Array and string payloads with pako deflate/inflate and gzip/ungzip, checking roundtrip equality and using the level option.
passed5 passed · 0 failed2026-10-16 02:18 UTC- Status
- passed
- Last passed
- 2026-10-16 02:18 UTC
- Tests
- 5 / 5
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
pako@3.0.2@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38839686104
The code
Exactly the files that passed. Your agent can pull them with get_recipe("pako-deflate-gzip") (install), or see them on GitHub.
package.json
{
"name": "pako-deflate-gzip",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"pako": "3.0.2"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/codec.ts
import { deflate, gzip, inflate, ungzip } from "pako";
const decoder = new TextDecoder();
type LevelOptions = { level?: number };
function withLevel(level?: number): LevelOptions {
return level === undefined ? {} : { level };
}
export function deflateBytes(input: Uint8Array, level?: number): Uint8Array {
return deflate(input, withLevel(level));
}
export function inflateBytes(input: Uint8Array): Uint8Array {
return inflate(input);
}
export function deflateText(input: string, level?: number): Uint8Array {
return deflate(input, withLevel(level));
}
export function inflateText(input: Uint8Array): string {
return decoder.decode(inflate(input));
}
export function gzipText(input: string, level?: number): Uint8Array {
return gzip(input, withLevel(level));
}
export function ungzipText(input: Uint8Array): string {
return decoder.decode(ungzip(input));
}
test/codec.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { deflate as pakoDeflate } from "pako";
import {
deflateBytes,
deflateText,
gzipText,
inflateBytes,
inflateText,
ungzipText,
} from "../src/codec.ts";
test("deflate/inflate roundtrips a Uint8Array", () => {
const input = new Uint8Array([0, 1, 2, 3, 128, 200, 250, 255]);
const compressed = deflateBytes(input);
assert.deepEqual(inflateBytes(compressed), input);
});
test("deflate/inflate roundtrips a string", () => {
const text = "The quick brown fox jumps over the lazy dog. ".repeat(40);
const compressed = deflateText(text);
assert.equal(inflateText(compressed), text);
});
test("gzip/ungzip roundtrips a string", () => {
const text = "gzip roundtrip payload ".repeat(60);
const compressed = gzipText(text);
assert.ok(compressed.length < text.length);
assert.equal(ungzipText(compressed), text);
});
test("compressed output is smaller for repetitive input", () => {
const text = "abcabcabc".repeat(2000);
const compressed = pakoDeflate(text);
assert.ok(compressed.length < text.length);
});
test("deflate honors the level option", () => {
const text = "repetitive payload ".repeat(1000);
const fastest = pakoDeflate(text, { level: 1 });
const smallest = pakoDeflate(text, { level: 9 });
assert.ok(smallest.length <= fastest.length);
assert.equal(inflateText(fastest), text);
assert.equal(inflateText(smallest), text);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.