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');
deflateRaw()
is a function of the zlib
module, which allows compressing a stream of data.
zlib.deflateRaw( buffer, options, callback )
buffer
is the data to be decompressed. It can be of any type, such as Buffer, TypedArray, DataView, ArrayBuffer, or string.
options
is an optional argument used to provide options to the zlib
classes.
callback
is the call-back function that is executed.
The deflateRaw()
method returns compressed data.
In the following example, we provide an input string to the deflateRaw()
method, which compresses the input in line 8.
// Including zlib moduleconst zlib = require("zlib");//input declarationvar input = "Educative Inc.";// Calling zlib.deflateRaw to compress datazlib.deflateRaw(input, (err, buffer) => {console.log("Compressed data: ",buffer.toString('utf8'));});