Skip to content

cryptor包下的Md5File函数建议改成这样,测试发现会稍快一点 #353

Description

@chenzhixiang111

func CalcFileMD5(filePath string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
return "", err
}
if stat.IsDir() {
return "", nil
}

hash := md5.New()

_, err = io.Copy(hash, file)
if err != nil {
	return "", err
}

md5Bytes := hash.Sum(nil)
md5Str := hex.EncodeToString(md5Bytes)

return md5Str, nil

}

虽然不知道是什么原理,但测试了几次,发现计算一个2G的mp4文件,这么写确实会稍快一点

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions