Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created August 26, 2012 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/3478356 to your computer and use it in GitHub Desktop.
Save dominictarr/3478356 to your computer and use it in GitHub Desktop.

Readable Stream

A stream that produces output. A one way interface, like a radio.

         ,----stream---------
 user<---|emits 'data', 'end'
         |
         |
         `-------------------

Writable Streams

A stream that accepts input. A one way interface, like a tape-recorder.

Diagram

         ,----stream---------
 user--->|write(), end()
         |
         |
         `-------------------

Through/Filter Stream

A stream that transforms input into output.
A through stream is like a meat grinder.
Mince comes out, but only when you put something in.

  user--,
        |
        v
 ,-------------------.
 |   write(), end()  |
 |                   |
 |emits 'end', 'data'|
 `-------------------`
        |
        |
  user<-`

Duplex Stream

A stream that enables two-way communication with some remote/complex object.

A duplex stream is like a telephone.
Although your speech may be a reaction to mine,
it is also the result of the crazy workings of your own brain,
and the strange things you are looking at and smelling.

It is important to understand the difference between a through stream, and a duplex stream.

                               |
             ,--------------------,
             |                    |
user ------->| write(), end() ======>   S O M E 
             |                    |
             |                    |     T H I N G
user <-------|emits 'data', 'end' <==
             |                    |     E L S E
             `--------------------`
                               |
@Raynos
Copy link

Raynos commented Aug 26, 2012

A duplex stream is also used to give a single interface for two other streams. For example a player is a duplex of a writable UI widget and a readable keyboard input stream.

I think remote/complex vs joining two streams together is an important distinquishion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment