欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
  });
}