V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cheshire
V2EX  ›  Node.js

从多个 readstream pipe 到一个 writeStream 的正确写法是啥?

  •  
  •   cheshire · 2015-06-19 18:01:56 +08:00 · 4053 次点击
    这是一个创建于 3205 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我现在的解决方法是有几个readstream 就创建几个writeStream({flags:'a'}),然后分别监听 finish 事件,在 callback 里面执行 .end() 方法。
    2 条回复    2015-06-24 14:10:44 +08:00
    magicdawn
        1
    magicdawn  
       2015-06-20 07:57:46 +08:00
    concat-stream

    先concat 再pipe ,比你手动concat考虑的多
    tulayang
        2
    tulayang  
       2015-06-24 14:10:44 +08:00
    你先要弄清楚什么是stream 流,pipe代表管道,管道到流只有一个通道,而且是不可逆的。你只能s1.pipe(s2).pipe(s3)。想要自由度,需要编写data事件

    s1.on('data', d1 => {
    s2.on('data', d2=> {
    // code here
    })
    })
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3279 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:11 · PVG 22:11 · LAX 07:11 · JFK 10:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.