code: func copyWithProgressAndStats(dst io.Writer, src io.Reader, size int, showProgress bool) error {
  	var progress *pb.ProgressBar
  	if showProgress && size > 0 {
  		progress = pb.New(size)
  		// Write to stderr in case dst is stdout.
  		progress.Output = os.Stderr
  		progress.ShowSpeed = true
  		progress.ShowPercent = true
  		progress.ShowTimeLeft = true
  		progress.SetUnits(pb.U_BYTES)
  		progress.Start()
  		dst = io.MultiWriter(dst, progress)
  	}
  
  	startTime := time.Now()
  	copied, err := io.Copy(dst, src)
  
  	if progress != nil {
  		progress.Finish()
  	}
  
  	if pathErr, ok := err.(*os.PathError); ok {
  		if errno, ok := pathErr.Err.(syscall.Errno); ok && errno == syscall.EPIPE {
  			// Pipe closed. Handle this like an EOF.
  			err = nil
  		}
  	}
  	if err != nil {
  		return err
  	}
  
  	duration := time.Now().Sub(startTime)
  	rate := int64(float64(copied) / duration.Seconds())
  	fmt.Fprintf(os.Stderr, "%d B/s (%d bytes in %s)\n", rate, copied, duration)
  
  	return nil
  }
docs: // copyWithProgressAndStats copies src to dst.
  // If showProgress is true and size is positive, a progress bar is shown.
  // After copying, final stats about the transfer speed and size are shown.
  // Progress and stats are printed to stderr.