Debian Codegraph @

xxhsum/main.go

raw
1 // Command line interface to the xxHash32 and xxHash64 packages.
2 // Usage:
3 // xxHash [-mode 0] [-seed 123] filename1 [filename2...]
4 // where
5 // mode: hash mode (0=32bits, 1=64bits) (default=1)
6 // seed: seed to be used (default=0)
7 package main
8
9 import (
10 "flag"
11 "fmt"
12 "hash"
13 "io"
14 "os"
15
16 "github.com/pierrec/xxHash/xxHash32"
17 "github.com/pierrec/xxHash/xxHash64"
18 )
19
20 func main() {
21 seed := flag.Uint64("seed", 0, "seed value")
22 mode := flag.Int("mode", 1, "hash mode: 0=32bits, 1=64bits")
23 flag.Parse()
24
25 var xxh hash.Hash
26 if *mode == 0 {
27 xxh = xxHash32.New(uint32(*seed))
28 } else {
29 xxh = xxHash64.New(*seed)
30 }
31
32 // Process each file in sequence
33 for _, filename := range flag.Args() {
34 inputFile, err := os.Open(filename)
35 if err != nil {
36 continue
37 }
38 if _, err := io.Copy(xxh, inputFile); err == nil {
39 fmt.Printf("%x %s\n", xxh.Sum(nil), filename)
40 }
41 inputFile.Close()
42 xxh.Reset()
43 }
44 }