What is createInflate() in Node.js ?
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');
createInflate() is a function of the zlib module that creates an Inflate object. This object is used to decompress a deflate stream. We use the deflate function to compress data.
Syntax
zlib.createInflate( options )
Parameters
optionsis an optional parameter used to provide options to thezlibclasses.
Return value
The createInflate() method returns a new Inflate object.
Example
In the program below, we will learn how to use the createInflate method to decompress data.
-
First, we compress the
inputdata using thedeflatemethod provided by thezlibmodule in line 4. -
Then, we create an
Inflateobject used to decompress the compressedinputin line 13. -
We use the
toStringmethod, 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.deflate(input, function(err, data){if (err){return console.log('err', err);}//The createInflate method allows us to decompress the datavar decompress = zlib.createInflate();decompress.write(data);decompress.on('data', function (data){console.log(data.toString());});});
Free Resources