Node.js zlib.brotliDecompressSync() Method
Last Updated :
30 Mar, 2023
The zlib.brotliDecompressSync() method is an inbuilt application programming interface of the Zlib module which is used to decompress a chunk of data with BrotliDecompress.
Syntax:
zlib.brotliDecompressSync( buffer, options )
Parameters: This method accepts two parameters as mentioned above and described below:
- buffer: This parameter holds the buffer of type Buffer, TypedArray, DataView, ArrayBuffer, and string.
- options: This parameter holds the value of the zlib option.
Return Value: It returns the chunk of data with BrotliDecompress.
The below examples illustrate the use of zlib.brotliDecompressSync() method in Node.js:
Example 1:
javascript
const zlib = require( 'zlib' );
let input = "Nidhi" ;
let brotliCom = zlib.brotliCompressSync(input);
let brotliDec = zlib.brotliDecompressSync(
new Buffer.from(brotliCom)).toString( 'hex' );
console.log(brotliDec);
|
Output:
4e69646869
Example 2:
javascript
const zlib = require( 'zlib' );
let input = "Nidhi" ;
let brotliCom = zlib.brotliCompressSync(input).toString( 'hex' )
let brotliDec = zlib.brotliDecompressSync(
new Buffer.from(brotliCom, 'hex' )).toString( 'base64' );
console.log(brotliDec);
|
Output:
TmlkaGk=
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_brotlidecompresssync_buffer_options
Share your thoughts in the comments
Please Login to comment...