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");
Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know.
Knowledge is the only thing that doubles when you spend it.
I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation