Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Empty read from gitdb.OStream.read() before EOF #120

Open
@lordmauve

Description

@lordmauve

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:

gitdb/gitdb/stream.py

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()).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp