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

Better handling of EOF in read_exact_bytes #201

Merged
merged 2 commits into from
May 11, 2024

Conversation

fintelia
Copy link
Contributor

After e69b4c5 I'm seeing that trying to read from a BufReader with a small buffer no longer works (using the wrapper from image-rs/image#2198):

let decoder = JpegDecoder::new(BufReader::with_capacity(32, Cursor::new(include_bytes!("test.jpg")))).unwrap();
let mut decoded = vec![0; decoder.total_bytes() as usize];
decoder.read_image(&mut decoded).unwrap();

Produces:

I/O errors Not enough bytes, expected 14 but found 3144

The error is because BufReader sometimes returns fewer bytes than requested in a read call without it indicating that the end-of-input has been reached.

This PR changes the implementation of ZByteReaderTrait::read_exact_bytes to only treat zero bytes read as meaning EOF and all other partial reads get re-attempted

@etemesi254
Copy link
Owner

Yea this makes more sense, thank you.

Sorry for missing that, the docs are pretty weird on the behavior.

@etemesi254 etemesi254 merged commit 4cf0ffe into etemesi254:dev May 11, 2024
19 of 23 checks passed
@fintelia fintelia deleted the cursor-eof branch May 11, 2024 22:48
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.

2 participants