How to chain write stream, immediately with a read stream in Node.js 0.10?

前端 未结 3 961
自闭症患者
自闭症患者 2020-12-17 17:37

The following line will download an image file from a specified url variable:

var filename = path.join(__dirname, url.replace(/^.*[\\\\\\/]/, \'         


        
3条回答
  •  隐瞒了意图╮
    2020-12-17 17:47

    I think the confusion in chaining the pipes is caused by the fact that the pipe method implicitly "makes choices" on it's own on what to return. That is:

    readableStream.pipe(writableStream) // Returns writable stream
    readableStream.pipe(duplexStream) // Returns readable stream
    

    But the general rule says that "You can only pipe a Writable Stream to a Readable Stream." In other words only Readable Streams have the pipe() method.

提交回复
热议问题