What is inflateRaw() 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');
inflateRaw() is a function of the zlib module, which allows decompressing a stream of data.
Syntax
zlib.inflateRaw( buffer, options, callback )
Parameters
-
bufferis the data to be decompressed. It can be of any type, such as Buffer, TypedArray, DataView, ArrayBuffer, or string. -
optionsis an optional argument used to provide options to thezlibclasses. -
callbackis the call-back function that is executed.
Return value
The inflateRaw() method returns decompressed data.
Example
In the following example, we provide an input string to the deflateRaw() method, which compresses the input in line 8. Then we use the inflateRaw() method to recover the original input string.
We provide the compressed data
bufferand the callback function as arguments to theinflateRaw()method.
// Including zlib moduleconst zlib = require("zlib");//input declarationvar input = "Educative Inc.";// Calling zlib.deflateRaw method to compress datazlib.deflateRaw(input, (err, buffer) => {console.log("Compressed data: ",buffer.toString('utf8'));// Calling zlib.inflateRawzlib.inflateRaw(buffer, (err, buffer) => {console.log("Decompressed data: ",buffer.toString('utf8'));});});
Free Resources