以前扯淡过 Readable Stream 了。segmentfault
此次来扯淡一下 Transform Stream。ui
Transform Stream 既是 Readable 又是 Writable。this
来看一个栗子:spa
var Transform = require('stream').Transform , inherits = require('util').inherits module.exports = BoringStream inherits(BoringStream, Transform) function BoringStream (options) { if (!(this instanceof BoringStream)) { return new BoringStream(options) } Transform.call(this, options) } BoringStream.prototype._transform = function (chunk, encoding, done) { this.push(chun done() }
妈蛋继续崩坏,不写了。prototype