mirror of
https://github.com/rclone/rclone.git
synced 2026-01-02 00:23:42 +00:00
fs: Adjust RangeOption.Decode to return -1 for read to end
A Range request can never request 0 bytes however this change was made to make a clearer signal that the limit means read to the end. Add test and more documentation and fixup uses
This commit is contained in:
@@ -97,17 +97,25 @@ func (o *RangeOption) Mandatory() bool {
|
||||
}
|
||||
|
||||
// Decode interprets the RangeOption into an offset and a limit
|
||||
//
|
||||
// The offset is the start of the stream and the limit is how many
|
||||
// bytes should be read from it. If the limit is -1 then the stream
|
||||
// should be read to the end.
|
||||
func (o *RangeOption) Decode(size int64) (offset, limit int64) {
|
||||
if o.Start >= 0 {
|
||||
offset = o.Start
|
||||
if o.End >= 0 {
|
||||
limit = o.End - o.Start + 1
|
||||
} else {
|
||||
limit = 0
|
||||
limit = -1
|
||||
}
|
||||
} else {
|
||||
offset = size - o.End
|
||||
limit = 0
|
||||
if o.End >= 0 {
|
||||
offset = size - o.End
|
||||
} else {
|
||||
offset = 0
|
||||
}
|
||||
limit = -1
|
||||
}
|
||||
return offset, limit
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user