enhance(hash):包装散列算法中的错误提示。
This commit is contained in:
@@ -4,6 +4,7 @@ package md5
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
@@ -24,13 +25,13 @@ func MD5Hex(data []byte) string {
|
||||
func SumFile(file string) ([]byte, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("未能打开指定文件,%w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
hasher := md5.New()
|
||||
if _, err := io.Copy(hasher, f); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("未能读取指定文件的内容,%w", err)
|
||||
}
|
||||
return hasher.Sum(nil), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user