Check out a free preview of the full Networking and Streams course:
The "Stream Types" Lesson is part of the full, Networking and Streams course featured in this preview video. Here's what you'd learn in this lesson:

James reviews the different types of streams: readable, writable, transform, and duplex.

Get Unlimited Access Now

Transcript from the "Stream Types" Lesson

>> So now we can talk a little bit about different kinds of stream types. We've already seen a few examples of some streams. We've seen transform streams with through2, through2 by default. Even if you never use the readable side, even if you never use the writable side, through2 is always gonna give you a transform stream.

[00:00:18] And concat-stream is always gonna be a writable stream. So you can think of readable streams as being producers of data or sources, like from where you get data. They're Like fs.createreadstream is another example of a readable stream. Writable streams are sinks of data, destinations where the data will flow to.

[00:00:41] There's a method that we'll get into called fs.createwritestream. That's good example of this, that writes data into a file on disk. There's also a transform streams. These are things that sort of take input and produce output. Then there's duplex streams which are more complicated, but you can think of things like bidirectional network protocols as duplex streams.

[00:01:05] Or you might also think of them as kinda a telephone. We'll get a little bit more into what those look like exactly because those are kinda the hardest to fully grok. So here's kind of what each of these looks like with the pipe method. So you pipe from a readable stream into some kind of writable stream.

[00:01:30] Transform streams and duplex streams are both readable and writable. So they are gonna appear on either side of this kinda thing. Writable streams are what you pipe to. So, inside of the arguments to the pipe functions is where a writable stream would go. With transform streams, you sort of put them between two streams.

[00:01:52] Even if you never hook up the other end of the stream like either end. If you have a writable stream, then you could do that. And a duplex stream is the oddball. And this looks like it would be a loop maybe, if you're thinking about how streams that'll work.

[00:02:09] But, if you see A.pipeB.pipeA, you're definitely dealing with a duplex stream.