Last active
March 5, 2016 14:01
-
-
Save alizbazar/7501012c0a3f8f6726f1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
var getPipedInput = function() { | |
return new Promise(function(resolve, reject) { | |
var data = ""; | |
var self = process.stdin; | |
var reading = false; | |
self.on('readable', function() { | |
var chunk = this.read(); | |
if (!reading) { | |
if (chunk == null) { | |
return resolve(); | |
} else { | |
reading = true; | |
} | |
} | |
if (chunk) { | |
reading = true; | |
data += chunk; | |
} | |
}); | |
self.on('end', function() { | |
resolve(data); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment