Created
January 15, 2019 15:02
-
-
Save miguelmota/837926791cedd3d06e909738c76c4578 to your computer and use it in GitHub Desktop.
Node.js gzip compress and decompress example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment