photoprism/internal/fsutil/hash.go
2018-11-17 06:21:39 +01:00

28 lines
345 B
Go

package fsutil
import (
"crypto/sha1"
"encoding/hex"
"io"
"os"
)
func Hash(filename string) string {
var result []byte
file, err := os.Open(filename)
if err != nil {
return ""
}
defer file.Close()
hash := sha1.New()
if _, err := io.Copy(hash, file); err != nil {
return ""
}
return hex.EncodeToString(hash.Sum(result))
}