A Deep Dive into Streams2 in Node.js
Table of Contents
Streams2
Presenter
Presenter maintains: https://npmjs.org/package/stream-spigot
Origin
Originally part of npm:readable-stream
Classes
readable
- implement _size
Sourse.prototype._read = functon(size) {};
Options are highWaterMark, encoding, and objectMode
writable
var s = new Source(); var d = new Drain();
See concat-stream: https://github.com/maxogden/node-concat-stream
passthrough
duplex
inherits(Server, Duplex); Server.prototype._read = function(size) {}; Server.prototype._write = function(out) {};
transform
inherits(Server, Duplex); Server.prototype._transform = function(chunkk, encoding, cb) {}; Server.prototype._flush = function(cb) {};
passthrough
Testing abstractions only. Given the volume of boilerplate use: https://github.com/brycebaril/through2-spy
Abstractions
Caveats
read(0) resets the stream
Stream.push(null) truncates streams
Streams are EventEmitters and you need to caputure all
Examples
http + other streams
chunks can break between requests (e.g. req.on('data', function)
Notes
Much of the conversation for Streams comes from @isaacs: