The zlib
module in Node.js provides compression and decompression functionality utilizing Gzip, Deflate/Inflate, and Brotli.
It can be accessed in your program with:
const zlib = require('zlib');
createGunzip()
is a function of the zlib
module that creates a Gunzip
object.
zlib.createGunzip( options )
options
is an optional parameter used to provide options to the zlib
classes.The createGunzip()
method returns a new Gunzip
object.
In the following example, we first compress the data in line 4 using the gzip
method. Then, we create the gunzip
object using the createGunzip()
method (line 10) to decompress the data.
var zlib = require('zlib'); // First we compress the data zlib.gzip('Educative', (err, buffer) => { if (err) { return console.log('err', err); } // Calling createGunzip method to decompress the data again var gunzip = zlib.createGunzip(); gunzip.write(buffer); gunzip.on('data', (buffer) => { console.log(buffer.toString()); }); });
RELATED TAGS
CONTRIBUTOR
View all Courses