badger/internal/tools/hash.go
2023-03-14 09:53:33 +01:00

23 lines
369 B
Go

package tools
import (
"io"
"os"
"github.com/cespare/xxhash"
)
// exported functions
func XxHash(file string) (uint64, error) {
filehandle, error := os.Open(file)
if error != nil {
return 0, error
}
defer filehandle.Close()
hash := xxhash.New()
_, error = io.Copy(hash, filehandle)
if error != nil {
return 0, error
}
return xxhash.Sum64(nil), nil
}