photoprism/internal/util/hash.go
2019-05-06 23:18:10 +02:00

29 lines
383 B
Go

package util
import (
"crypto/sha1"
"encoding/hex"
"io"
"os"
)
// Returns sha1 hash of file as string
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))
}