enhance(hash):包装散列算法中的错误提示。

This commit is contained in:
徐涛
2023-07-13 13:58:53 +08:00
parent 2e276ca33c
commit 955d3a96f2
9 changed files with 27 additions and 18 deletions

View File

@@ -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
}