A Deep Dive into Streams2 in Node.js

Table of Contents

1. Streams2

1.2. Origin

Originally part of npm:readable-stream

1.3. Classes

1.3.1. readable

  • implement _size
Sourse.prototype._read = functon(size) {};

Options are highWaterMark, encoding, and objectMode

1.3.2. writable

var s = new Source(); 
var d = new Drain();

See concat-stream: https://github.com/maxogden/node-concat-stream

1.3.3. passthrough

1.3.4. duplex

inherits(Server, Duplex);
Server.prototype._read = function(size) {};
Server.prototype._write = function(out) {};

1.3.5. transform

inherits(Server, Duplex);
Server.prototype._transform = function(chunkk, encoding, cb) {};
Server.prototype._flush = function(cb) {};

1.3.6. passthrough

Testing abstractions only. Given the volume of boilerplate use: https://github.com/brycebaril/through2-spy

1.6. Examples

1.6.1. http + other streams

chunks can break between requests (e.g. req.on('data', function)

2. Notes

Much of the conversation for Streams comes from @isaacs: