cat: Use RangeOption for limited fetches to make more efficient #1825

This commit is contained in:
Nick Craig-Wood 2018-02-19 16:12:43 +00:00
parent ab0d06eb16
commit abc736df1d

View file

@ -1340,16 +1340,17 @@ func Cat(f fs.Fs, w io.Writer, offset, count int64) error {
defer func() {
accounting.Stats.DoneTransferring(o.Remote(), err == nil)
}()
opt := fs.RangeOption{Start: offset, End: -1}
size := o.Size()
thisOffset := offset
if thisOffset < 0 {
thisOffset += size
if opt.Start < 0 {
opt.Start += size
}
if count >= 0 {
opt.End = opt.Start + count - 1
}
// size remaining is now reduced by thisOffset
size -= thisOffset
var options []fs.OpenOption
if thisOffset > 0 {
options = append(options, &fs.SeekOption{Offset: thisOffset})
if opt.Start > 0 || opt.End >= 0 {
options = append(options, &opt)
}
in, err := o.Open(options...)
if err != nil {