【每日一包0022】through2-map,through2-filter,stream-spigot

[github地址:https://github.com/ABCDdouyae…]

through2-map

对于through2包的transformFunction参数封装为map函数形式

  • {wantStrings: true}输出的chunk为字符串形式而不是buffer
  • 默认objectModal为true
const map = require('through2-map');
const fs = require('fs');

let trucate = map({wantStrings: true}, (chunk)=>{
    console.log(chunk);
    let a = chunk.replace(/[,:]/g, '🌞')
    return a;
})

fs.createReadStream('./test/1.txt')
  .pipe(trucate)
  .pipe(fs.createWriteStream('./test/2.txt'))
  • map.ctor([options,] fn)与through2.ctor类似
  • map.objCtor([options,] fn)与through2.ctor({objectMode: true}, transformFunction)类似

through2-filter

对于through2包的transformFunction参数封装为filter函数形式,API与through2-map一样

stream-spigot

可读流生成器,用于测试和转换一些惰性函数为简单的可读流,或者创建可读流

    原文作者:王炜
    原文地址: https://segmentfault.com/a/1190000017262655
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞