{"library":"pako","title":"Pako - JavaScript Zlib Compression","description":"Pako is a high-performance JavaScript port of the zlib library, designed for fast data compression and decompression directly within web browsers and Node.js environments. The current stable version is 2.1.0. It aims to provide binary-compatible results with the original C zlib implementation (v1.2.8 as per the README), demonstrating near-native speed in modern JavaScript engines for CPU-intensive tasks. Pako differentiates itself by its modular design, allowing individual components to be used or browserified, and its support for both raw deflate/inflate streams and gzip format. It handles various input types, including automatic UTF-8 recoding for strings during compression and optional UTF-8 string output for decompression. Its release cadence is generally feature-driven and as needed, rather than fixed time intervals.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pako"],"cli":null},"imports":["const pako = require('pako');","const { Deflate } = require('pako');","const { inflate } = require('pako');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const pako = require('pako');\n\nconst data = { message: 'Hello, pako!', timestamp: Date.now(), items: ['a', 'b', 'c'] };\nconst stringifiedData = JSON.stringify(data);\n\nconsole.log('Original size (bytes):', Buffer.byteLength(stringifiedData, 'utf8'));\n\n// Compress stringified data\nconst compressed = pako.deflate(stringifiedData, { level: 9 }); // Use highest compression level\nconsole.log('Compressed size (bytes):', compressed.length);\n\n// Decompress back to string\nconst restoredString = pako.inflate(compressed, { to: 'string' });\nconsole.log('Decompressed string matches original:', restoredString === stringifiedData);\n\nconst restoredData = JSON.parse(restoredString);\nconsole.log('Restored data:', restoredData);\n\n// Demonstrating stream interface for larger data\nconst deflator = new pako.Deflate();\ndeflator.push(new TextEncoder().encode('First chunk of data. '), false);\ndeflator.push(new TextEncoder().encode('Second chunk, and this is the end.'), true);\n\nif (deflator.err) {\n  console.error('Deflate error:', deflator.msg);\n} else {\n  console.log('Stream compressed data length:', deflator.result.length);\n}","lang":"javascript","description":"Demonstrates basic string compression/decompression using `deflate` and `inflate` with string conversion, including an example of the streaming API for larger data handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}