You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
512 B
27 lines
512 B
package md5
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"io"
|
|
)
|
|
|
|
func Sum(reader io.Reader) ([]byte, error) {
|
|
hash := md5.New()
|
|
var err error
|
|
var length int
|
|
for err == nil {
|
|
byteBuffer := make([]byte, 1024*1024)
|
|
length, err = reader.Read(byteBuffer)
|
|
// While hash.Write() wouldn't mind a Nil byteBuffer
|
|
// It is necessary for us to verify this and break
|
|
if length == 0 {
|
|
break
|
|
}
|
|
byteBuffer = byteBuffer[0:length]
|
|
hash.Write(byteBuffer)
|
|
}
|
|
if err != io.EOF {
|
|
return nil, err
|
|
}
|
|
return hash.Sum(nil), nil
|
|
}
|
|
|