mirror of
https://github.com/minio/minio.git
synced 2024-12-29 08:33:21 -05:00
28 lines
512 B
Go
28 lines
512 B
Go
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
|
|
}
|