Md5 get the md5 value of the file based on the path
(filepath string)
| 81 | |
| 82 | // Md5 get the md5 value of the file based on the path |
| 83 | func 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 |
| 109 | func BlockMd5(file *os.File, size int64, hashed hash.Hash) (string, error) { |