Node.js zlib.unzipSync() Method
Last Updated :
11 Oct, 2021
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:
var zlib = require( 'zlib' );
var input = "NidhiSingh" ;
var gzi = zlib.gzipSync(input);
var decom = zlib.unzipSync(
new Buffer.from(gzi)).toString( 'base64' );
console.log(decom);
|
Output:
TmlkaGlTaW5naA==
Example 2:
var zlib = require( 'zlib' );
var input = "NidhiSingh" ;
var gzi = zlib.gzipSync(input).toString( 'hex' );
var 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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...