zlib module is used to provide compression and decompression functionalities in node.js, In simple words, it is used to zip or unzip files. These functionalities are implemented using GZIP and deflate/inflate.
var zlib = require('zlib');
Compressing and decompressing a file can be done by piping the source stream data into a destination stream through zlib stream.
const zlib = require('zlib'); const gzip = zlib.createGzip(); const fs = require('fs'); const inp = fs.createReadStream('test-input.txt'); const out = fs.createWriteStream('test-input.txt.qz'); inp.pipe(gzip).pipe(out);
var zlib = require('zlib'); var fs = require('fs'); var unzip = zlib.createUnzip(); var read = fs.createReadStream('test-input.txt.qz'); var write = fs.createWriteStream('unzip-test.txt'); //Transform stream which is unzipping the zipped file read.pipe(unzip).pipe(write); console.log("Decompressed");
Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.