Commit 33f70931 authored by Max Kellermann's avatar Max Kellermann

decoder/API: add decoder_read_much()

parent 8830ea31
......@@ -42,6 +42,27 @@ decoder_read(DecoderClient *client,
}
}
size_t
decoder_read_much(DecoderClient *client, InputStream &is,
void *_buffer, size_t size) noexcept
{
uint8_t *buffer = (uint8_t *)_buffer;
size_t total = 0;
while (size > 0 && !is.LockIsEOF()) {
size_t nbytes = decoder_read(client, is, buffer, size);
if (nbytes == 0)
return false;
total += nbytes;
buffer += nbytes;
size -= nbytes;
}
return total;
}
bool
decoder_read_full(DecoderClient *client, InputStream &is,
void *_buffer, size_t size) noexcept
......
......@@ -76,6 +76,18 @@ decoder_read(DecoderClient &decoder, InputStream &is,
/**
* Blocking read from the input stream. Attempts to fill the buffer
* as much as possible, until either end-of-file is reached or an
* error occurs.
*
* @return the number of bytes read, or 0 if one of the following
* occurs: end of file; error; command (like SEEK or STOP).
*/
size_t
decoder_read_much(DecoderClient *decoder, InputStream &is,
void *buffer, size_t size) noexcept;
/**
* Blocking read from the input stream. Attempts to fill the buffer
* completely; there is no partial result.
*
* @return true on success, false on error or command or not enough
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment