Skip to content

Commit

Permalink
Read data asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Jun 6, 2016
1 parent e89bea4 commit 545a9fc
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ module.exports = function () {

stdin.setEncoding('utf8');

stdin.on('readable', function () {
var chunk;

while ((chunk = stdin.read())) {
ret += chunk;
}
stdin.on('data', function (chunk) {
ret += chunk;
});

stdin.on('end', function () {
Expand All @@ -36,13 +32,9 @@ module.exports.buffer = function () {
return;
}

stdin.on('readable', function () {
var chunk;

while ((chunk = stdin.read())) {
ret.push(chunk);
len += chunk.length;
}
stdin.on('data', function (chunk) {
ret.push(chunk);
len += chunk.length;
});

stdin.on('end', function () {
Expand Down

0 comments on commit 545a9fc

Please sign in to comment.