Created
November 30, 2022 14:28
-
-
Save mping-exo/ab6a65b54e0629907af85189987a6863 to your computer and use it in GitHub Desktop.
xxhash golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"os" | |
"reflect" | |
"github.com/cespare/xxhash/v2" | |
) | |
func xxh64Sum(filePath string) (uint64, error) { | |
file, err := os.Open(filePath) | |
if err != nil { | |
return 0, err | |
} | |
defer file.Close() | |
h := xxhash.New() | |
if _, err = io.Copy(h, file); err != nil { | |
return 0, err | |
} | |
return h.Sum64(), nil | |
} | |
func main() { | |
path := os.Args[1] | |
hash, err := xxh64Sum(path) | |
if err != nil { | |
fmt.Println(err) | |
} else { | |
fmt.Printf("file: %s, type: %s, hash: %d", path, reflect.TypeOf(hash), hash) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment