- Notifications
You must be signed in to change notification settings - Fork68
Description
I have code that relies on reading an object from a gitdb stream.
To do this I used with a standard.read() loop (like withio.RawIOBase):
stream=db.stream(bytes.fromhex(sha))whilechunk:=stream.read(4096):yieldchunk
The behaviour I expected to see (from the duck-type with RawIOBase) is to only seeb'' at EOF:
If 0 bytes are returned, and size was not 0, this indicates end of file.
Howeverstream.read(4096) can return empty chunks even before the end of the stream, so the loop exits early.
For the file where I saw this first, it is sensitive to thesize parameter - it apparently occurs for0 < size <= 4096.
Looking at the code there is a condition to repeat a read if we got insufficient bytes:
Lines 316 to 317 inf36c0cc
| ifdcompdatand (len(dcompdat)-len(dat))<sizeandself._br<self._s: | |
| dcompdat+=self.read(size-len(dcompdat)) |
However the leadingif dcompdat and means that the condition doesn't apply if zero bytes were read. Removing this part of the condition addresses the issue (but I understand from the comment that this is in order to supportcompressed_bytes_read()).