Created
August 23, 2012 12:03
-
-
Save nyuichi/3436029 to your computer and use it in GitHub Desktop.
nodejs.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
O-02551-MAC:example nishiwaki.yuichi$ jsx --run cat.jsx | |
fs.js:381 | |
var r = binding.read(fd, buffer, offset, length, position); | |
^ | |
Error: EAGAIN, no more processes | |
at Object.fs.readSync (fs.js:381:19) | |
at Function._Main.main$AS (/private/var/folders/9c/fvg4rhxn5c57ptdjzv3t69c95jvdwl/T/cat.jsx.73524.13953608600.js:119:18) | |
at Object.JSX.runMain (/private/var/folders/9c/fvg4rhxn5c57ptdjzv3t69c95jvdwl/T/cat.jsx.73524.13953608600.js:178:15) | |
at /private/var/folders/9c/fvg4rhxn5c57ptdjzv3t69c95jvdwl/T/cat.jsx.73524.13953608600.js:214:5 | |
at Object.<anonymous> (/private/var/folders/9c/fvg4rhxn5c57ptdjzv3t69c95jvdwl/T/cat.jsx.73524.13953608600.js:215:3) | |
at Module._compile (module.js:449:26) | |
at Object.Module._extensions..js (module.js:467:10) | |
at Module.load (module.js:356:32) | |
at Function.Module._load (module.js:312:12) | |
at Module.require (module.js:362:17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "js.jsx"; | |
import "../lib/js/nodejs.jsx"; | |
native class Buffer { | |
function constructor(size : int); | |
} | |
native __fake__ class FS { | |
function write(fd : variant, buffer : Buffer, offset : int, length : int, position : Nullable.<int>) : void; | |
function writeSync(fd : variant, buffer : Buffer, offset : int, length : int) : int; | |
function writeSync(fd : variant, buffer : Buffer, offset : int, length : int, position : int) : int; | |
function writeSync(fd : variant, str : string, position : int) : int; | |
function read(fd : variant, buffer : Buffer, offset : int, length : int, position : Nullable.<int>) : void; | |
function readSync(fd : variant, buffer : Buffer, offset : int, length : int) : int; | |
function readSync(fd : variant, buffer : Buffer, offset : int, length : int, position : int) : int; | |
function readFileSync(filename : string, encoding : string) : string; | |
} | |
class _Main { | |
static function main(args : string[]) : void { | |
var eval = js.global["eval"] as (string) -> variant; | |
var fs = eval('require("fs")') as __noconvert__ FS; | |
var buf = new Buffer(512); | |
if (args.length == 0 || (args.length == 1 && args[0] == '-')) { | |
var n; | |
while ((n = fs.readSync(process.stdin['fd'], buf, 0, 512)) > 0) { | |
// fs.writeSync(process.stdout['fd'], buf, 0, 512); | |
} | |
// var on = process.stdin['on'] as (string, (string) -> void) -> void; | |
// on('data', function(chunk) { | |
// log chunk; | |
// }); | |
} else { | |
for (var i in args) { | |
log fs.readFileSync(args[i], 'utf8'); | |
// fs.writeSync(process.stdout['fd'], fs.readFileSync(args[i], 'utf8'), 0); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment