diff options
author | Mihai Bazon <mihai.bazon@gmail.com> | 2013-03-05 22:17:09 -0800 |
---|---|---|
committer | Mihai Bazon <mihai.bazon@gmail.com> | 2013-03-05 22:17:09 -0800 |
commit | 3bd7ca9961125b39dcd54d2182cb72bd1ca6006e (patch) | |
tree | 4b2789bd152a5c9cd8438b29df662eb3197a504a | |
parent | aebafad41eab48f43ed649ce8c77e8f1528b50da (diff) | |
parent | f83aca65b75a93dd030b80c7b6c3f76456c32a81 (diff) | |
download | tracifyjs-3bd7ca9961125b39dcd54d2182cb72bd1ca6006e.tar.gz tracifyjs-3bd7ca9961125b39dcd54d2182cb72bd1ca6006e.zip |
Merge pull request #146 from mbostock/read-all-stdin
Read the entire STDIN.
-rwxr-xr-x | bin/uglifyjs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/bin/uglifyjs b/bin/uglifyjs index 9d2eedcb..88fd46bd 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -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); |