mirror of
https://github.com/pgsty/minio.git
synced 2026-08-09 07:43:29 +03:00
Adding minio-hash with streaming crypto hashes
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package md5
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"io"
|
||||
)
|
||||
|
||||
func Sum(reader io.Reader) ([]byte, error) {
|
||||
hash := md5.New()
|
||||
var err error
|
||||
for err == nil {
|
||||
length := 0
|
||||
byteBuffer := make([]byte, 1024*1024)
|
||||
length, err = reader.Read(byteBuffer)
|
||||
byteBuffer = byteBuffer[0:length]
|
||||
hash.Write(byteBuffer)
|
||||
}
|
||||
if err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
return hash.Sum(nil), nil
|
||||
}
|
||||
Reference in New Issue
Block a user