添加md5流式计算
This commit is contained in:
+9
-1
@@ -22,7 +22,15 @@ func Md5File(path string) (string, error) {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
return Md5Stream(file)
|
||||
}
|
||||
|
||||
// 流式的md5
|
||||
func Md5Stream(reader io.Reader) (string, error) {
|
||||
hash := md5.New()
|
||||
io.Copy(hash, file)
|
||||
_, err := io.Copy(hash, reader)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(hash.Sum(nil)), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user