Monday, 28 May 2018

008 Node.js Zlib

The Node.js zlib used for compression implemented using Gzip and Deflate/Inflate.zlib module can be added as  

const obj = require('zlib');
 

Below is the code to compress file.

Example 1

const obj = require('zlib');
const gobj = obj.createGzip();
const fs = require('fs');
const inp = fs.createReadStream('myFile.txt');
const out = fs.createWriteStream('myFile.txt.gz');

inp.pipe(gobj).pipe(out);
 


Output :




Below is the code to de compress file.

Example 2
 
const obj = require('zlib');
const gobj = obj.createGzip();
const fs = require('fs');
const inp = fs.createReadStream('myFile.txt.gz');
const out = fs.createWriteStream('myFile.txt');

inp.pipe(gobj).pipe(out);
 

Output :







 




 

No comments:

Post a Comment

Interactive CSS Button Designer Tool – Free & Fast

What is Button ?                               Button is an element of HTML. HTML is used to design Web Pages, Websites and Web applications...