- // First, make sure there's stuff in the byte reservoir if we can.
- assert(source->bytes_available <= BYTERESERVOIR_SIZE);
-
- // Read data from the source until we have enough to satisfy the request.
- while (source->bits_available + 8 * source->bytes_available < num_bits) {
- const size_t bytes_to_read = BYTERESERVOIR_SIZE - source->bytes_available;
- const ssize_t bytes_read =
- (*source->input_func)(source->userdata,
- source->bytes + source->bytes_available,
- bytes_to_read);
- assert(bytes_read <= bytes_to_read);
- assert(bytes_read >= (ssize_t)-1);
+ while (len > 0) {
+ ssize_t bytes_read = input_func(userdata, buf, len);
+ assert(bytes_read <= (ssize_t)len);