music-library/utils.go

26 lines
418 B
Go
Raw Normal View History

2025-01-15 12:48:20 +01:00
package main
import (
"crypto/sha512"
"io"
"os"
)
func HashFile(path string) ([sha512.Size]byte, error) {
file, err := os.Open(path)
if err != nil {
return [sha512.Size]byte{}, err
}
defer file.Close()
hasher := sha512.New()
if _, err := io.Copy(hasher, file); err != nil {
return [sha512.Size]byte{}, err
}
res := [sha512.Size]byte{}
hash := hasher.Sum(nil)
copy(res[:], hash)
return res, nil
}