-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.js
26 lines (23 loc) · 887 Bytes
/
zip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const zlib=require('zlib');
const path=require('path');
const fs= require('fs');
const gzip = (filePath,dstPath)=> {
var readSt=fs.createReadStream(filePath);
var writeSt=fs.createWriteStream(dstPath);
readSt.pipe(zlib.createGzip()).pipe(writeSt).on('finish',function(){
console.log("done");})
};
const gunzip = (filePath,dstPath)=> {
var readSt=fs.createReadStream(filePath);
var writeSt=fs.createWriteStream(dstPath);
readSt.pipe(zlib.createGunzip()).on('error',function(error){console.log(error);}).pipe(writeSt).on('finish',
function(){console.log('done');});
};
gzip(__dirname+'/bigfile.txt',__dirname+'/bigfile.txt.gz');
gunzip(__dirname+'/bigfile2.txt.gz',__dirname+'/bigfile2.txt');
// var newfile=fs.createWriteStream('./bigfile.txt');
// for(let i=0;i<10e5;i++)
// {
// newfile.write("this makes a big text file");
// }
// newfile.end;