forked from TrueCloudLab/rclone
cat: Use RangeOption for limited fetches to make more efficient #1825
This commit is contained in:
parent
ab0d06eb16
commit
abc736df1d
1 changed files with 8 additions and 7 deletions
|
@ -1340,16 +1340,17 @@ func Cat(f fs.Fs, w io.Writer, offset, count int64) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
accounting.Stats.DoneTransferring(o.Remote(), err == nil)
|
accounting.Stats.DoneTransferring(o.Remote(), err == nil)
|
||||||
}()
|
}()
|
||||||
|
opt := fs.RangeOption{Start: offset, End: -1}
|
||||||
size := o.Size()
|
size := o.Size()
|
||||||
thisOffset := offset
|
if opt.Start < 0 {
|
||||||
if thisOffset < 0 {
|
opt.Start += size
|
||||||
thisOffset += size
|
}
|
||||||
|
if count >= 0 {
|
||||||
|
opt.End = opt.Start + count - 1
|
||||||
}
|
}
|
||||||
// size remaining is now reduced by thisOffset
|
|
||||||
size -= thisOffset
|
|
||||||
var options []fs.OpenOption
|
var options []fs.OpenOption
|
||||||
if thisOffset > 0 {
|
if opt.Start > 0 || opt.End >= 0 {
|
||||||
options = append(options, &fs.SeekOption{Offset: thisOffset})
|
options = append(options, &opt)
|
||||||
}
|
}
|
||||||
in, err := o.Open(options...)
|
in, err := o.Open(options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue