Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between util.pump(streamA, streamB) and streamA.pipe(streamB)?

Tags:

stream

node.js

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?

like image 523
Domenic Avatar asked Mar 15 '12 19:03

Domenic


People also ask

What is pipe stream?

A stream pipe is a UNIX interprocess communication (IPC) facility that allows processes on the same computer to communicate with each other.

What is the correct way to pipe a readable stream and a writable stream?

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.

What does stream PassThrough do?

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.

What is the source of streams piping?

, 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.


1 Answers

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

like image 80
henry.oswald Avatar answered Oct 13 '22 01:10

henry.oswald