asyncreader: fix EOF error

This commit is contained in:
buengese 2019-12-05 13:32:42 +01:00 committed by Nick Craig-Wood
parent 41ba1bba2b
commit a186284b23
2 changed files with 10 additions and 3 deletions

View file

@ -174,6 +174,9 @@ func (a *AsyncReader) WriteTo(w io.Writer) (n int64, err error) {
n = 0 n = 0
for { for {
err = a.fill() err = a.fill()
if err == io.EOF {
return n, nil
}
if err != nil { if err != nil {
return n, err return n, err
} }
@ -183,6 +186,10 @@ func (a *AsyncReader) WriteTo(w io.Writer) (n int64, err error) {
if err != nil { if err != nil {
return n, err return n, err
} }
if a.cur.err == io.EOF {
a.err = a.cur.err
return n, err
}
if a.cur.err != nil { if a.cur.err != nil {
a.err = a.cur.err a.err = a.cur.err
return n, a.cur.err return n, a.cur.err

View file

@ -60,12 +60,12 @@ func TestAsyncWriteTo(t *testing.T) {
var dst = &bytes.Buffer{} var dst = &bytes.Buffer{}
n, err := io.Copy(dst, ar) n, err := io.Copy(dst, ar)
assert.Equal(t, io.EOF, err) require.NoError(t, err)
assert.Equal(t, int64(10), n) assert.Equal(t, int64(10), n)
// Should still return EOF // Should still not return any errors
n, err = io.Copy(dst, ar) n, err = io.Copy(dst, ar)
assert.Equal(t, io.EOF, err) require.NoError(t, err)
assert.Equal(t, int64(0), n) assert.Equal(t, int64(0), n)
err = ar.Close() err = ar.Close()