Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js zlib.createUnzip() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Syntax:

zlib.createUnzip( options )

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

Return Value: It returns a new Unzip object. 

The below examples illustrate the use of zlib.createUnzip() method in Node.js: 

Example 1: In this example, we will see the use of zlib.createUnzip() method.

javascript




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

Output:

Nidhi Singh

Example 2: In this example, we will see the use of the createUnzip() method.

javascript




// Node.js program to demonstrate the   
// createUnzip() method
 
// Including zlib module
const zlib = require('zlib');
 
// Calling gzip function to compress data
zlib.gzip('Nidhi Singh', function (err, data) {
    if (err) {
        return console.log('err', err);
    }
    // Calling createUnzip method
    // to decompress the data again
    const unzip = zlib.createUnzip();
    unzip.write(data);
    unzip.on('data', function (data) {
        console.log(data.toString('hex'));
    });
});

Output:

4e696468692053696e6768

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


My Personal Notes arrow_drop_up
Last Updated : 04 Apr, 2023
Like Article
Save Article
Similar Reads
Related Tutorials