Jacob Swartwood



Pittsburgh Node.js Meetup 2013

http://jswartwood.github.io/node-streams




|


Unix Pipe




Usage

cat results.txt | grep "success" | wc -l

Count lines that match "success" from results.txt

Douglas McIlroy



Doug's Unix Philosophy

  • Write programs that do one thing well
  • Write programs that work together
  • Write programs that handle text streams,
    because that is a universal interface



We should have some ways of coupling programs like garden hose--screw in another segment when it becomes necessary to massage data in another way. This is the way of IO also.


- MD McIlroy 10/11/64




Node.js Streams



Streams 1

  • Chunky (event-based)
  • Clunky (boilerplate)
  • Clumsy (pause/resume)



Streams 2!!!

  • Direct (methods)
  • Easy (inheritence)
  • Stable (buffers)





Stream Classes


stream.Readable


Author:

._read(), .push()


Consumer:

.read()


stream.Writable


Author:

._write()


Consumer:

.write()


stream.Duplex


Author:

._read(), .push(), ._write()


Consumer:

.read(), .write()


stream.Transform


Author:

._transform(), .push()


Consumer:

.read(), .write()


stream.Passthrough


Author:

er... well... um


Consumer:

take a nap




...and of course


.pipe()




How?

linefeed

gitfiles

Why?

Do stuff to stuff while stuff

Command line fu

Latency!!!

Efficiency!!!

Huge files

Parser/processor

Stupid slow thing!

Stupid cluttered thing!

Demo!


Jacob Swartwood



t jswartwood


g jswartwood