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)

更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/119836266

posted @ 2022-06-13 12:02  忘川信使  阅读(43)  评论(0编辑  收藏  举报