Open In App

Node.js zlib.deflateRaw() Method

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

Syntax:



zlib.deflateRaw( buffer, options, callback )

Parameters: This method accepts three parameters as mentioned above and described below:

Return Value: It returns the chunk of data after compression.



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

Example 1:




// Node.js program to demonstrate the     
// deflateRaw() method
  
// Including zlib module
const zlib = require("zlib");
  
// Declaring input and assigning
// it a value string
var input = "Nidhi Singh";
  
// Calling deflateRaw method
zlib.deflateRaw(input, (err, buffer) => {
  
    console.log(buffer.toString('hex'));
  
});

Output:

f3cb4cc9c85408cecc4bcf0000

Example 2:




// Node.js program to demonstrate the     
// deflateRaw() method
  
// Including zlib module
const zlib = require("zlib");
  
// Declaring input and assigning
// it a value string
var input = "GeeksforGeeks";
  
// Calling deflateRaw method
zlib.deflateRaw(input, (err, buffer) => {
  
  if(!err) {
    console.log(buffer.toString('hex'));
  
  else {
    console.log(err);
  }
});

Output:

734f4dcd2e4ecb2f7207d100

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


Article Tags :