GetByName gets the hashcode of a binary given its filename
(name string)
| 76 | |
| 77 | // GetByName gets the hashcode of a binary given its filename |
| 78 | func GetByName(name string) (string, error) { |
| 79 | binaryFileStream, err := StreamByName(name) |
| 80 | if err != nil { |
| 81 | return "", err |
| 82 | } |
| 83 | defer func() { |
| 84 | err = binaryFileStream.Close() |
| 85 | }() |
| 86 | |
| 87 | encoder := sha256.New() |
| 88 | _, err = io.Copy(encoder, binaryFileStream) |
| 89 | if err != nil { |
| 90 | return "", err |
| 91 | } |
| 92 | |
| 93 | return fmt.Sprintf("%x", encoder.Sum(nil)), err |
| 94 | } |
no test coverage detected