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: javascript
// 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);
Output:
TmlkaGlTaW5naA==
Example 2: javascript
// 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);
Output:
4e6964686953696e6768
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_unzipsync_buffer_options
Comment

Explore