Last active
August 29, 2015 14:07
-
-
Save techjanitor/531002af54b105b1129a to your computer and use it in GitHub Desktop.
Get MD5 hash with TeeReader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make new md5 | |
hasher := md5.New() | |
// Make a new file | |
image, err := os.Create(imagefile) | |
if err != nil { | |
err = errors.New("problem creating file") | |
return | |
} | |
// Save file and also read into hasher for md5 | |
_, err = io.Copy(image, io.TeeReader(file, hasher)) | |
if err != nil { | |
os.RemoveAll(imagefile) | |
err = errors.New("problem copying file") | |
return | |
} | |
// Set md5sum from hasher | |
md5sum = hex.EncodeToString(hasher.Sum(nil)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment