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 14:31:29 +00:00
parent 9a73688e3a
commit fe52502f19
7 changed files with 42 additions and 14 deletions
+2 -2
View File
@@ -9,10 +9,10 @@ type LimitedReadCloser struct {
}
// NewLimitedReadCloser returns a LimitedReadCloser wrapping rc to
// limit it to reading limit bytes. If limit == 0 then it does not
// limit it to reading limit bytes. If limit < 0 then it does not
// wrap rc, it just returns it.
func NewLimitedReadCloser(rc io.ReadCloser, limit int64) (lrc io.ReadCloser) {
if limit == 0 {
if limit < 0 {
return rc
}
return &LimitedReadCloser{