Files
cloudsave/pkg/tools/hash/hash.go
Aurélie DELHAIE 46f312078d
Some checks failed
CloudSave/pipeline/head Something is wrong with the build of this commit
fix sec
2025-09-07 01:31:14 +02:00

25 lines
392 B
Go

package hash
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
"path/filepath"
)
func FileMD5(fp string) (string, error) {
f, err := os.OpenFile(filepath.Clean(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
}