go-asink/hash.go
2013-02-11 23:17:12 -05:00

26 lines
352 B
Go

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