rclone_progress.go 467 B

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