read-all-stdin-sync
Save one level of indentation in scripts that won't do anything anyway until they've read all of stdin.
Caveats
- Only works if data can be read from stdin right away,
e.g. reading from a ready file handle.
- If stdin isn't ready, expect
Error: EAGAIN: resource temporarily unavailable, read
- We can't just wait and retry in sync mode because Node probably won't do I/O if we sleep.
- If stdin isn't ready, expect
var data = ;consoledirObject;
If you want to get rid of a possible leading Byte-Order Mark:
var data = stripBOM: true ;consoledirObject;
Actually, there's a shorthand for BOM stripping and parsing JSON:
var data = JSON;consoledirObject;
You can read buffers, too:
var data = encoding: null ;consoledirdata;
Easier to remember:
var data = Buffer;consoledirdata;
License
ISC