Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func ChecksumFile(fn string) string {
- file, err := os.Open(fn)
- if err != nil {
- panic(err.Error())
- }
- defer file.Close()
- info, _ := file.Stat()
- filesize := info.Size()
- blocks := uint64(math.Ceil(float64(filesize) / float64(filechunk)))
- hash := md5.New()
- for i := uint64(0); i < blocks; i++ {
- blocksize := int(math.Min(filechunk, float64(filesize-int64(i*filechunk))))
- buf := make([] byte, blocksize)
- file.Read(buf)
- io.WriteString(hash, string(buf))
- }
- return fmt.Sprintf("%x", hash.Sum(nil))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement