enhance(hash):包装散列算法中的错误提示。
This commit is contained in:
@@ -3,6 +3,7 @@ package crc8
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/sigurn/crc8"
|
||||
@@ -51,14 +52,14 @@ func CRC8Hex(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, "CRC8")
|
||||
var buf = make([]byte, 0)
|
||||
if _, err := f.Read(buf); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("读取指定文件内容出错,%w", err)
|
||||
}
|
||||
return []byte{crc8.Checksum(buf, hasherSelect(crcTable[0]))}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user