Skip to content

Instantly share code, notes, and snippets.

@nathany nathany/checksum.go

Created Aug 11, 2016
What would you like to do?
Using MultiWriter to do two things at once
// 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
You can’t perform that action at this time.