Skip to content
Related Articles

Related Articles

Improve Article

Node.js | zlib.brotliDecompressSync() Method

  • Last Updated : 23 Mar, 2020

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, string.
  • options: This parameter holds the zlib options value.

Return Value: It returns the chunk of data with BrotliDecompress.

Below examples illustrate the use of zlib.brotliDecompressSync() method in Node.js:



Example 1:




// Node.js program to demonstrate the     
// zlib.brotliDecompressSync() method  
  
// Including zlib module
var zlib = require('zlib');
  
// Declaring input and assigning
// it a value string
var input = "Nidhi";
  
// Calling brotliDecompressSync method
var brotliCom = zlib.brotliCompressSync(input);
var brotliDec = zlib.brotliDecompressSync(
    new Buffer.from(brotliCom)).toString('hex');
  
console.log(brotliDec);

Output:

4e69646869

Example 2:




// Node.js program to demonstrate the     
// zlib.brotliDecompressSync() method  
  
// Including zlib module
var zlib = require('zlib');
  
// Declaring input and assigning
// it a value string
var input = "Nidhi";
  
// Calling brotliDecompressSync method
var brotliCom = zlib.brotliCompressSync(input).toString('hex')
var 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




My Personal Notes arrow_drop_up
Recommended Articles
Page :