The zlib.brotliCompress() method is an inbuilt application programming interface of the Zlib module which is used to compresses a chunk of data.
Syntax:
javascript
Output:
javascript
Output:
zlib.brotliCompress( 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.
// Node.js program to demonstrate the
// brotliCompress() method
// Including zlib module
const zlib = require("zlib");
// Declaring input and assigning
// it a value string
var input = "Computer Science";
// Calling brotliCompress method
zlib.brotliCompress(input, (err, buffer) => {
console.log(buffer.toString('base64'));
});
Gw8A+CUAqhBDSpVv9iA=Example 2:
// Node.js program to demonstrate the
// brotliCompress() method
// Including zlib module
const zlib = require("zlib");
// Declaring input and assigning
// it a value string
var input = "Computer Science";
// Calling brotliCompress method
zlib.brotliCompress(input, (err, buffer) => {
if(!err) {
console.log(buffer.toString('hex'));
}
else {
console.log(err);
}
});
1b0f00f82500aa10434a956ff620Reference: https://nodejs.org/api/zlib.html#zlib_zlib_brotlicompress_buffer_options_callback