import { Deflate, Inflate, deflate, inflate } from 'pako';// Deflate//const input = new Uint8Array();//... fill input data hereconst output = deflate(input);// Inflate (simple wrapper can throw exception on broken stream)//const compressed = new Uint8Array();//... fill data to uncompress heretry { const result = inflate(compressed); // ... continue processing} catch (err) { console.log(err);}//// Alternate interface for chunking & without exceptions
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.