added preload transfer rate
This commit is contained in:
parent
0c4376ec32
commit
470eeb921c
5 changed files with 111 additions and 13 deletions
|
|
@ -42,6 +42,7 @@ func (p *preload) Read(data []byte) (n int, err error) {
|
|||
if p.f.hasChunk(n) {
|
||||
p.skipped++
|
||||
_, err = p.f.Seek(int64(n), io.SeekCurrent)
|
||||
n = 0
|
||||
return
|
||||
}
|
||||
n, err = p.f.readToCache(data)
|
||||
|
|
@ -49,8 +50,9 @@ func (p *preload) Read(data []byte) (n int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (f *File) Preload(ctx context.Context, fin func(), errf func(), stop func()) {
|
||||
func (f *File) Preload(ctx context.Context, r *Rate, fin, errf, stop func()) {
|
||||
log := f.log
|
||||
defer r.Stop()
|
||||
defer f.Close()
|
||||
if f.offline {
|
||||
log.V(2).Error(errors.New("no preload in offline mode"), "error preloading file")
|
||||
|
|
@ -65,7 +67,8 @@ func (f *File) Preload(ctx context.Context, fin func(), errf func(), stop func()
|
|||
|
||||
log.V(2).Info("preload started")
|
||||
p := &preload{f: f, ctx: ctx}
|
||||
_, err := io.Copy(Discard, p)
|
||||
r.SetReader(p)
|
||||
_, err := io.Copy(Discard, r)
|
||||
if err == context.Canceled {
|
||||
log.V(2).Info("preload canceled", "skipped", p.skipped, "written", p.written)
|
||||
stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue