chore: 并入 iotlcm-openapi 历史到 openapi/(原提交 3b05d5a)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package hash
|
||||
|
||||
import "os"
|
||||
|
||||
func Sum16ChecksumData(bs []byte) uint16 {
|
||||
sum := uint16(0)
|
||||
for _, b := range bs {
|
||||
sum += uint16(b)
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func Sum16ChecksumFile(filePath string) uint16 {
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer file.Close()
|
||||
// 分块读取
|
||||
blockSize := 1024 * 1024
|
||||
buf := make([]byte, blockSize)
|
||||
sum := uint16(0)
|
||||
for {
|
||||
n, err := file.Read(buf)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
sum += Sum16ChecksumData(buf[:n])
|
||||
}
|
||||
return sum
|
||||
}
|
||||
Reference in New Issue
Block a user