Skip to content

Instantly share code, notes, and snippets.

@tacke758
Forked from mironal/ok_pipe.js
Last active December 10, 2015 19:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacke758/4481500 to your computer and use it in GitHub Desktop.
Save tacke758/4481500 to your computer and use it in GitHub Desktop.
Node.jsで標準入力から大きなデータの入力を受ける
process.stdin.resume();
process.stdin.setEncoding('utf8');
var fragment = "";
process.stdin.on('data', function(chunk){
if (chunk == "") { return ;}
var lines = chunk.split("\n");
lines[0] = fragment + lines[0];
fragment = lines.pop();
lines.forEach(function(line){
// なんか処理する
});
});
// ストリーム終了時に呼ばれる.
process.stdin.on('end', function(){
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment