Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js

What is createGunzip() in Node.js zlib module?

Adnan Abbas

The zlib module in Node.js provides compression and decompression functionality utilizing Gzip, Deflate/Inflate, and Brotli.

It can be accessed in your program with:

const zlib = require('zlib');

createGunzip() is a function of the zlib module that creates a Gunzip object.

Syntax

zlib.createGunzip( options )

Parameters

  • options is an optional parameter used to provide options to the zlib classes.

Return value

The createGunzip() method returns a new Gunzip object.

Example

In the following example, we first compress the data in line 4 using the gzip method. Then, we create the gunzip object using the createGunzip() method (line 10) to decompress the data.

var zlib = require('zlib');
  
// First we compress the data
zlib.gzip('Educative', (err, buffer) => {
  if (err) { 
    return console.log('err', err);
  }
  
  // Calling createGunzip method to decompress the data again
  var gunzip = zlib.createGunzip();
  gunzip.write(buffer);
  gunzip.on('data', (buffer) => 
   {
      console.log(buffer.toString());
  });
});
createGunzip() in Node

RELATED TAGS

node.js

CONTRIBUTOR

Adnan Abbas
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring