Compression and decompression of data using zlib in Nodejs

For anybody stumbling on this in 2016 (and also wondering how to serialize compressed data to a string rather than a file or a buffer) – it looks like zlib (since node 0.11) now provides synchronous versions of its functions that do not require callbacks:

var zlib = require('zlib');
var input = "Hellow world";

var deflated = zlib.deflateSync(input).toString('base64');
var inflated = zlib.inflateSync(new Buffer(deflated, 'base64')).toString();

console.log(inflated);

Syntax has changed to simply:

var inflated = zlib.inflateSync(Buffer.from(deflated, 'base64')).toString()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)