mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 23:49:15 +01:00
cat: Use RangeOption for limited fetches to make more efficient #1825
This commit is contained in:
parent
ab0d06eb16
commit
abc736df1d
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user