流是用于在 Node.js 中处理流数据的抽象接口,流可以是可读的、可写的、下面例子实现一个读取和写入成压缩文件的例子。同时也引用gzip模块
const fs = require('fs')
const zlib = require('zlib')
const gzip = zlib.createGzip()
const readStream = fs.createReadStream('./logs.txt')
const writeStream = fs.createWriteStream('./logs.gzip')
readStream
.pipe(gzip)
.pipe(writeStream)