Open In App

Node.js zlib.createBrotliDecompress() Method

Last Updated : 30 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The zlib.createBrotliDecompress() method is an inbuilt application programming interface of the Zlib module which is used to create a new BrotliDecompress object. 

Syntax:

zlib.createBrotliDecompress( options )

Parameters: This method accepts single parameter options which is an optional parameter that holds the zlib options. 

Return Value: It returns a new BrotliDecompress object. 

The below examples illustrate the use of zlib.createBrotliDecompress() method in Node.js:

 Example 1: 

javascript




// Node.js program to demonstrate the    
// createBrotliDecompress() method
 
// Including zlib module
const zlib = require('zlib');
 
// Calling brotliCompress function to compress data
zlib.brotliCompress('Nidhi', function (err, data) {
    if (err) {
        return console.log('err', err);
    }
 
    // Calling createBrotliDecompress method
    // to decompress the data again
    let gunzip = zlib.createBrotliDecompress();
    gunzip.write(data);
    gunzip.on('data', function (data) {
        console.log(data.toString());
    });
});


Output:

Nidhi

Example 2: 

javascript




// Node.js program to demonstrate the    
// createBrotliDecompress() method
 
// Including zlib module
const zlib = require('zlib');
 
// Calling brotliCompress function to compress data
zlib.brotliCompress('CS-Portal!', function (err, data) {
    if (err) {
        return console.log('err', err);
    }
 
    // Calling createBrotliDecompress method
    // to decompress the data again
    let gunzip = zlib.createBrotliDecompress();
    gunzip.write(data);
    gunzip.on('data', function (data) {
        console.log(data.toString('base64'));
    });
});


Output:

Q1MtUG9ydGFsIQ==

Reference: https://nodejs.org/api/zlib.html#zlib_zlib_createbrotlidecompress_options



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads