MCPcopy
hub / github.com/rclone/rclone / reader

Method reader

backend/cache/handle.go:352–383  ·  view source on GitHub ↗

reader will return a reader depending on the capabilities of the source reader: - if it supports seeking it will seek to the desired offset and return the same reader - if it doesn't support seeking it will close a possible existing one and open at the desired offset - if there's no reader associate

(offset, end int64, closeOpen bool)

Source from the content-addressed store, hash-verified

350// - if it doesn't support seeking it will close a possible existing one and open at the desired offset
351// - if there's no reader associated with this worker, it will create one
352func (w *worker) reader(offset, end int64, closeOpen bool) (io.ReadCloser, error) {
353 var err error
354 r := w.rc
355 if w.rc == nil {
356 r, err = w.r.cacheFs().openRateLimited(func() (io.ReadCloser, error) {
357 return w.r.cachedObject.Object.Open(w.r.ctx, &fs.RangeOption{Start: offset, End: end - 1})
358 })
359 if err != nil {
360 return nil, err
361 }
362 return r, nil
363 }
364
365 if !closeOpen {
366 if do, ok := r.(fs.RangeSeeker); ok {
367 _, err = do.RangeSeek(w.r.ctx, offset, io.SeekStart, end-offset)
368 return r, err
369 } else if do, ok := r.(io.Seeker); ok {
370 _, err = do.Seek(offset, io.SeekStart)
371 return r, err
372 }
373 }
374
375 _ = w.rc.Close()
376 return w.r.cacheFs().openRateLimited(func() (io.ReadCloser, error) {
377 r, err = w.r.cachedObject.Object.Open(w.r.ctx, &fs.RangeOption{Start: offset, End: end - 1})
378 if err != nil {
379 return nil, err
380 }
381 return r, nil
382 })
383}
384
385// run is the main loop for the worker which receives offsets to preload
386func (w *worker) run() {

Callers 1

downloadMethod · 0.95

Calls 6

openRateLimitedMethod · 0.80
cacheFsMethod · 0.80
OpenMethod · 0.65
RangeSeekMethod · 0.65
SeekMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected