Last active
March 23, 2017 05:30
-
-
Save kingcc/76a2827db70f6820b853033092ba693e to your computer and use it in GitHub Desktop.
nodeJS read muti-lines datas from console.
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
/** | |
* nodeJS read muti-lines datas from console. | |
* @Author kingcc | |
* @DateTime 2017-03-23T13:29:22+0800 | |
* @param {Function} cb callback | |
* @return {[type]} callback results | |
*/ | |
function readMutiLines(cb) { | |
let datas = []; | |
process.stdin.setEncoding('utf8'); | |
process.stdin.pause(); | |
process.stdin.on('readable', function(chunk) { | |
if (chunk = process.stdin.read()) | |
datas.push(chunk.slice(0, -1)); | |
}); | |
process.stdin.on('end', function() { | |
return cb(datas); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment