1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-08 03:23:26 +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:
Nick Craig-Wood
2018-01-27 10:07:17 +00:00
parent 9a73688e3a
commit fe52502f19
7 changed files with 42 additions and 14 deletions

View File

@@ -220,11 +220,11 @@ func (o *Object) Open(options ...fs.OpenOption) (io.ReadCloser, error) {
var err error
cacheReader := NewObjectHandle(o)
var offset, limit int64
var offset, limit int64 = 0, -1
for _, option := range options {
switch x := option.(type) {
case *fs.SeekOption:
offset, limit = x.Offset, 0
offset = x.Offset
case *fs.RangeOption:
offset, limit = x.Decode(o.Size())
}

View File

@@ -634,11 +634,11 @@ func (f *ftpReadCloser) Close() error {
func (o *Object) Open(options ...fs.OpenOption) (rc io.ReadCloser, err error) {
// defer fs.Trace(o, "")("rc=%v, err=%v", &rc, &err)
path := path.Join(o.fs.root, o.remote)
var offset, limit int64
var offset, limit int64 = 0, -1
for _, option := range options {
switch x := option.(type) {
case *fs.SeekOption:
offset, limit = x.Offset, 0
offset = x.Offset
case *fs.RangeOption:
offset, limit = x.Decode(o.Size())
default:

View File

@@ -676,13 +676,12 @@ func (file *localOpenFile) Close() (err error) {
// Open an object for read
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
var offset int64
var limit int64
var offset, limit int64 = 0, -1
hashes := hash.Supported
for _, option := range options {
switch x := option.(type) {
case *fs.SeekOption:
offset, limit = x.Offset, 0
offset = x.Offset
case *fs.RangeOption:
offset, limit = x.Decode(o.size)
case *fs.HashesOption:

View File

@@ -855,11 +855,11 @@ func (file *ObjectReader) Close() (err error) {
// Open a remote sftp file object for reading. Seek is supported
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
var offset, limit int64
var offset, limit int64 = 0, -1
for _, option := range options {
switch x := option.(type) {
case *fs.SeekOption:
offset, limit = x.Offset, 0
offset = x.Offset
case *fs.RangeOption:
offset, limit = x.Decode(o.Size())
default: