photoprism/internal/file/hash.go
Michael Mayer e43983d579 Backend: Refactor thumbnail package #157
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-01-06 14:32:15 +01:00

30 lines
383 B
Go

package file
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))
}