hashFile streams a file through sha256.
(path string)
| 101 | |
| 102 | // hashFile streams a file through sha256. |
| 103 | func hashFile(path string) (string, error) { |
| 104 | f, err := os.Open(path) |
| 105 | if err != nil { |
| 106 | return "", err |
| 107 | } |
| 108 | defer f.Close() |
| 109 | h := sha256.New() |
| 110 | if _, err := io.Copy(h, f); err != nil { |
| 111 | return "", err |
| 112 | } |
| 113 | return hex.EncodeToString(h.Sum(nil)), nil |
| 114 | } |
| 115 | |
| 116 | // Apply downloads the current platform's binary, verifies its sha256 against the |
| 117 | // published codehamr_checksums.txt, and atomically replaces execPath. The caller |