Node.js | zlib.close() Method
The zlib.close() method is an inbuilt application programming interface of the Zlib module which is used to close the underlying handle.
Syntax:
zlib.close( callback )
Parameters: This method accepts single parameter callback which holds the callback function.
Below examples illustrate the use of zlib.close() method in Node.js:
Example 1:
// Node.js program to demonstrate the // zlib.close() method // Including zlib moduleconst zlib = require('zlib'); // Constructing createGzip and createGunzipconst input = zlib.createGzip();const output = zlib.createGunzip(); // Pipinginput.pipe(output); // Write to streaminput.write('GeeksforGeeks'); // Calling flush methodinput.flush(); // Calling close methodinput.close(); // Check outputoutput.on('data', (d) => { console.log('Input: Data flush received ' + d.length + ' bytes');});console.log("Closed!"); |
Output:
Closed!
Example 2:
// Node.js program to demonstrate the // zlib.close() method // Including zlib and fs moduleconst zlib = require("zlib");const fs = require('fs'); // Creating readable Streamconst inp = fs.createReadStream('input.text'); // Creating writable streamconst out = fs.createWriteStream('input.txt.gz'); // Calling createDeflateRaw methodconst defR = zlib.createDeflateRaw(); // Calling close methoddefR.close(); // Pipinginp.pipe(defR).pipe(out);console.log("Program Completed!"); |
Output:
Program Completed!
Here, piping is not done as close method closes the hidden handle.
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_close_callback


