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

Related Articles

Node.js zlib.createInflate() Method

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

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

Syntax:

zlib.createInflate( options )

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

Return Value: It returns a new Inflate object. 

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

Example 1: 

javascript




// Node.js program to demonstrate the    
// createInflate() method
 
// Including zlib module
const zlib = require('zlib');
 
// Calling deflate function to compress data
zlib.deflate('Hello World!', function (err, data) {
    if (err) {
        return console.log('err', err);
    }
 
    // Calling createInflate method
    // to decompress the data again
    const gunzip = zlib.createInflate();
    gunzip.write(data);
    gunzip.on('data', function (data) {
        console.log(data.toString());
    });
});

Output:

Hello World!

Example 2: 

javascript




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

Output:

4465636f6d707265737365642e2e

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


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