Browse Source

Initial commit

master
Greg 3 years ago
commit
341054857e
  1. 1
      .gitignore
  2. 5
      go.mod
  3. 6
      go.sum
  4. 46
      main.go

1
.gitignore vendored

@ -0,0 +1 @@
b3sum

5
go.mod

@ -0,0 +1,5 @@
module git.wow.st/gmp/b3sum
go 1.13
require github.com/zeebo/blake3 v0.0.1

6
go.sum

@ -0,0 +1,6 @@
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/blake3 v0.0.1 h1:nZUbpoC0IddEMH+XSzRlqmLLpxg+knEXBx3b2u0kzWY=
github.com/zeebo/blake3 v0.0.1/go.mod h1:+l01N1So4KnXR2QTSMaSH2H6dHCb16oZOLgyfN5AgDc=
github.com/zeebo/wyhash v0.0.0-20191228005337-11a718112e35/go.mod h1:Ti+OwfNtM5AZiYAL0kOPIfliqDP5c0VtOnnMAqzuuZk=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

46
main.go

@ -0,0 +1,46 @@
package main
import (
"encoding/hex"
"flag"
"fmt"
"io"
"os"
"github.com/zeebo/blake3"
)
var (
help = flag.Bool("h", false, "Prints help information")
length = flag.Int("l", 32, "The number of output bytes, prior to hex encoding (default 32)")
)
func main() {
flag.Parse()
if *help || len(flag.Args()) == 0 {
flag.Usage()
os.Exit(0)
}
buf := [65536]byte{}
for _, name := range flag.Args() {
file, err := os.Open(name)
if err != nil {
panic(err)
}
hasher := blake3.NewSized(*length)
for {
n, err := file.Read(buf[:])
hasher.Write(buf[:n])
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
}
file.Close()
hash := hasher.Sum([]byte{})
fmt.Print(hex.EncodeToString(hash))
fmt.Print(" ")
fmt.Println(name)
}
}
Loading…
Cancel
Save