折騰了一下 Node.js 的 stream.Transform

以前扯淡過 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

請輸入圖片描述

相關文章
相關標籤/搜索