1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/checksum/checksum.go

32 lines
549 B
Go
Raw Normal View History

2017-04-14 20:39:32 +02:00
// Package checksum contain algorithms to checksum files
2017-04-14 18:50:25 +02:00
package checksum
import (
"crypto/sha256"
"encoding/hex"
"hash"
"io"
"os"
)
// SHA256 sum of the given file
func SHA256(path string) (result string, err error) {
return calculate(sha256.New(), path)
}
func calculate(hash hash.Hash, path string) (result string, err error) {
file, err := os.Open(path)
if err != nil {
return
}
defer func() { _ = file.Close() }()
_, err = io.Copy(hash, file)
if err != nil {
return
}
result = hex.EncodeToString(hash.Sum(nil))
return
}