mirror of
https://github.com/bit1001/tdl.git
synced 2025-01-04 02:52:56 +08:00
fix(downloader): write files concurrently
This commit is contained in:
parent
f85aa491cb
commit
8b8c4ecb7a
1 changed files with 5 additions and 0 deletions
|
@ -3,15 +3,20 @@ 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()
|
||||
|
|
Loading…
Reference in a new issue