添加md5流式计算

This commit is contained in:
Yun
2024-03-15 13:49:58 +08:00
parent be8a2f84bd
commit 8b8575566b
3 changed files with 21 additions and 2 deletions
+9 -1
View File
@@ -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
}