enhance(hash):包装散列算法中的错误提示。
This commit is contained in:
@@ -3,6 +3,7 @@ package crc32
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"os"
|
||||
@@ -39,14 +40,14 @@ func CRC32Hex(data []byte, table ...string) string {
|
||||
func SumFile(file string, table ...string) ([]byte, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("未能打开指定文件,%w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
crcTable := append(table, "IEEE")
|
||||
hasher := crc32.New(tableSelect(crcTable[0]))
|
||||
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