Initial commit

This commit is contained in:
Greg 2020-04-02 12:02:23 -04:00
commit 6942e2ac7f
4 changed files with 57 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
b3sum

5
go.mod Normal file
View File

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

6
go.sum Normal file
View File

@ -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=

45
main.go Normal file
View File

@ -0,0 +1,45 @@
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.New()
for {
n, err := file.Read(buf[:])
hasher.Write(buf[:n])
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
}
hash := hasher.Sum([]byte{})
fmt.Print(hex.EncodeToString(hash))
fmt.Print(" ")
fmt.Println(name)
}
}