流是用于在 Node.js 中处理流数据的抽象接口,流可以是可读的、可写的、下面例子实现一个读取和写入成压缩文件的例子。同时也引用gzip模块

    1. const fs = require('fs')
    2. const zlib = require('zlib')
    3. const gzip = zlib.createGzip()
    4. const readStream = fs.createReadStream('./logs.txt')
    5. const writeStream = fs.createWriteStream('./logs.gzip')
    6. readStream
    7. .pipe(gzip)
    8. .pipe(writeStream)