Open In App

Node.js zlib.brotliDecompressSync() Method

Last Updated : 28 Apr, 2025
Suggest changes
Share
Like Article
Like
Report

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

Output:

4e69646869

Example 2: 

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


Explore