mirror of
https://github.com/octoleo/restic.git
synced 2024-11-04 12:34:13 +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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user