The zlib.unzipSync() method is an inbuilt application programming interface of the Zlib module which is used to decompress a chunk of data with Unzip.
Syntax:
javascript
Output:
javascript
Output:
zlib.unzipSync( buffer, options )Parameters: This method accepts two 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.
// Node.js program to demonstrate the
// zlib.unzipSync() method
// Including zlib module
var zlib = require('zlib');
// Declaring input and assigning
// it a value string
var input = "NidhiSingh";
// Calling gzipSync method
var gzi = zlib.gzipSync(input);
// Calling unzipSync method
var decom = zlib.unzipSync(
new Buffer.from(gzi)).toString('base64');
console.log(decom);
TmlkaGlTaW5naA==Example 2:
// Node.js program to demonstrate the
// zlib.unzipSync() method
// Including zlib module
var zlib = require('zlib');
// Declaring input and assigning
// it a value string
var input = "NidhiSingh";
// Calling gzipSync method
var gzi = zlib.gzipSync(input).toString('hex');
// Calling unzipSync method
var decom = zlib.unzipSync(
new Buffer.from(gzi, 'hex')).toString('hex');
console.log(decom);
4e6964686953696e6768Reference: https://nodejs.org/api/zlib.html#zlib_zlib_unzipsync_buffer_options