mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 12:13:48 +08:00
35 lines
577 B
Go
35 lines
577 B
Go
package s3
|
|
|
|
import "io"
|
|
|
|
type noOpReadCloser struct{}
|
|
|
|
type readerWithCloser struct {
|
|
io.Reader
|
|
closer func() error
|
|
}
|
|
|
|
var _ io.ReadCloser = &readerWithCloser{}
|
|
|
|
func (d noOpReadCloser) Read(b []byte) (n int, err error) {
|
|
return 0, io.EOF
|
|
}
|
|
|
|
func (d noOpReadCloser) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func limitReadCloser(rdr io.Reader, closer func() error, sz int64) io.ReadCloser {
|
|
return &readerWithCloser{
|
|
Reader: io.LimitReader(rdr, sz),
|
|
closer: closer,
|
|
}
|
|
}
|
|
|
|
func (rwc *readerWithCloser) Close() error {
|
|
if rwc.closer != nil {
|
|
return rwc.closer()
|
|
}
|
|
return nil
|
|
}
|