Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js zlib.brotliCompressSync() Method

  • Last Updated : 08 Oct, 2021

The zlib.brotliCompressSync() method is an inbuilt application programming interface of Zlib module which is used to compress a chunk of data with BrotliCompress.

Syntax:

zlib.brotliCompressSync( 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: It is an optional parameter.

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

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

Example 1:




// Node.js program to demonstrate the     
// zlib.brotliCompressSync() method  
  
// Including zlib module
var zlib = require('zlib');
  
// Declaring input and assigning
// it a value string
var input = "0123456789";
  
// Calling brotliCompressSync method
var brotliCom = zlib.brotliCompressSync(input);
  
console.log(brotliCom);

Output:

// Buffer 8b 04 80 30 31 32 33 34 35 36 37 38 39 03

Example 2:




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

Output:

8b04803031323334353637383903

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!