MCPcopy
hub / github.com/dosco/graphjin / Put

Method Put

wasm/fs.go:34–61  ·  view source on GitHub ↗
(path string, data []byte)

Source from the content-addressed store, hash-verified

32}
33
34func (f *JSFS) Put(path string, data []byte) (err error) {
35 defer func() {
36 if err1 := recover(); err1 != nil {
37 err = toError(err1)
38 }
39 }()
40 path = filepath.Join(f.bp, path)
41
42 dir := filepath.Dir(path)
43 ok, err := f.exists(dir)
44 if !ok {
45 err = f.createDir(dir)
46 }
47 if err != nil {
48 return
49 }
50
51 a := js.Global().Get("Uint8Array").New(len(data))
52 js.CopyBytesToJS(a, data)
53 runtime.KeepAlive(data)
54 jsData := js.Global().Get("Int8Array").New(
55 a.Get("buffer"),
56 a.Get("byteOffset"),
57 a.Get("byteLength"))
58
59 f.fs.Call("writeFileSync", path, jsData)
60 return nil
61}
62
63func (f *JSFS) Exists(path string) (ok bool, err error) {
64 path = filepath.Join(f.bp, path)

Callers

nothing calls this directly

Calls 5

existsMethod · 0.95
createDirMethod · 0.95
toErrorFunction · 0.85
GetMethod · 0.65
CallMethod · 0.65

Tested by

no test coverage detected