readFileSync is working

This commit is contained in:
Ryan Dahl 2018-05-14 02:50:55 -04:00
parent 1a80bcb250
commit aba6a1dc87
8 changed files with 70 additions and 5 deletions

31
main.go
View file

@ -3,12 +3,37 @@ package main
import (
"github.com/golang/protobuf/proto"
"github.com/ry/v8worker2"
"io/ioutil"
"os"
)
func recv(msg []byte) []byte {
println("recv cb", string(msg))
return nil
func ReadFileSync(filename string) []byte {
buf, err := ioutil.ReadFile(filename)
msg := &Msg{Kind: Msg_DATA_RESPONSE}
if err != nil {
msg.Error = err.Error()
} else {
msg.Data = buf
}
out, err := proto.Marshal(msg)
if err != nil {
panic(err)
}
return out
}
func recv(buf []byte) []byte {
msg := &Msg{}
err := proto.Unmarshal(buf, msg)
if err != nil {
panic(err)
}
switch msg.Kind {
case Msg_READ_FILE_SYNC:
return ReadFileSync(msg.Path)
default:
panic("Unexpected message")
}
}
func loadAsset(w *v8worker2.Worker, path string) {