diff options
Diffstat (limited to 'go')
-rw-r--r-- | go/cbrotli/cbrotli_test.go | 4 | ||||
-rw-r--r-- | go/cbrotli/reader.go | 3 |
2 files changed, 7 insertions, 0 deletions
diff --git a/go/cbrotli/cbrotli_test.go b/go/cbrotli/cbrotli_test.go index f59ec58..36ad2ba 100644 --- a/go/cbrotli/cbrotli_test.go +++ b/go/cbrotli/cbrotli_test.go @@ -274,6 +274,10 @@ func TestReader(t *testing.T) { "<%d bytes>", got, len(content)) } + buf := make([]byte, 4) + if _, err := r.Read(buf); err != errReaderClosed { + t.Errorf("Read-after-Close returned %v, expected %v", err, errReaderClosed) + } } func TestDecode(t *testing.T) { diff --git a/go/cbrotli/reader.go b/go/cbrotli/reader.go index 3d8d424..6e390c3 100644 --- a/go/cbrotli/reader.go +++ b/go/cbrotli/reader.go @@ -82,6 +82,9 @@ func (r *Reader) Close() error { } func (r *Reader) Read(p []byte) (n int, err error) { + if r.state == nil { + return 0, errReaderClosed + } if int(C.BrotliDecoderHasMoreOutput(r.state)) == 0 && len(r.in) == 0 { m, readErr := r.src.Read(r.buf) if m == 0 { |