Skip to content

Commit

Permalink
Enable reading from a closed gbytes.Buffer (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhsingyuchen authored Aug 27, 2022
1 parent 758e947 commit 061fd26
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
6 changes: 0 additions & 6 deletions gbytes/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,11 @@ func (b *Buffer) Write(p []byte) (n int, err error) {
/*
Read implements the io.Reader interface. It advances the
cursor as it reads.
Returns an error if called after Close.
*/
func (b *Buffer) Read(d []byte) (int, error) {
b.lock.Lock()
defer b.lock.Unlock()

if b.closed {
return 0, errors.New("attempt to read from closed buffer")
}

if uint64(len(b.contents)) <= b.readCursor {
return 0, io.EOF
}
Expand Down
13 changes: 0 additions & 13 deletions gbytes/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,6 @@ var _ = Describe("Buffer", func() {
Expect(err).Should(Equal(io.EOF))
Expect(n).Should(Equal(0))
})

Context("after the buffer has been closed", func() {
It("returns an error", func() {
buffer := BufferWithBytes([]byte("abcde"))

buffer.Close()

dest := make([]byte, 3)
n, err := buffer.Read(dest)
Expect(err).Should(HaveOccurred())
Expect(n).Should(Equal(0))
})
})
})

Describe("detecting regular expressions", func() {
Expand Down

0 comments on commit 061fd26

Please sign in to comment.