diff --git a/fs/asyncreader/asyncreader.go b/fs/asyncreader/asyncreader.go index b4feb3149..c385aace5 100644 --- a/fs/asyncreader/asyncreader.go +++ b/fs/asyncreader/asyncreader.go @@ -174,6 +174,9 @@ func (a *AsyncReader) WriteTo(w io.Writer) (n int64, err error) { n = 0 for { err = a.fill() + if err == io.EOF { + return n, nil + } if err != nil { return n, err } @@ -183,6 +186,10 @@ func (a *AsyncReader) WriteTo(w io.Writer) (n int64, err error) { if err != nil { return n, err } + if a.cur.err == io.EOF { + a.err = a.cur.err + return n, err + } if a.cur.err != nil { a.err = a.cur.err return n, a.cur.err diff --git a/fs/asyncreader/asyncreader_test.go b/fs/asyncreader/asyncreader_test.go index 2b4e8aaba..8419cba2b 100644 --- a/fs/asyncreader/asyncreader_test.go +++ b/fs/asyncreader/asyncreader_test.go @@ -60,12 +60,12 @@ func TestAsyncWriteTo(t *testing.T) { var dst = &bytes.Buffer{} n, err := io.Copy(dst, ar) - assert.Equal(t, io.EOF, err) + require.NoError(t, err) assert.Equal(t, int64(10), n) - // Should still return EOF + // Should still not return any errors n, err = io.Copy(dst, ar) - assert.Equal(t, io.EOF, err) + require.NoError(t, err) assert.Equal(t, int64(0), n) err = ar.Close()