Skip to content

Commit

Permalink
Merge pull request #146 from mbostock/read-all-stdin
Browse files Browse the repository at this point in the history
Read the entire STDIN.
  • Loading branch information
mishoo committed Mar 6, 2013
2 parents aebafad + f83aca6 commit 3bd7ca9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions bin/uglifyjs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,15 @@ function getOptions(x, constants) {
}

function read_whole_file(filename) {
if (filename == "-") {
// XXX: this sucks. How does one read the whole STDIN
// synchronously?
filename = "/dev/stdin";
}
try {
if (filename == "-") {
var chunks = [];
do {
var chunk = fs.readFileSync("/dev/stdin", "utf8");
chunks.push(chunk);
} while (chunk.length);
return chunks.join("");
}
return fs.readFileSync(filename, "utf8");
} catch(ex) {
sys.error("ERROR: can't read file: " + filename);
Expand Down

0 comments on commit 3bd7ca9

Please sign in to comment.