mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
readFileSync is working
This commit is contained in:
parent
1a80bcb250
commit
aba6a1dc87
8 changed files with 70 additions and 5 deletions
31
main.go
31
main.go
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue