亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我的代碼輸出總是第一行不顯示?


var Readable = require('stream').Readable;

var Writable = require('stream').Writable;


// 實例化

var readStream = new Readable();

var writStream = new Writable();


readStream.push('Hello ');

readStream.push('I ');

readStream.push('Love ');

readStream.push("Scott's ");

readStream.push('lessons\n');

readStream.push(null); // 代表push結束



writStream._write = function(chunk, encode, cb)

{

console.log(chunk.toString());

cb();

}


readStream.pipe(writStream);

http://img1.sycdn.imooc.com//57ed339a0001144b05160132.jpg

正在回答

2 回答

var?stream?=?require('stream');
var?util?=?require('util');		//tools

function?ReadStream(){
	//?改變上下文
	stream.Readable.call(this);
}

util.inherits(ReadStream,?stream.Readable);

ReadStream.prototype._read?=?function()?{
	this.push('Hello?');
	this.push('I?');
	this.push('Love?');
	this.push("Scott's?");
	this.push('lessons\n');
	this.push(null);	//	代表push結束
};

function?WritStream(){
	stream.Writable.call(this);
}

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('Oh?Fuck!');
	cb();
}

var?rs?=?new?ReadStream();
var?ws?=?new?WritStream();
var?ts?=?new?TransformStream();

rs.pipe(ts).pipe(ws);

這個也是第一行不顯示

0 回復 有任何疑惑可以回復我~
#1

緋色昌

我的可以顯示,復制你的代碼的
2016-10-10 回復 有任何疑惑可以回復我~
//代碼如下
var?Readable?=?require('stream').Readable;
var?Writable?=?require('stream').Writable;

//?實例化
var?readStream?=?new?Readable();
var?writStream?=?new?Writable();

readStream.push('Hello?');
readStream.push('I?');
readStream.push('Love?');
readStream.push("Scott's?");
readStream.push('lessons\n');
readStream.push(null);	//	代表push結束


writStream._write?=?function(chunk,?encode,?cb)
{
	console.log(chunk.toString());
	cb();
}

readStream.pipe(writStream);


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
進擊Node.js基礎(二)
  • 參與學習       76735    人
  • 解答問題       242    個

本教程帶你攻破 Nodejs,讓 JavaScript流暢運行在服務器端

進入課程

為什么我的代碼輸出總是第一行不顯示?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號