34 lines
577 B
Go
34 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
|
|
}
|