Node.js zlib.inflate() Method
Last Updated :
12 Oct, 2021
The zlib.inflate() method is an inbuilt application programming interface of the Zlib module which is used to decompress a chunk of data.
Syntax:
zlib.inflate( 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.
Return Value: It returns the chunk of data after decompression.
Below examples illustrate the use of zlib.inflate() method in Node.js:
Example 1:
const zlib = require( "zlib" );
var input = "Geeks" ;
zlib.deflate(input, (err, buffer) => {
zlib.inflate(buffer, (err, buffer) => {
console.log(buffer.toString( 'utf8' ));
});
});
|
Output:
Geeks
Example 2:
const zlib = require( "zlib" );
var input = "Nidhi Singh" ;
zlib.deflate(input, (err, buffer) => {
zlib.inflate(buffer, (err, buffer) => {
console.log(buffer.toString( 'hex' ));
});
});
|
Output:
4e696468692053696e6768
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_inflate_buffer_options_callback
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...