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

Function File

internal/cachehash/hash.go:35–50  ·  view source on GitHub ↗

File returns a hex-encoded hash of a file's contents.

(path string)

Source from the content-addressed store, hash-verified

33
34// File returns a hex-encoded hash of a file's contents.
35func File(path string) (string, error) {
36 f, err := os.Open(path)
37 if errors.Is(err, os.ErrNotExist) {
38 return "", nil
39 }
40 if err != nil {
41 return "", err
42 }
43 defer f.Close()
44
45 h := newHash()
46 if _, err := io.Copy(h, f); err != nil {
47 return "", err
48 }
49 return hex.EncodeToString(h.Sum(nil)), nil
50}
51
52// JSON marshals a to JSON and returns its hex-encoded hash.
53func JSON(a any) (string, error) {

Callers 3

HashMethod · 0.92
TestFileFunction · 0.70
TestFileNotExistFunction · 0.70

Calls 2

newHashFunction · 0.85
IsMethod · 0.80

Tested by 2

TestFileFunction · 0.56
TestFileNotExistFunction · 0.56