photoprism/pkg/fs/hash.go
Michael Mayer f8a45b14d9 Backend: Move reusable packages to pkg/
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-01-12 14:00:56 +01:00

29 lines
391 B
Go

package fs
import (
"crypto/sha1"
"encoding/hex"
"io"
"os"
)
// Hash returns the 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))
}