stram pipe管道 代码运行错误

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); //通过管道实现数据的读转换和写

我这个代码不晓得哪里写错了,运行结果总是不对,是这样的,希望大神指教

http://img.mukewang.com/58bd0fee0001ad0604070432.jpg

木子水吉_1025
浏览 1218回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Node.js