Created
August 11, 2016 23:09
-
-
Save nathany/ca7a3b5aac1d89d821014e644230d691 to your computer and use it in GitHub Desktop.
Using MultiWriter to do two things at once
This file contains hidden or 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
// copyAndChecksum calculates a checksum while writing to another output | |
func copyAndChecksum(w io.Writer, r io.Reader) (string, error) { | |
h := md5.New() | |
mw := io.MultiWriter(w, h) | |
if _, err := io.Copy(mw, r); err != nil { | |
return "", err | |
} | |
return hex.EncodeToString(h.Sum(nil)), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment