Class ov::util::NativeStreamBuf#

class NativeStreamBuf : public std::streambuf#

A std::streambuf that reads from an already-open file handle using the platform-agnostic I/O backend.

The buffer is decoupled from any file path: it only holds a (non-owning) file handle and serves reads through io_read_into. Bulk reads (>= threshold) are passed straight to the backend into the caller’s destination buffer, saturating fast storage without an intermediate copy. Smaller, char-by-char reads are amortized through a single internal window buffer.

The handle is not owned by this object; the caller is responsible for keeping it open for the whole lifetime of the streambuf and for closing it afterwards.

Usage:

FileHandle handle = ...;        // opened and sized by the caller
std::streamoff size = ...;      // readable bytes from blob_offset to the end of the region
NativeStreamBuf buf(handle, blob_offset, size);
std::istream stream(&buf);
ib >> ...;

Public Functions

NativeStreamBuf() noexcept#

Constructs an empty streambuf not associated with any file. Any read immediately returns EOF.

explicit NativeStreamBuf(FileHandle handle, std::streamoff offset, std::streamoff size, size_t window = default_native_window, size_t threshold = default_native_threshold)#
Parameters:
  • handle – Open, readable file handle. Not owned; must outlive this object. Pass ov::invalid_handle only via the default constructor.

  • offset – Absolute file offset mapped to logical stream position 0. Must be >= 0.

  • size – Number of readable bytes starting at offset. Must be >= 0; pass 0 to create an empty (EOF-only) region. Caller is responsible for ensuring the range [offset, offset + size) lies within the file; out-of-range reads fail at the io_read_into level.

  • window – Size of the internal amortization window in bytes.

  • threshold – Minimum read size that bypasses the window and reads straight into the destination.