1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/utils/checksum.go
Sam Alba 8d230cf89c registry: Added simple checksums (sha256) for layers
Docker-DCO-1.1-Signed-off-by: Sam Alba <sam@docker.com> (github: samalba)
2014-02-23 18:50:04 -08:00

24 lines
338 B
Go

package utils
import (
"encoding/hex"
"hash"
"io"
)
type CheckSum struct {
io.Reader
Hash hash.Hash
}
func (cs *CheckSum) Read(buf []byte) (int, error) {
n, err := cs.Reader.Read(buf)
if err == nil {
cs.Hash.Write(buf[:n])
}
return n, err
}
func (cs *CheckSum) Sum() string {
return hex.EncodeToString(cs.Hash.Sum(nil))
}