The zlib.gunzip() method is an inbuilt application programming interface of the Zlib module which is used to decompress a chunk of data.
Syntax:
javascript
Output:
javascript
Output:
zlib.gunzip( buffer, options, callback )Parameters: This method accepts three parameters as mentioned above and described below:
- buffer: It can be of type Buffer, TypedArray, DataView, ArrayBuffer, and string.
- options: It is an optional parameter that holds the zlib options.
- callback: It holds the callback function.
// Node.js program to demonstrate the
// gunzip() method
// Including zlib module
const zlib = require("zlib");
// Declaring input and assigning
// it a value string
var input = "Geek";
// Calling gzip method
zlib.gzip(input, (err, buffer) => {
// Calling gunzip method
zlib.gunzip(buffer, (err, buffer) => {
console.log(buffer.toString('utf8'));
});
});
console.log("Data Decompressed...");
Data Decompressed... GeekExample 2:
// Node.js program to demonstrate the
// gunzip() method
// Including zlib module
const zlib = require("zlib");
// Declaring input and assigning
// it a value string
var input = "Geek";
// Calling gzip method
zlib.gzip(input, (err, buffer) => {
// Calling gunzip method
zlib.gunzip(buffer, (err, buffer) => {
console.log(buffer.toString('hex'));
});
});
console.log("Data Decompressed...");
Data Decompressed... 4765656bReference: https://nodejs.org/api/zlib.html#zlib_zlib_gunzip_buffer_options_callback