Title: Empty read from gitdb.OStream.read() before EOF · Issue #120 · gitpython-developers/gitdb · GitHub
Open Graph Title: Empty read from gitdb.OStream.read() before EOF · Issue #120 · gitpython-developers/gitdb
X Title: Empty read from gitdb.OStream.read() before EOF · Issue #120 · gitpython-developers/gitdb
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 with io.RawIOBase): stream = db.stream(bytes.fromhex(sha)) while chunk := stream.read(4096): yield chunk The behaviour...
Open Graph 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 with io.RawIOBase): stream = db.stream(bytes.fromhex(sha)) while chunk := stre...
X 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 with io.RawIOBase): stream = db.stream(bytes.fromhex(sha)) while chunk := stre...
Opengraph URL: https://github.com/gitpython-developers/gitdb/issues/120
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Empty read from gitdb.OStream.read() before EOF","articleBody":"I have code that relies on reading an object from a gitdb stream.\n\nTo do this I used with a standard `.read()` loop (like with [io.RawIOBase](https://docs.python.org/3/library/io.html#io.RawIOBase)):\n\n```python\nstream = db.stream(bytes.fromhex(sha))\nwhile chunk := stream.read(4096):\n yield chunk\n```\n\nThe behaviour I expected to see (from the duck-type with RawIOBase) is to only see `b''` at EOF:\n\n\u003e If 0 bytes are returned, and size was not 0, this indicates end of file. \n\nHowever `stream.read(4096)` can return empty chunks even before the end of the stream, so the loop exits early.\n\nFor the file where I saw this first, it is sensitive to the `size` parameter - it apparently occurs for `0 \u003c size \u003c= 4096`.\n\nLooking at the code there is a condition to repeat a read if we got insufficient bytes:\n\nhttps://github.com/gitpython-developers/gitdb/blob/f36c0cc42ea2f529291e441073f74e920988d4d2/gitdb/stream.py#L316-L317\n\nHowever the leading `if 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 support `compressed_bytes_read()`).","author":{"url":"https://github.com/lordmauve","@type":"Person","name":"lordmauve"},"datePublished":"2025-04-16T10:35:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/120/gitdb/issues/120"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:827e702c-e17f-6956-e19e-a2852f62d87d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A25E:22825A:823F2E:B18CF8:6968A476 |
| html-safe-nonce | 3a37721dfdc61add4845ccd0b3ea70674330c1dd4ca6b0b5a9e95b6dfb8b5e86 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjVFOjIyODI1QTo4MjNGMkU6QjE4Q0Y4OjY5NjhBNDc2IiwidmlzaXRvcl9pZCI6IjQ3MDI1ODYyOTcxODYyOTY5NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 53ace7c57f2f30e870e02bd49328247b756289bd422dba92cf50d5194bd5222e |
| hovercard-subject-tag | issue:2999218306 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/gitdb/120/issue_layout |
| twitter:image | https://opengraph.githubassets.com/79f6d87f930bb8f908f8a26c95555a0b819fa6cacea7e23cec4b27a3a734e87d/gitpython-developers/gitdb/issues/120 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/79f6d87f930bb8f908f8a26c95555a0b819fa6cacea7e23cec4b27a3a734e87d/gitpython-developers/gitdb/issues/120 |
| og:image:alt | I have code that relies on reading an object from a gitdb stream. To do this I used with a standard .read() loop (like with io.RawIOBase): stream = db.stream(bytes.fromhex(sha)) while chunk := stre... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lordmauve |
| hostname | github.com |
| expected-hostname | github.com |
| None | fdc7c66bd36a6c12eb8e771e806db863266e573fc299e77f27505a768d4f8a98 |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/gitdb git https://github.com/gitpython-developers/gitdb.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126093 |
| octolytics-dimension-repository_nwo | gitpython-developers/gitdb |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126093 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/gitdb |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3223a6503d318917691422cdadfbe16cd8fb21e5 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width