Rajkamal Subramanian
Rajkamal Subramanian

Reputation: 6964

Can a writeable stream be piped to either a readable or wirtable stream

code:

a.pipe(b).pipe(c).pipe(d);

Im node newbie. I read that for piping, the source should be a readable stream and destination should be a writeable stream.

  1. If you see the above code, my assumption is that 'a' is readable stream, 'b' is writable stream. If 'b' is writable stream how is it possible to pipe it further?
  2. how the 'b' writeable stream is piped to 'c'?
  3. Streams and Buffers is being difficult to understand. Any good documentation to read?

Upvotes: 1

Views: 300

Answers (1)

Golo Roden
Golo Roden

Reputation: 150902

Ad 1: Yes, a must be a readable stream, and b must be a writable one. But, streams are not neccessarily either / or, they also can be both: Readable and writeable at the same time. So, b and c are both, hence you can pipe into them, but also pipe from them. Technically they are so-called duplex streams.

Ad 2: Should be answered by now ;-).

Ad 3: Yes, you should definitely check out the stream-handbook by @substack (aka James Halliday). For buffers, see How to use buffers in Node.js by NodeJitsu.

Upvotes: 1

Related Questions