mirror of
https://github.com/restic/restic.git
synced 2024-12-24 16:54:00 +00:00
ReadCloser: Call close if reader implements it
This commit is contained in:
parent
e0361b1f9f
commit
5071f28d55
1 changed files with 6 additions and 2 deletions
|
@ -125,17 +125,21 @@ func memCreate(be *MemoryBackend) (Blob, error) {
|
||||||
return blob, nil
|
return blob, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadCloser wraps a reader and adds a noop Close method.
|
// ReadCloser wraps a reader and adds a noop Close method if rd does not implement io.Closer.
|
||||||
func ReadCloser(rd io.Reader) io.ReadCloser {
|
func ReadCloser(rd io.Reader) io.ReadCloser {
|
||||||
return readCloser{rd}
|
return readCloser{rd}
|
||||||
}
|
}
|
||||||
|
|
||||||
// readCloser wraps a reader and adds a noop Close method.
|
// readCloser wraps a reader and adds a noop Close method if rd does not implement io.Closer.
|
||||||
type readCloser struct {
|
type readCloser struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rd readCloser) Close() error {
|
func (rd readCloser) Close() error {
|
||||||
|
if r, ok := rd.Reader.(io.Closer); ok {
|
||||||
|
return r.Close()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue