24 lines
369 B
Go
24 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
|
||
|
}
|