Open In App

Node.js zlib.inflateRaw() Method

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

Syntax:



zlib.inflateRaw( buffer, options, callback )

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

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



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

Example 1:




// Node.js program to demonstrate the     
// inflateRaw() 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) => {
  
      // Calling inflateRaw
      zlib.inflateRaw(buffer, (err, buffer) => {
        console.log(buffer.toString('utf8'));
    });
});

Output:

GeeksforGeeks

Example 2:




// Node.js program to demonstrate the     
// inflateRaw() 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) => {
  
      // Calling inflateRaw
      zlib.inflateRaw(buffer, (err, buffer) => {
        console.log(buffer.toString('base64'));
    });
});

Output:

R2Vla3Nmb3JHZWVrcw==

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


Article Tags :