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

stram pipe管道 代码运行错误

stram pipe管道 代码运行错误

木子水吉_1025 2017-03-06 15:30:46
var stream = require('stream');var util = require('util');//自定义可读类的方法function ReadStream() { stream.Readable.call(this);  }//调用util.inherits(ReadStream, stream.Readable);//让ReadStream继承流里面可读的原型stream.Readable//为ReadStream添加原型链上的read方法ReadStream.prototype._read = function() { this.push('lijie '); this.push('do not love'); this.push('you!');}function WritStream() { stream.Writable.call(this); this._cached = new Buffer('');}util.inherits(WritStream, stream.Writable);WritStream.prototype._write = function(chunk, encode, cb) { console.log(chunk.toString()); cb();}function TransformStream() { stream.Transform.call(this);}util.inherits(TransformStream, stream.Transform);TransformStream.prototype._transform = function(chunk, encode, cb) { this.push(chunk); cb();}TransformStream.prototype._flush = function(cb) { this.push('i have no chioce'); //为得到的数据增加定制的内容 cb();}var rs = new ReadStream();var ws = new WritStream();var ts = new TransformStream();rs.pipe(ts).pipe(ws); //通过管道实现数据的读转换和写我这个代码不晓得哪里写错了,运行结果总是不对,是这样的,希望大神指教
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1217 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信