const zlib = require('zlib');
const buf = Buffer.from('hello world', 'utf-8');
zlib.gzip(buf, (err, compressed) => {
if (err) {
console.error(err);
}
console.log(compressed);
// <Buffer 1f 8b 08 00 00 00 00 00 00 13 cb 48 cd c9 c9 57 28 cf 2f ca 49 01 00 85 11 4a 0d 0b 00 00 00>
zlib.unzip(compressed, (err, decompressed) => {
if (err) {
console.error(err);
}
console.log(decompressed.toString()); // "hello world"
});
});
Try it on runkit.com or visit the original gist page.
Hi,
Can you share your node version? Because I couldn't use zlib package with nodejs 18.14.0 version(latest).
Thank you