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

Allow readBuff and readString to succeed even when multiple Read calls are needed #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

barnardb
Copy link

@barnardb barnardb commented Feb 14, 2025

The readBuff and readString methods in binaryReader were directly calling Read on their buffered reader. The Read method may not fill the entire buffer that it is passed, so calls to readBuff and readString could fail when the buffered reader's buffer only contained part of the data to be read.

io.ReaderFull does what we want: it calls Read on the reader multiple times if needed in order to fill our buffer, returning an error only if there really isn't enough data left in the reader.

io.ReadFull will Read multiple times if necessary, returning an error if
there really isn't enough data left in the reader. We don't need to
check how many bytes it actually read, because it anyway returns an
error if it fails to properly fill the buffer.
@barnardb barnardb changed the title Allow readBuff to succeed even when multiple Read calls are needed Allow readBuff and readString to succeed even when multiple Read calls are needed Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant