mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
ReadCloser: Call close if reader implements it
This commit is contained in:
parent
e0361b1f9f
commit
5071f28d55
@ -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 New Issue
Block a user