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');
createInflateRaw()
is a function of the zlib
module that creates an InflateRaw
object. This object is used to decompress a raw deflate stream.
We use the raw deflate function to compress data.
zlib.createInflateRaw( options )
options
is an optional parameter used to provide options to the zlib
classes.The createInflateRaw()
method returns a new InflateRaw
object.
In the program below, we will learn how to use the createInflateRaw
method to decompress data.
First, we compress the input
data using the deflateRaw
method provided by the zlib
module in
line 4.
Then, we create an InflateRaw
object used to decompress the compressed input
in line 11.
We use the toString
method, which converts the decompressed data stream to text, and then we print it.
var zlib = require('zlib');var input = 'Educative Inc.'// Calling deflate function to compress datazlib.deflateRaw(input, function(err, data){if (err) {return console.log('err', err);}//The createInflateRaw method allows us to decompress the datavar decompress = zlib.createInflateRaw();decompress.write(data);decompress.on('data', function (data){console.log(data.toString());});});
Free Resources