diff options
author | Mike Bostock <mbostock@gmail.com> | 2013-03-05 20:35:49 -0800 |
---|---|---|
committer | Mike Bostock <mbostock@gmail.com> | 2013-03-05 20:35:49 -0800 |
commit | f83aca65b75a93dd030b80c7b6c3f76456c32a81 (patch) | |
tree | 4b2789bd152a5c9cd8438b29df662eb3197a504a /bin | |
parent | aebafad41eab48f43ed649ce8c77e8f1528b50da (diff) | |
download | tracifyjs-f83aca65b75a93dd030b80c7b6c3f76456c32a81.tar.gz tracifyjs-f83aca65b75a93dd030b80c7b6c3f76456c32a81.zip |
Read the entire STDIN.
The problem with reading synchronously from /dev/stdin is that you can get a
spurious EOF when the input buffer is empty, even if more content is coming. Now
STDIN is read from a loop, and only stops polling when all input has been read.
This fixes #70 #85 and other errors related to parsing large files on STDIN.
Diffstat (limited to 'bin')
-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); |