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

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.

Share this Article Facebook
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 -->