template <typename Source>
nxt::io::byte_reader class

Buffered asynchronous reader over any source with a read_some method.

Constructors, destructors, conversion operators

byte_reader(Source& source, std::span<std::byte> buffer, std::stop_token stop = {})
Use caller-owned storage as the read-ahead buffer.

Public functions

auto buffered() const →  std::span<const std::byte> noexcept
Bytes currently buffered and not yet consumed.
auto buffered_size() const →  std::size_t noexcept
Number of buffered bytes.
auto capacity() const →  std::size_t noexcept
Total buffer capacity.
auto end() const →  std::size_t noexcept
End offset of written bytes in the buffer.
auto fill(std::size_t n) →  nxt::task
Ensure at least n bytes are buffered.
auto fill_more() →  nxt::task<std::size_t>
Read more bytes from the source and return the count read.
auto peek(std::size_t n) →  nxt::task<std::span<const std::byte>>
Return the next n bytes without consuming them.
void rebase(std::size_t capacity)
Move unread bytes to the front when needed to expose capacity.
auto seek() const →  std::size_t noexcept
Start offset of unread bytes in the buffer.
template <typename Writer>
auto stream_exact(Writer& writer, std::size_t n) →  nxt::task
Stream exactly n bytes to a writer without materializing a string.
auto take(std::size_t n) →  nxt::task<std::span<const std::byte>>
Consume and return exactly n bytes.
auto take_until(std::span<const std::byte> delimiter) →  nxt::task<std::span<const std::byte>>
Consume through delimiter and return bytes before it.
auto take_until(std::string_view delimiter) →  nxt::task<std::span<const std::byte>>
Consume through a string delimiter and return bytes before it.
void toss(std::size_t n)
Discard buffered bytes.
auto unused_capacity() →  std::span<std::byte> noexcept
Unused buffer storage after the current end offset.