A Deep Dive into Streams2 in Node.js

Table of Contents

Streams2

Presenter

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

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:

Author: Jason Walsh

j@wal.sh

Last Updated: 2025-07-30 13:45:27

build: 2025-12-23 09:11 | sha: a10ddd7