最后一個輸出流的問題
我的代碼是這樣的,為什么執行出來只輸出一個第一次push進去的內容啊
var stream = require('stream');
var util = require('util');
function ReadStream () {
?? ?stream.Readable.call(this);
}
util.inherits(ReadStream, stream.Readable);
ReadStream.prototype._read = function () {
?? ?this.push(' I');
?? ?this.push(' love');
?? ?this.push(' imooc,');
?? ?this.push(null);
};
function WriteStream () {
?? ?stream.Writable.call(this);
?? ?this._cached = new Buffer.from('');
}
util.inherits(WriteStream, stream.Writable);
WriteStream.prototype._write = function (chunk) {
?? ?console.log(chunk.toString());
};
function TransformStream () {
?? ?stream.Transform.call(this);
}
util.inherits(TransformStream, stream.Transform);
TransformStream.prototype._transform = function(chunk){
?? ?this.push(chunk);
};
TransformStream.prototype._flush = function(cb){
?? ?this.push('12345');
?? ?cb && cb();
};
var rs = new ReadStream();
var ws = new WriteStream();
var ts = new TransformStream();
rs.pipe(ts).pipe(ws);