Skip to content

Instantly share code, notes, and snippets.

@dperini
Created May 21, 2011 10:39
Show Gist options
  • Save dperini/984426 to your computer and use it in GitHub Desktop.
Save dperini/984426 to your computer and use it in GitHub Desktop.
/*
*
* readfile.js - Spidermonkey/V8 readfile wrapper
*
* Author: Diego Perini <[email protected]>
*
* Released under the Creative Commons license:
* http://creativecommons.org/licenses/by/3.0/
*
*/
// read file from "stdin" using SM or V8 style
var _readFile = typeof this.read == 'function' ?
function() {
return read('/dev/stdin');
} : typeof this.readline == 'function' ?
function() {
var outstr = '', line = '';
while ((line = readline()) != null) {
outstr += line + '\x0a';
}
return outstr;
} :
function() {
return '';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment