MCPcopy Create free account
hub / github.com/blues/note / WriteJSON

Method WriteJSON

lib/fileio.go:61–81  ·  view source on GitHub ↗
(ctx context.Context, path string, data []byte)

Source from the content-addressed store, hash-verified

59}
60
61func (fio *filesystem) WriteJSON(ctx context.Context, path string, data []byte) (err error) {
62 _ = os.MkdirAll(filepath.Dir(path), 0777)
63 fd, err2 := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o666)
64 if err2 != nil {
65 err = err2
66 logError(ctx, "fileioWrite: error creating %s: %s", path, err)
67 return
68 }
69
70 // Write it
71 _, err = fd.Write(data)
72 if err != nil {
73 logError(ctx, "fileioWrite: error writing %s: %s", path, err)
74 fd.Close()
75 return
76 }
77
78 // Done
79 fd.Close()
80 return
81}

Callers 1

CreateMethod · 0.95

Calls 2

logErrorFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected