Created
May 5, 2015 06:03
-
-
Save limingzju/caaee86b953d7032dd96 to your computer and use it in GitHub Desktop.
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
type CopyCb func(written int64) | |
func CopyWithCb(dst io.Writer, src io.Reader, cb CopyCb) (written int64, err error) { | |
for { | |
n, err := io.CopyN(dst, src, KB) | |
written += n | |
cb(written) | |
if err != nil { | |
if err == io.EOF { | |
return written, nil | |
} | |
return written, err | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment