This commit is contained in:
2013-02-11 23:17:12 -05:00
parent 54a0359897
commit 61d5532e33
6 changed files with 69 additions and 39 deletions

12
hash.go
View File

@ -1,21 +1,25 @@
package main
import (
"crypto/sha256"
"fmt"
"io"
"os"
"fmt"
"crypto/sha256"
)
func HashFile(filename string) (string, error) {
hashfn := sha256.New()
infile, err := os.Open(filename)
if err != nil { return "", err }
if err != nil {
return "", err
}
defer infile.Close()
_, err = io.Copy(hashfn, infile)
if err != nil { return "", err }
if err != nil {
return "", err
}
return fmt.Sprintf("%x", hashfn.Sum(nil)), nil
}