cheshire
5.11D
V2EX  ›  Node.js

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

  •  
  •   cheshire ·
    PRO
    · Jun 19, 2015 · 4891 views
    This topic created in 3981 days ago, the information mentioned may be changed or developed.
    我现在的解决方法是有几个readstream 就创建几个writeStream({flags:'a'}),然后分别监听 finish 事件,在 callback 里面执行 .end() 方法。
    2 replies    2015-06-24 14:10:44 +08:00
    magicdawn
        1
    magicdawn  
       Jun 20, 2015
    concat-stream

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

    s1.on('data', d1 => {
    s2.on('data', d2=> {
    // code here
    })
    })
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5530 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 08:21 · PVG 16:21 · LAX 01:21 · JFK 04:21
    ♥ Do have faith in what you're doing.