badger/internal/tools/hash.go

24 lines
369 B
Go
Raw Permalink Normal View History

2023-03-14 09:53:33 +01:00
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
}