-
-
Save tacke758/4481500 to your computer and use it in GitHub Desktop.
Node.jsで標準入力から大きなデータの入力を受ける
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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