From 49e5299a95e0a31a18c33d18ffcc08ecf41514c6 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 4 Apr 2020 12:21:20 +0100 Subject: [PATCH] asyncreader: make ErrorStreamAbandoned public --- fs/asyncreader/asyncreader.go | 5 +++-- fs/asyncreader/asyncreader_test.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/asyncreader/asyncreader.go b/fs/asyncreader/asyncreader.go index c385aace5..1df1603f9 100644 --- a/fs/asyncreader/asyncreader.go +++ b/fs/asyncreader/asyncreader.go @@ -21,7 +21,8 @@ const ( bufferCacheFlushTime = 5 * time.Second // flush the cached buffers after this long ) -var errorStreamAbandoned = errors.New("stream abandoned") +// ErrorStreamAbandoned is returned when the input is closed before the end of the stream +var ErrorStreamAbandoned = errors.New("stream abandoned") // AsyncReader will do async read-ahead from the input reader // and make the data available as an io.Reader. @@ -132,7 +133,7 @@ func (a *AsyncReader) fill() (err error) { if !ok { // Return an error to show fill failed if a.err == nil { - return errorStreamAbandoned + return ErrorStreamAbandoned } return a.err } diff --git a/fs/asyncreader/asyncreader_test.go b/fs/asyncreader/asyncreader_test.go index 8419cba2b..2a5e06099 100644 --- a/fs/asyncreader/asyncreader_test.go +++ b/fs/asyncreader/asyncreader_test.go @@ -279,7 +279,7 @@ func testAsyncReaderClose(t *testing.T, writeto bool) { // Abandon the copy a.Abandon() wg.Wait() - assert.Equal(t, errorStreamAbandoned, copyErr) + assert.Equal(t, ErrorStreamAbandoned, copyErr) // t.Logf("Copied %d bytes, err %v", copyN, copyErr) assert.True(t, copyN > 0) } @@ -353,7 +353,7 @@ func TestAsyncReaderSkipBytes(t *testing.T) { if initialRead >= len(data) { assert.Equal(t, err, io.EOF) } else { - assert.True(t, err == errorStreamAbandoned || err == io.EOF) + assert.True(t, err == ErrorStreamAbandoned || err == io.EOF) } } })