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');
gunzipSync()
is a function of the zlib
module, which allows decompressing a stream of data.
zlib.gunzipSync( buffer, options )
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 parameter used to provide options to the zlib
classes.
The gunzipSync()
method returns decompressed data.
In the following example, we provide an input string to the gzipSync()
method, which compresses the input in line 8. Then, we use the gunzipSync()
method in line 11 to recover the original input string.
// Including zlib moduleconst zlib = require("zlib");//input declarationvar input = "Educative";// Calling gzip method to compress datavar compressed = zlib.gzipSync(input);console.log("Compressed data: ",compressed.toString('utf8'));// Calling gunzip methodvar decompressed = zlib.gunzipSync(compressed);console.log("Decompressed data: ",decompressed.toString('utf8'));
Free Resources