Node.js zlib.unzipSync() Method
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:
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.
Return Value: It returns the chunk of data with Unzip.
Below examples illustrate the use of zlib.unzipSync() method in Node.js:
Example 1:
// Node.js program to demonstrate the // zlib.unzipSync() method // Including zlib modulevar zlib = require('zlib'); // Declaring input and assigning// it a value stringvar input = "NidhiSingh"; // Calling gzipSync methodvar gzi = zlib.gzipSync(input); // Calling unzipSync methodvar decom = zlib.unzipSync( new Buffer.from(gzi)).toString('base64'); console.log(decom); |
Output:
TmlkaGlTaW5naA==
Example 2:
// Node.js program to demonstrate the // zlib.unzipSync() method // Including zlib modulevar zlib = require('zlib'); // Declaring input and assigning// it a value stringvar input = "NidhiSingh"; // Calling gzipSync methodvar gzi = zlib.gzipSync(input).toString('hex'); // Calling unzipSync methodvar decom = zlib.unzipSync( new Buffer.from(gzi, 'hex')).toString('hex'); console.log(decom); |
Output:
4e6964686953696e6768
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_unzipsync_buffer_options


