mirror of
https://github.com/rclone/rclone.git
synced 2025-08-19 09:52:05 +02:00
cache: Implement RangeOption #1825
This commit is contained in:
22
lib/readers/limited.go
Normal file
22
lib/readers/limited.go
Normal file
@@ -0,0 +1,22 @@
|
||||
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,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user