mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 01:18:37 +08:00
fe52502f19
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
23 lines
572 B
Go
23 lines
572 B
Go
package readers
|
|
|
|
import "io"
|
|
|
|
// LimitedReadCloser adds io.Closer to io.LimitedReader. Create one with NewLimitedReadCloser
|
|
type LimitedReadCloser struct {
|
|
*io.LimitedReader
|
|
io.Closer
|
|
}
|
|
|
|
// NewLimitedReadCloser returns a LimitedReadCloser wrapping rc to
|
|
// 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 {
|
|
return rc
|
|
}
|
|
return &LimitedReadCloser{
|
|
LimitedReader: &io.LimitedReader{R: rc, N: limit},
|
|
Closer: rc,
|
|
}
|
|
}
|