MCPcopy Index your code
hub / github.com/jetify-com/devbox / JSONFile

Function JSONFile

internal/cachehash/hash.go:62–75  ·  view source on GitHub ↗

JSONFile compacts the JSON in a file and returns its hex-encoded hash.

(path string)

Source from the content-addressed store, hash-verified

60
61// JSONFile compacts the JSON in a file and returns its hex-encoded hash.
62func JSONFile(path string) (string, error) {
63 b, err := os.ReadFile(path)
64 if errors.Is(err, os.ErrNotExist) {
65 return "", nil
66 }
67 if err != nil {
68 return "", err
69 }
70 buf := &bytes.Buffer{}
71 if err := json.Compact(buf, b); err != nil {
72 return "", redact.Errorf("compact json for hashing: %v", err)
73 }
74 return Bytes(buf.Bytes()), nil
75}
76
77func newHash() hash.Hash { return sha256.New() }

Callers 5

manifestHashFunction · 0.92
printDevEnvCacheHashFunction · 0.92
getLockfileHashFunction · 0.92
TestJSONFileFunction · 0.85
TestJSONFileNotExistFunction · 0.85

Calls 4

ErrorfFunction · 0.92
BytesFunction · 0.85
IsMethod · 0.80
BytesMethod · 0.80

Tested by 2

TestJSONFileFunction · 0.68
TestJSONFileNotExistFunction · 0.68