Skip to content

Instantly share code, notes, and snippets.

@limingzju
Created May 5, 2015 06:03
Show Gist options
  • Save limingzju/caaee86b953d7032dd96 to your computer and use it in GitHub Desktop.
Save limingzju/caaee86b953d7032dd96 to your computer and use it in GitHub Desktop.
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