4kills/go-zlib

Read() doesn't adhere to io.Reader specifications

Closed this issue · 1 comments

Hi,

I noticed that Read() does not adhere to the io.Reader specifications;.

The specification says Read reads up to len(p) bytes into p (source)
Meanwhile, the library's Read() does the following (source)

		min := len(p)
		if len(p) < r.outBuffer.Len() {
			min = r.outBuffer.Len()
		}
		copy(p, r.outBuffer.Bytes()[:min])

Consequently, the read could be larger than len(p).
I'm wondering whether this deviation is deliberate?

Thanks!

You actually found a bug there. The if statement should not use lesser-than but greater-than. I've fixed it in the latest release.