node.js - gzip压缩
程序员文章站
2024-03-14 09:26:22
...
/**
* gzip压缩
* @param {*} inpath
* @param {*} outpath
* @param {*} callback
*/
var zlib = require('zlib');
function gZip(inpath, outpath, callback) {
let readStream = fs.createReadStream(inpath);
let writeStream = fs.createWriteStream(outpath);
readStream.pipe(zlib.createGzip()).pipe(writeStream);
writeStream.on('close', (data) => {
//success
});
writeStream.on('error', (error) => {
//error
});
}
上一篇: 用blob下载文件