binary_io::file_istream class final

A stream which composes a file handle.

Base classes

class file_stream_base
Implements the common interface of every file_stream.
template<class Derived>
class istream_interface<binary_io::file_istream>
A CRTP utility which can be used to flesh out the interface of a given stream.

Constructors, destructors, conversion operators

file_istream(const std::filesystem::path& a_path)

Buffer management

auto rdbuf() -> std::FILE* noexcept
Provides mutable access to the underlying buffer.
auto rdbuf() const -> const std::FILE* noexcept
Provides immutable access to the underlying buffer.

Buffering

void flush() noexcept
Flushes the underlying file buffer.

File operations

void close() noexcept
Closes the stream's file handle, if applicable.
auto is_open() const -> bool noexcept
Checks if the stream has an open file handle.
void open(const std::filesystem::path& a_path)
Opens the file at the given path.

Formatting

auto endian() const -> std::endian noexcept
Gets the current default endian format.
void endian(std::endian a_endian) noexcept
Sets the default endian format.

Position

void seek_absolute(binary_io::streamoff a_pos) noexcept
Seek to an absolute position in the stream (i.e. from the beginning).
void seek_relative(binary_io::streamoff a_off) noexcept
Seek to a position in the stream relative to the current position.
auto tell() const -> binary_io::streamoff noexcept
Gets the current stream position.

Reading

auto read() -> std::tuple<Args...>
Batch reads the given values from the input stream.
auto read(std::endian a_endian) -> std::tuple<Args...>
Batch reads the given values with the given endian format from the input stream.
void read(Args&... a_args)
Batch reads the given values from the input stream.
void read(std::endian a_endian, Args&... a_args)
Batch reads the given values with the given endian format from the input stream.
void read_bytes(std::span<std::byte> a_dst)
Reads bytes into the given buffer.

Function documentation

void binary_io::file_istream::open(const std::filesystem::path& a_path)

Opens the file at the given path.

Parameters
a_path The path to the file to open.
Exceptions
std::system_error Thrown when filesystem errors are encountered.

void binary_io::file_istream::read_bytes(std::span<std::byte> a_dst)

Reads bytes into the given buffer.

Parameters
a_dst The buffer to read bytes into.
Exceptions
binary_io::buffer_exhausted Thrown when the buffer has less than the requested number of bytes.