2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 08:44:02 +00:00

ReadCloser: Call close if reader implements it

This commit is contained in:
Alexander Neumann 2016-01-02 14:10:38 +01:00
parent e0361b1f9f
commit 5071f28d55

View File

@ -125,17 +125,21 @@ func memCreate(be *MemoryBackend) (Blob, error) {
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 {
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 {
io.Reader
}
func (rd readCloser) Close() error {
if r, ok := rd.Reader.(io.Closer); ok {
return r.Close()
}
return nil
}