node zlib壓縮模塊了解一下
壓縮:
從index.html壓縮成index.html.gz
const zlib = require('zlib');
const gzip = zlib.createGzip();
const fs = require('fs');
const inp = fs.createReadStream('index.html');
const out = fs.createWriteStream('index.html.gz');
inp.pipe(gzip)
.on('error', () => {
// 處理錯誤
})
.pipe(out)
.on('error', () => {
// 處理錯誤
});
解壓:
從index.html.gz解壓為index.html
const zlib = require('zlib');
const gzip = zlib.createGzip();
const fs = require('fs');
const inp = fs.createReadStream('index.html.gz');
const out = fs.createWriteStream('index.html');
inp.pipe(gzip)
.on('error', () => {
// 處理錯誤
})
.pipe(out)
.on('error', () => {
// 處理錯誤
});
作者:Vam的金豆之路
主要領(lǐng)域:前端開發(fā)
我的微信:maomin9761
微信公眾號:前端歷劫之路