之前扯淡过 Readable Stream 了。

这次来扯淡一下 Transform Stream。

Transform Stream 既是 Readable 又是 Writable。

来看一个栗子:

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()
}

妈蛋继续崩坏,不写了。

请输入图片描述


XiNGRZ
1.1k 声望47 粉丝