First working cut

This commit is contained in:
Barak Michener 2016-11-02 15:33:53 -07:00
parent 608290c74e
commit db918f12ad
4 changed files with 436 additions and 0 deletions

43
sha.go Normal file
View file

@ -0,0 +1,43 @@
package main
import (
"crypto/sha256"
"fmt"
"io"
"os"
)
type fileSha struct {
bytes []byte
size int64
}
func sha256File(path string) fileSha {
h := sha256.New()
f, err := os.Open(path)
if err != nil {
panic(err)
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
panic(err)
}
io.Copy(h, f)
return fileSha{
bytes: h.Sum(nil),
size: fi.Size(),
}
}
func (f fileSha) String() string {
return fmt.Sprintf("sha256:%x", f.bytes)
}
func (f fileSha) Name() string {
return fmt.Sprintf("%x", f.bytes)
}
func (f fileSha) Size() int64 {
return f.size
}