Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable reading from a closed gbytes.Buffer #575

Merged
merged 1 commit into from Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions gbytes/buffer.go
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
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