为了账号安全,请及时绑定邮箱和手机立即绑定

最后一个输出流的问题

我的代码是这样的,为什么执行出来只输出一个第一次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);



正在回答

举报

0/150
提交
取消
进击Node.js基础(二)
  • 参与学习       76795    人
  • 解答问题       226    个

本教程带你攻破 Nodejs,让 JavaScript流畅运行在服务器端

进入课程

最后一个输出流的问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信