MD5ChecksumForFile computes just the MD5 hash and not all the others
(path string)
| 13 | |
| 14 | // MD5ChecksumForFile computes just the MD5 hash and not all the others |
| 15 | func MD5ChecksumForFile(path string) (string, error) { |
| 16 | file, err := os.Open(path) |
| 17 | if err != nil { |
| 18 | return "", err |
| 19 | } |
| 20 | defer func() { |
| 21 | _ = file.Close() |
| 22 | }() |
| 23 | |
| 24 | hash := md5.New() |
| 25 | _, err = io.Copy(hash, file) |
| 26 | if err != nil { |
| 27 | return "", err |
| 28 | } |
| 29 | |
| 30 | return fmt.Sprintf("%x", hash.Sum(nil)), nil |
| 31 | } |
| 32 | |
| 33 | // ChecksumInfo represents checksums for a single file |
| 34 | type ChecksumInfo struct { |