cccccc

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');	

Compress a file :

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); 

DeCompress the file in NodeJS :


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");

About Author

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

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Protractor Online Training : We have closed registration for training

Please do email to chercher.tech@gmail.com for any queries

If you already registered then please do check your email for the Webex link
Subscribe -->