The source code looks very similar: pump
, pipe
. Why would I use one instead of the other? Is one simply a better version of the other?
A stream pipe is a UNIX interprocess communication (IPC) facility that allows processes on the same computer to communicate with each other.
To consume a readable stream, we can use the pipe / unpipe methods, or the read / unshift / resume methods. To consume a writable stream, we can make it the destination of pipe / unpipe , or just write to it with the write method and call the end method when we're done.
PassThrough. This Stream is a trivial implementation of a Transform stream that simply passes the input bytes across to the output. This is mainly for testing and some other trivial use cases. Here is an example of Passthrough Stream where it is piping from readable stream to writable stream.
, that implement the input and output components of a pipe. Pipes are used to channel the output from one program (or thread) into the input of another. Piped input and output streams are convenient for methods that produce output to be used as input by someone else.
Stream.pipe is now the preferred method apparently since 0.3.x so try and use that when possible
sources:
https://groups.google.com/forum/?fromgroups#!topic/nodejs/FwdDQvAf4xM
https://stackoverflow.com/a/4591335/424851
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With