File creates the hash value of a file
(path string)
| 26 | |
| 27 | // File creates the hash value of a file |
| 28 | func File(path string) (string, error) { |
| 29 | file, err := os.Open(path) |
| 30 | if err != nil { |
| 31 | return "", err |
| 32 | } |
| 33 | defer file.Close() |
| 34 | |
| 35 | hash := sha256.New() |
| 36 | _, err = io.Copy(hash, file) |
| 37 | if err != nil { |
| 38 | return "", err |
| 39 | } |
| 40 | |
| 41 | return hex.EncodeToString(hash.Sum(nil)), nil |
| 42 | } |
| 43 | |
| 44 | // Directory creates the hash value of a directory |
| 45 | func Directory(path string) (string, error) { |
no test coverage detected