Overview
The file operations API provides type-safe binary reading capabilities forstd::istream objects. All functions enforce type safety through the binary_readable concept and use strongly-typed offsets.
readfs (single object)
Reads a single object from a binary stream at a specified position.Parameters
Input stream to read from. Must be opened in binary mode.
Position to seek to before reading. Defaults to 0.
Reference point for the offset. Can be
origin::begin, origin::current, or origin::end.Returns
A copy of the object read from the stream.Behavior
- Seeks to the specified position using
setposfs() - Reads
sizeof(Type)bytes from the stream - Returns the value by copy
Example
readfs (span buffer)
Reads multiple objects directly into an existing buffer.Parameters
Input stream to read from. Must be opened in binary mode.
Destination buffer. Reads
out_buffer.size() * sizeof(Type) bytes.Behavior
Reads directly into the provided buffer from the current stream position. Does not change the stream position before reading.Example
readfs (dynamic vector)
Allocates and reads multiple objects into adirty_vector.
Parameters
Input stream to read from. Must be opened in binary mode.
Position to seek to before reading.
Number of elements to read.
Reference point for the offset. Can be
origin::begin, origin::current, or origin::end.Returns
Adirty_vector<Type> containing the read data.
Behavior
- Allocates a
dirty_vector<Type>withcountelements - Seeks to the specified position
- Reads
count * sizeof(Type)bytes - Returns the vector
dirty_vector uses a custom allocator that avoids unnecessary zero-initialization, making it ideal for binary buffers.Example
readfs (fixed-size array)
Reads a compile-time fixed number of objects into astd::array.
Parameters
Input stream to read from. Must be opened in binary mode.
Position to seek to before reading.
Reference point for the offset. Can be
origin::begin, origin::current, or origin::end.Template Parameters
Element type to read.
Number of elements to read (must be greater than 0).
Returns
Astd::array<Type, Size> containing the read data.
Example
last_read_ok
Checks if the last read operation succeeded.Parameters
Stream to check.
Returns
true if the stream is in a good state and not at EOF, false otherwise.
Equivalent to: file.good() && !file.eof()
Example
Type Aliases
dirty_vector
- Uses custom allocator (
vec_init_allocator) - Constrains element type to
binary_readable - Ideal for raw binary data
- No forced value-initialization overhead
Design Notes
The API provides:- Type safety: Enforced via
binary_readableconcept - Strong typing: Offsets use
offset_t, not raw integers - Zero overhead: No dynamic polymorphism or hidden buffering
- Explicit semantics: No automatic endianness handling
- Binary file parsing
- Structured header extraction
- Section-based file inspection
- Memory-mapped stream adapters
- Low-level file analysis tooling