Working with Streams

“Streams are Node's best and most misunderstood idea”
Dominic Tarr

Streams

Readable Streams
HTTP responses, on the client
HTTP requests, on the server
fs read streams
zlib streams
crypto streams
TCP sockets
child process stdout and stderr
process.stdin

Writable Streams
HTTP requests, on the client
HTTP responses, on the server
fs write streams
zlib streams
crypto streams
TCP sockets
child process stdin
process.stdout,process.stderr

What are streams?

Streams

Collections of data that might not be available all at once and don't have to fit in memory.

Types of Streams

All streams are

EventEmitters

src.pipe(dst);

Piping

netstat -tulpn | grep 80

Streams

Readable Streams

Events
- data
- end
- error
- close
- readable
Functions
- pipe(), unpipe()
- read(), unshift(), resume()
- pause(), isPaused()
- setEncoding()

Writable Streams

Events
- drain
- finish
- error
- close
- pipe/unpipe
Functions
- write()
- end()
- cork(), uncork()
- setDefaultEncoding()

Readable Streams

Working with Streams

By Shuhratbek Mamadaliyev

Working with Streams

  • 869