rclone_progress.go 431 B

12345678910111213141516171819
  1. package rclone_backend
  2. import "github.com/rclone/rclone/fs/accounting"
  3. type ProgressReader struct {
  4. acc *accounting.Account
  5. tr *accounting.Transfer
  6. fn func(progressed int64, percentage float32) error
  7. }
  8. func (pr *ProgressReader) Read(p []byte) (n int, err error) {
  9. n, err = pr.acc.Read(p)
  10. if err != nil {
  11. return
  12. }
  13. snap := pr.tr.Snapshot()
  14. err = pr.fn(snap.Bytes, 100*float32(snap.Bytes)/float32(snap.Size))
  15. return
  16. }