Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node Streams

Node Streams

old and new

Charles Julian Knight

April 17, 2014
Tweet

More Decks by Charles Julian Knight

Other Decks in Programming

Transcript

  1. Streams in Node.js the old, the new, and the why

    Charles Julian Knight @ c h a r l e s j u l i a n k
  2. Concept: pipes "We should have some ways of coupling programs

    like garden hose -- screw in another segment when it becomes when it becomes necessary to massage data in another way. This is the way of IO also." -- Douglas McIlroy, 1964
  3. Readable Examples f s . c r e a t

    e R e a d S t r e a m h t t p . I n c o m i n g M e s s a g e Implement u t i l . i n h e r i t s ( m y S t r e a m , s t r e a m . R e a d a b l e ) ; m y S t r e a m . p r o t o t y p e . r e a d = f u n c t i o n ( ) . . .
  4. Writable Examples f s . c r e a t

    e W r i t e S t r e a m h t t p . S e r v e r R e s p o n s e Implement u t i l . i n h e r i t s ( m y S t r e a m , s t r e a m . W r i t a b l e ) ; m y S t r e a m . p r o t o t y p e . w r i t e = f u n c t i o n ( ) . . .
  5. Duplex Both worlds! Example n e t . S o

    c k e t Implement u t i l . i n h e r i t s ( m y S t r e a m , s t r e a m . D u p l e x ) ; m y S t r e a m . p r o t o t y p e . r e a d = f u n c t i o n ( ) . . . m y S t r e a m . p r o t o t y p e . w r i t e = f u n c t i o n ( ) . . .
  6. Old streams Readable o n ( ' d a t

    a ' ) o n ( ' e n d ' ) r e a d ( ) p a u s e ( ) r e s u m e ( ) u n s h i f t ( )
  7. Old streams Writable o n ( ' d r a

    i n ' ) o n ( ' f i n i s h ' ) w r i t e ( ) e n d ( )
  8. Problems data comes immediately p a u s e (

    ) doesn't pause handoff is difficult
  9. Streams2 Implemented in v 0 . 1 0 new event:

    'readable' p a u s e ( ) , r e s u m e ( ) , o n ( ' d a t a ' ) or o n ( ' e n d ' ) revert to old functionality Allows for arbitrary Objects as well as Buffers and Strings
  10. And now for pipes MP3 Player s p e a

    k e r - takes in a stream of PCM audio data and plays it through the speakers. l a m e - Encodes/decodes MP3's to/from raw PCM formats.
  11. contact [email protected] thanks @ s u b s t a

    c k @ d o m i n i c t a r r @ t o o t a l l n a t e MarkdownPresenter slides & notes speakerdeck.com/rabidaudio/node-streams github.com/rabidaudio/stream-talk