mirror of
https://github.com/bit1001/tdl.git
synced 2025-01-22 13:30:54 +08:00
27 lines
471 B
Go
27 lines
471 B
Go
package downloader
|
|
|
|
import (
|
|
"github.com/jedib0t/go-pretty/v6/progress"
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
// writeAt wrapper for file to use progress bar
|
|
type writeAt struct {
|
|
mu sync.Mutex
|
|
f *os.File
|
|
tracker *progress.Tracker
|
|
}
|
|
|
|
func (w *writeAt) WriteAt(p []byte, off int64) (int, error) {
|
|
w.mu.Lock()
|
|
defer w.mu.Unlock()
|
|
|
|
at, err := w.f.WriteAt(p, off)
|
|
if err != nil {
|
|
w.tracker.MarkAsErrored()
|
|
return 0, err
|
|
}
|
|
w.tracker.Increment(int64(at))
|
|
return at, nil
|
|
}
|