amazon-ion / ion-c

A C implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
166 stars 43 forks source link

Fix user stream reading to carry out multiple handler calls when needed #320

Closed nirosys closed 1 year ago

nirosys commented 1 year ago

Issue #, if available: 318

Description of changes: Prior to this PR when a user managed buffer is read with the intention of filling a page, the handler for the buffer is called only once. No information is provided to the handler in order to communicate how much data is needed.

This resulted in user managed buffers not correctly seeking and the reader falling out of sync with the underlying buffer. More details can be seen in issue #318.

This PR updates the _ion_stream_fread function to ensure that the user managed buffer handler is called enough times to fill the requested buffer, stopping early in the cases of error, or insufficient data.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

nirosys commented 1 year ago

ty Tyler! Updated with a new commit adding a unit test based on the test program I had been used.