Files
cloudsave/pkg/tools/hash/hash.go
Aurélie DELHAIE af11e843a4
Some checks failed
CloudSave/pipeline/head There was a failure building this commit
fixing sec issues
2025-09-07 01:14:19 +02:00

25 lines
361 B
Go

package hash
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
)
func FileMD5(fp string) (string, error) {
f, err := os.OpenFile(fp, os.O_RDONLY, 0)
if err != nil {
return "", err
}
defer f.Close()
hasher := md5.New()
if _, err := io.Copy(hasher, f); err != nil {
return "", err
}
sum := hasher.Sum(nil)
return hex.EncodeToString(sum), nil
}