fix(downloader): write files concurrently

This commit is contained in:
iyear 2022-09-04 11:02:50 +08:00
parent f85aa491cb
commit 8b8c4ecb7a

View file

@ -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()