diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-14 02:50:55 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-14 02:50:55 -0400 |
commit | aba6a1dc871edbc6cbb286a350a4ba79ca645fb8 (patch) | |
tree | ecd6347c2374a36a6524782f985975c7c315068b /main.ts | |
parent | 1a80bcb250c81a8959b8af816f499c22bca0db51 (diff) |
readFileSync is working
Diffstat (limited to 'main.ts')
-rw-r--r-- | main.ts | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1,10 +1,29 @@ //import * as ts from "typescript"; import { main as pb } from "./msg.pb" import "./util"; +import { TextDecoder } from "text-encoding"; +function readFileSync(filename: string): string { + const msg = pb.Msg.fromObject({ + kind: pb.Msg.MsgKind.READ_FILE_SYNC, + path: filename + }); + const ui8 = pb.Msg.encode(msg).finish(); + const ab = ui8.buffer.slice(ui8.byteOffset, ui8.byteOffset + ui8.byteLength); + const resBuf = V8Worker2.send(ab as ArrayBuffer); + const res = pb.Msg.decode(new Uint8Array(resBuf)); + if (res.error != null && res.error.length > 0) { + throw Error(res.error); + } + const decoder = new TextDecoder("utf8"); + return decoder.decode(res.data) +} function load(argv: string[]): void { console.log("Load argv", argv); + const inputFn = argv[1]; + const source = readFileSync(inputFn); + console.log("source", source) } V8Worker2.recv((ab: ArrayBuffer) => { |