You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
431 B

  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. }