pkg/ioutils: add ReaderErrWrapper to readers

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack 2014-08-20 23:50:42 +03:00
parent 65f57a95bb
commit 2a633df603

View file

@ -22,6 +22,26 @@ func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser {
} }
} }
type readerErrWrapper struct {
reader io.Reader
closer func()
}
func (r *readerErrWrapper) Read(p []byte) (int, error) {
n, err := r.reader.Read(p)
if err != nil {
r.closer()
}
return n, err
}
func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader {
return &readerErrWrapper{
reader: r,
closer: closer,
}
}
type bufReader struct { type bufReader struct {
sync.Mutex sync.Mutex
buf *bytes.Buffer buf *bytes.Buffer