mirror of
https://github.com/bit1001/tdl.git
synced 2025-01-06 11:56:41 +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 (
|
import (
|
||||||
"github.com/jedib0t/go-pretty/v6/progress"
|
"github.com/jedib0t/go-pretty/v6/progress"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeAt wrapper for file to use progress bar
|
// writeAt wrapper for file to use progress bar
|
||||||
type writeAt struct {
|
type writeAt struct {
|
||||||
|
mu sync.Mutex
|
||||||
f *os.File
|
f *os.File
|
||||||
tracker *progress.Tracker
|
tracker *progress.Tracker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *writeAt) WriteAt(p []byte, off int64) (int, error) {
|
func (w *writeAt) WriteAt(p []byte, off int64) (int, error) {
|
||||||
|
w.mu.Lock()
|
||||||
|
defer w.mu.Unlock()
|
||||||
|
|
||||||
at, err := w.f.WriteAt(p, off)
|
at, err := w.f.WriteAt(p, off)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.tracker.MarkAsErrored()
|
w.tracker.MarkAsErrored()
|
||||||
|
|
Loading…
Reference in a new issue