Stream Types

In notebook:
FrontEndMasters Networking and Streams
Created at:
2017-09-24
Updated:
2017-09-24
Tags:
backend Node JS JavaScript Fundamentals

stream types

There are many kinds of streams. We've seen two types already: transform (through2) and writable (concat-stream).

  • readable - produces data: you can pipe FROM it (sources)
  • writable - consumes data: you can pipe TO it (destination) e.g. fs.createWriteStream
  • transform - consumes data, producing transformed data, take input and produce output
  • duplex - consumes data separately from producing data (bidirectional network protocols e.g. telephone)

stream types in code

How each of those would look like with the pipe method:

  • readable: readable.pipe(A)
  • writable: A.pipe(writable)
  • transform: A.pipe(transform).pipe(B)
  • duplex: A.pipe(duplex).pipe(A) ☛ this would be a loop

Duplex methods can appear on both sides.