MCPcopy
hub / github.com/Tencent/CodeAnalysis / Md5

Function Md5

tools/owl/scan/scanner.go:83–106  ·  view source on GitHub ↗

Md5 get the md5 value of the file based on the path

(filepath string)

Source from the content-addressed store, hash-verified

81
82// Md5 get the md5 value of the file based on the path
83func Md5(filepath string) (string, error) {
84 file, err := os.Open(filepath)
85 if err != nil {
86 return "", err
87 }
88 defer file.Close()
89
90 fileInfo, err := os.Stat(filepath)
91 if err != nil {
92 return "", err
93 }
94
95 hashed := md5.New()
96
97 if fileInfo.Size() >= fileMaxSize {
98 return BlockMd5(file, fileInfo.Size(), hashed)
99 } else {
100 io.Copy(hashed, file)
101 }
102
103 // io.Copy(hashed, file)
104
105 return hex.EncodeToString(hashed.Sum(nil)), nil
106}
107
108// BlockMd5 Built-in sharding md5 algorithm used
109func BlockMd5(file *os.File, size int64, hashed hash.Hash) (string, error) {

Callers 3

SearchMethod · 0.85
SearchMethod · 0.85
ListMethod · 0.85

Calls 1

BlockMd5Function · 0.85

Tested by

no test coverage detected