Some checks failed
CloudSave/pipeline/head There was a failure building this commit
25 lines
361 B
Go
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
|
|
}
|