1. Home
  2. Docs
  3. golang
  4. utils

utils

// 获取文件唯一值
func GetFileMD5(path string) (fileMD5 string, err error) {
    f, err := os.Open(path)
    if err != nil {
        return fileMD5, err
    }
    defer f.Close()

    md5hash := sha1.New()
    if _, err := io.Copy(md5hash, f); err != nil {
        return fileMD5, err
    }

    fileMD5 = hex.EncodeToString(md5hash.Sum(nil))
    return fileMD5, nil
}

相关资料

golang 获取文件摘要代码优化

Was this article helpful to you? Yes No

How can we help?