nodejs logo


Solving I/O Bound Problems

Created by Evan Oxfeld / @evanoxfeld


  • Explore I/O bound problems in Node
  • Explore Streams API

Streams Example - Unzip



Behind the curtain

## util.pump(readable, writable) * Sets up event handlers for 'data', 'end' * Ignores other events e.g. 'error', 'close' * API limits customization, not chainable

Streams in 0.8

## Streams in 0.8 * Readable * Emit data events * Optionally implement pause() and resume() * Writable * Implement write() and end()
## Awesome! Let's demo!

Issues - Backpressure

Readable Writable

Issues - Backpressure

Readable Writable

Issues - Backpressure

Readable Writable

Issues - Backpressure


More Issues

  • Buffering and backpressure
  • No on.('pipe') method
  • pause() isn't a guarantee

Streams of Tomorrow, Finally Here

Streams in 0.10

  • Readable streams are now suck streams
  • read([size]) is equivalent to write(data)
    • read() returns null if less data is buffered than size
    • write() return false or pass a callback
  • Object mode
  • Same composable pipe API
  • Shared base classes for backpressure and buffering

Streams 0.10 Base Classes

  • Readable, Writable, Duplex
  • Transform: implement _transform(chunk, encoding, cb)
  • PassThrough: no method to implement
# Example stream.Transform Code!

Unzip Demo


  • Stream API is great for solving I/O bound problems
  • Streams2 developed in the open with a parallel user-land module
Streams make programming in node simple, elegant, and composable.