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 :
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