Skip to content
Related Articles

Related Articles

Improve Article

Node.js | zlib.createGunzip() Method

  • Last Updated : 05 Mar, 2020

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

Syntax:

zlib.createGunzip( options )

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

Return Value: It returns a new Gunzip object.

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



Example 1:




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

Output:

GeeksforGeeks

Example 2:




// Node.js program to demonstrate the     
// createGunzip() method
  
// Including zlib module
var zlib = require('zlib');
  
// Calling gzip function to compress data
zlib.gzip('GfG', function(err, data) {
  if (err) { 
    return console.log('err', err);
  }
  
  // Calling createGunzip method
  // to decompress the data again
  var gunzip = zlib.createGunzip();
  gunzip.write(data);
  gunzip.on('data', function (data)
   {
      // Encoding the data
      console.log(data.toString('hex'));
  });
});

Output:

476647

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :