refine error handling in byte reader

pull/432/head
Darien Raymond 2017-02-07 00:39:07 +01:00
parent 3643dc37e0
commit 4e8e15d528
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 6 additions and 6 deletions

View File

@ -46,7 +46,7 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {
type BufferToBytesReader struct { type BufferToBytesReader struct {
stream Reader stream Reader
current *Buffer current *Buffer
eof bool err error
} }
// Fill fills in the internal buffer. // Fill fills in the internal buffer.
@ -55,20 +55,20 @@ func (v *BufferToBytesReader) Fill() {
b, err := v.stream.Read() b, err := v.stream.Read()
v.current = b v.current = b
if err != nil { if err != nil {
v.eof = true v.err = err
v.current = nil v.current = nil
} }
} }
func (v *BufferToBytesReader) Read(b []byte) (int, error) { func (v *BufferToBytesReader) Read(b []byte) (int, error) {
if v.eof { if v.err != nil {
return 0, io.EOF return 0, v.err
} }
if v.current == nil { if v.current == nil {
v.Fill() v.Fill()
if v.eof { if v.err != nil {
return 0, io.EOF return 0, v.err
} }
} }
nBytes, err := v.current.Read(b) nBytes, err := v.current.Read(b)