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 關注
- 1239 瀏覽
添加回答
舉報
0/150
提交
取消