Skip to content

<blake3pp/io.hpp>

File hashing at storage speed: the windowed pipeline that joins the file_reader to the compute engine. The reader uses io_uring + O_DIRECT, the I/O ring or IOCP + NO_BUFFERING, GCD + F_NOCACHE, or POSIX AIO + O_DIRECT, whatever the platform allows.

While window i is being hashed, windows i+1..i+depth-1 are already streaming in. The queue-depth buffer ring is the backpressure mechanism, so the pipeline allocates nothing past setup.

The primitive is update_file(), which is hasher::update() with a file as the source. It streams into a caller-owned hasher and returns. Because the hasher belongs to the caller, its mode (plain, keyed, derive_key) and every finalize form (digest, extended output, the seekable reader) compose with file input without this header knowing about them. hash_file() is the one-shot convenience on top: construct, update_file, finalize.

This header is free of any execution-provider dependency: core.hpp, dispatch.hpp and io.hpp compile against the standard library alone. File reads still overlap hashing here (the file reader is asynchronous); what is sequential is the compute. update_stream() reads a pipe or standard input on the calling thread. The scheduler-taking overloads, which fan each window out over cores, live in parallel_io.hpp, which, like parallel.hpp and async_io.hpp, needs an execution provider (stdexec, beman or std::execution).

std::filesystem::path is the path currency throughout (string literals and std::string convert implicitly). Each entry point follows the standard library's dual-overload idiom: the plain form throws std::system_error on I/O failure, the std::error_code& form reports through ec instead.

file_io_options

struct blake3pp::file_io_options;

The pipeline's knobs: what update_file() takes. The hasher it streams into already carries the SIMD variant and the mode.

Data members

window_bytes

std::size_t window_bytes = detail::default_window_bytes;

Bytes per window, 8 MiB by default; rounded down to a power-of-2 multiple of chunk_size, minimum 64 KiB.

queue_depth

unsigned queue_depth = detail::default_queue_depth;

Reads in flight at once, four by default; clamped to [2, 256]. Each window costs window_bytes of arena plus its own tables, which is what the ceiling guards (and BLAKE3PP_MAX_QUEUE_DEPTH moves). The sequential forms allocate exactly this many windows.

The forms that take a scheduler allocate more. The depth is what the device sees; the window objects behind it are what the hash pool draws work from while the device serves the next reads, and on a fast device they are worth more than the depth is. Their arena follows the machine's thread count, not the scheduler's: one window per four threads, held between 128 MiB and 2 GiB of windows (detail::read_plan_budget_bytes), and at most 256 windows or as many as the file has. A pool narrower than the machine gets the same arena. A smaller window_bytes shrinks the arena only while the thread count puts it above the 128 MiB floor; at the floor it buys more, smaller windows within the same 128 MiB. docs/pipeline.md carries the measurement.

io

io_mode io = io_mode::direct;

io_mode::direct bypasses the page cache where the platform supports it, and degrades to buffered reads where it does not. A file below 512 KiB (detail::min_pipeline_bytes) is read through the page cache either way: it runs without the pipeline, and buffered is the faster read there, by 5-10% on a four-drive PCIe 5 stripe (the figures are at detail::min_pipeline_bytes).

submit

submit_mode submit = submit_mode::offload;

submit_mode::offload issues each read on the kernel's I/O worker threads instead of inside the submit call (Linux: io_uring's IOSQE_ASYNC). Issuing a large direct read costs real CPU time, and immediate submission pays it on the thread that also drives the hash; kernels since 6.x issue inline whenever they can, so offload asks for the hand-off explicitly.

engine

engine_mode engine = engine_mode::async;

engine_mode::sync gives up the engines is_async() marks; for a given build, compiled_io_engines() filtered by is_async() names them. Which rung was engaged is reported after the fact: read_backend(trace.driver()) for a read, write_report::backend for a write.

windows_api

windows_engine windows_api = windows_engine::ioring;

Windows only; see windows_engine. The engaged rung is reported after the fact and names which one ran.

trace

trace_buffer * trace = nullptr;

Where to record per-window timing (<blake3pp/trace.hpp>); nullptr records nothing, at the cost of one branch per window. Not owned and not copied: the buffer has to outlive the call. The senders in <blake3pp/async_io.hpp> do not read this field: their operation state is a type fixed at connect, so they take the tracing policy as an argument instead (blake3pp::buffer_tracer).

file_io_probe

struct blake3pp::file_io_probe;

What update_file() over a scheduler would engage for a file: the geometry its plan decides from the options and the file's size, and the rung the open lands on. The sequential update_file() opens the same way and reads through queue_depth windows. See probe_file_io().

Data members

file_bytes

std::uint64_t file_bytes = 0;

The file's size as the filesystem reports it.

window_bytes

std::size_t window_bytes = 0;

Bytes per window, as the pipeline rounds the request.

reads_in_flight

unsigned reads_in_flight = 0;

Reads the device sees at once.

windows

unsigned windows = 0;

Windows in flight at most, reading or being hashed, in the scheduler form; never more than the file has.

io

io_mode io = io_mode::buffered;

Whether the open asks for the cache bypass: the caller's io_mode::direct, granted only to a file of at least 512 KiB (detail::min_pipeline_bytes) and to a size the filesystem would not give.

backend

std::string backend;

The rung the open landed on, spelled as write_report::backend is: an engine token as to_string(io_engine) gives it ("io_uring", "ioring", "iocp", "gcd", "aio", "pread", "readfile", "stdio"), then "+direct" or "+nocache" where the cache bypass engaged, then " (inline submit)" where submit_mode::immediate was asked for, and the reason appended where the async engine was asked for and refused. Where the bypass was asked for and the filesystem declined it, this says so by naming the buffered rung while io above is io_mode::direct.

The leading token is an engine name: to_string(io_engine) spells the same words from the same table, so backend and best_io_engine() agree for a file that got what a fresh open engages.

file_write_options

struct blake3pp::file_write_options;

Knobs for write_file(): the geometry of a generated file. On the write side the windows in flight are the whole parallelism, because one window's fill is sequential, so the queue depth is the lever and the window size moves little. The default depth is therefore automatic: over a scheduler, one window per hardware thread as long as depth x window stays within 256 MiB in flight (32 windows of the default 8 MiB), past which a striped volume slows down; in the sequential forms, two, one filling while the other drains.

Data members

window_bytes

std::size_t window_bytes = detail::default_write_window_bytes;

Bytes per window. The sequential forms round up to a multiple of 4 KiB (minimum 64 KiB, maximum 1 GiB); the forms that take a scheduler round down to a power-of-2 multiple of chunk_size, as reading does, so one options object asking for an odd size can mean two geometries.

queue_depth

unsigned queue_depth = detail::default_write_queue_depth;

Windows in flight, clamped to [2, 256]; zero means automatic, as described above. A caller that knows its pool is smaller than the machine, or its device prefers less in flight, sets it.

io

io_mode io = io_mode::direct;

See io_mode.

submit

submit_mode submit = submit_mode::offload;

See submit_mode.

engine

engine_mode engine = engine_mode::async;

engine_mode::sync gives up the engines is_async() marks; for a given build, compiled_io_engines() filtered by is_async() names them.

windows_api

windows_engine windows_api = windows_engine::ioring;

Windows only; see windows_engine. The engaged rung is reported after the fact and names which one ran.

allocation

ntfs_allocation allocation = ntfs_allocation::sparse;

Windows only: how the writer keeps NTFS from zeroing ahead of the writes. NTFS zeroes every byte between a file's valid data length and a write that lands beyond it, so that no reader sees the blocks a deleted file left there; with several writes in flight that zeroing is most of the write's cost. sparse, the default, makes the file sparse for the duration of the run, which turns those gaps into holes (read as zeros, nothing exposed), and clears the flag once the file is complete. A run that fails leaves a sparse file with holes.

valid_data sets the valid data length to the preallocation up front (SetFileValidData), which is faster still. It needs SeManageVolumePrivilege, which the request enables on the PROCESS token, and until the writes land the file exposes whatever its disk blocks held before. Where the privilege is not held, the sparse route is taken.

write_report::backend says which route ran: "+validdata", "+sparse", or neither where the file system refused sparse files too. Unix preallocates unwritten extents that read as zeros, and ignores the field.

trace

trace_buffer * trace = nullptr;

Where to record per-window timing (<blake3pp/trace.hpp>) in the forms that take a scheduler; nullptr records nothing, and the sequential forms record nothing either. The stamps carry the write side's stages: admitted, fill begun on an agent, fill done, write landed, released. Not owned: the buffer outlives the call.

hash_file_options

struct blake3pp::hash_file_options;

hash_file()'s knobs: the pipeline's, plus what shapes the hasher it constructs internally. Both structs spell the shared fields the same way so designated initializers read alike, and this one converts to file_io_options so a single options object can drive both entry points (a tool's --window/--qd/--no-direct flags land in one place).

Member functions

operator file_io_options

constexpr operator file_io_options() const noexcept;

The pipeline knobs alone, so one options object drives update_file() too.

Data members

a

arch a = arch::auto_detect;

The SIMD variant of the hasher.

window_bytes

std::size_t window_bytes = detail::default_window_bytes;

Bytes per window, 8 MiB by default; rounded down to a power-of-2 multiple of chunk_size, minimum 64 KiB.

queue_depth

unsigned queue_depth = detail::default_queue_depth;

Windows in flight at once, four by default; clamped to [2, 256]; see file_io_options.

io

io_mode io = io_mode::direct;

See file_io_options, for the small-file exception too.

submit

submit_mode submit = submit_mode::offload;

See file_io_options.

engine

engine_mode engine = engine_mode::async;

See file_io_options.

windows_api

windows_engine windows_api = windows_engine::ioring;

See file_io_options.

mode

hash_mode mode {};

Plain, keyed or key-derivation mode: hash_mode::keyed(key) or hash_mode::derive_key(context), named as hasher spells them. Extended output has no shortcut here, since hash_file() returns a 32-byte digest: take the hasher these options describe (make_hasher()), stream it with update_file() and finalize it to any length.

trace

trace_buffer * trace = nullptr;

Where to record per-window timing (<blake3pp/trace.hpp>); nullptr records nothing.

hash_mode

class blake3pp::hash_mode;

Which BLAKE3 mode a hasher built from options runs in: plain, keyed (MAC/PRF), or key derivation. One value rather than one field per mode: a hash is keyed or derived or neither, and asking for two of those does not compile. The mode is named the way hasher spells the same choice, so the two read alike:

blake3pp::hash_file_options plain{};
blake3pp::hash_file_options mac{
    .mode = blake3pp::hash_mode::keyed(my_key)};
blake3pp::hash_file_options kdf{
    .mode = blake3pp::hash_mode::derive_key("fixture v3 2026-09")};

Types

kind

enum class kind {
    plain,
    keyed,
    derive_key
};

Which of the three a mode value holds.

Member functions

hash_mode

constexpr hash_mode() noexcept=default;

Plain hashing.

which

constexpr kind which() const noexcept;

Which mode this is.

key

constexpr std::span<const std::byte, key_size> key() const noexcept;

The key, when which() is keyed.

context

std::string_view context() const noexcept;

The context string, when which() is derive_key. A view of this mode's own copy, valid as long as the mode is.

Static member functions

plain

static constexpr hash_mode plain() noexcept;

Plain hashing, named: what a default-constructed mode is.

keyed

static constexpr hash_mode keyed(std::span<const std::byte, key_size> key) noexcept;

Keyed (MAC/PRF) mode: BLAKE3's replacement for HMAC, as hasher::keyed().

Parameter
key Exactly key_size bytes, enforced by the span extent.

derive_key

static hash_mode derive_key(std::string_view context);

Key-derivation mode, as hasher::derive_key(): the input is key material and the output a subkey bound to the context, which should be hardcoded, globally unique and application-specific (see the BLAKE3 spec); it is not a secret. The context is copied, like the key: a mode outlives the expression that built it -- an options object holds one, and the senders in <blake3pp/async_io.hpp> hold a copy of the options for the whole operation -- so a borrowed string would have to outlive all of that, and nothing at the call site says it does.

Parameter
context The domain-separation string.

write_report

struct blake3pp::write_report;

What a write_file() run did.

Data members

bytes

std::uint64_t bytes = 0;

Bytes written: the size that was asked for, or what the generator produced before it stopped.

backend

std::string backend;

Which mechanism carried them, as the writer names it, in order: - the engine, in the write spelling to_string(e, io_direction::write) gives ("io_uring", "ioring", "iocp", "gcd-write", "aio", or the synchronous "pwrite", "writefile", "stdio"); - "+direct" or "+nocache" where the cache bypass engaged; - on Windows, "+sparse" or "+validdata" for how the preallocation was kept from zeroing ahead of the writes (see file_write_options::allocation); - " (inline submit)" where submit_mode::immediate was asked for; - the reason, where an asynchronous rung was asked for and refused.

So "io_uring+direct", "iocp+direct+sparse", "pwrite+direct [io_uring: ENOSYS, kernel too old]", and so on. Owned by the report, because the writer that composed it is gone by then.

Types

stream_handle

using stream_handle = int;

A stream handle: a file descriptor where the platform has those, a HANDLE on Windows.

Functions

make_hasher

hasher make_hasher(const hash_file_options &opts) noexcept;

The hasher these options describe: its SIMD variant and its mode. hash_file() builds this internally; it is public so a caller that needs a finalize form hash_file() does not have -- extended output, the seekable reader -- can stream the same options through update_file() without respelling the mode selection.

blake3pp::hash_file_options opts{
    .mode = blake3pp::hash_mode::derive_key("fixture v3 2026-09")};
blake3pp::hasher h = blake3pp::make_hasher(opts);
blake3pp::update_file(h, "seed.bin", opts);
auto stream = h.finalize_xof();
Parameter
opts The variant and mode; the pipeline knobs are ignored here.

update_file

void update_file(hasher &h, const std::filesystem::path &path, const file_io_options &opts={});

Streams a file's bytes into a hasher, as h.update() would, and returns with h open for more input or any finalize form. Files hash in sequence: after update_file(h, a); update_file(h, b); h holds the hash of a's bytes followed by b's. The hasher's mode (plain, keyed, derive_key) applies unchanged.

blake3pp::hasher h = blake3pp::hasher::derive_key("fixture v3 2026-09");
blake3pp::update_file(h, "seed.bin");
auto stream = h.finalize_xof();
Parameter
h The hasher to stream into.
path The file to read.
opts The pipeline knobs.

update_file

void update_file(hasher &h, const std::filesystem::path &path, std::error_code &ec, const file_io_options &opts={}) noexcept;

Streams a file's bytes into a hasher, reporting failure through ec instead of throwing.

Parameter
h The hasher to stream into.
path The file to read.
ec Cleared on success; the I/O error otherwise, or errc::not_enough_memory for an allocation failure.
opts The pipeline knobs.

probe_file_io

file_io_probe probe_file_io(const std::filesystem::path &path, const file_io_options &opts={});

Opens the file the way update_file() opens it for a fresh hasher, reports what that open engaged, and closes it; nothing is read. The answer is this filesystem's and this kernel's for this path and these options, which is why it takes an open to give it: a hashing call with the same options gets the same rung. A hasher part-way through a message may lose the bypass to an unaligned window grid, which this probe, asked for a fresh hasher, does not see.

Parameter
path The file to probe.
opts The pipeline knobs update_file() would be given.

probe_file_io

file_io_probe probe_file_io(const std::filesystem::path &path, std::error_code &ec, const file_io_options &opts={}) noexcept;

probe_file_io() reporting failure through ec instead of throwing.

Parameter
path The file to probe.
ec Cleared on success; the error otherwise.
opts The pipeline knobs update_file() would be given.

Returns The probe, or a default one when ec is set.

is_available

bool is_available(io_engine e) noexcept;

True if the engine is in this binary and the running kernel grants it, which is the same as saying available_io_engines() names it. There is no os_supports() beside this, as there is a cpu_supports() beside the dispatch twin: the code that asks the kernel about an engine is the backend itself, so a build without that backend has nothing to ask with.

Parameter
e Any engine.

best_io_engine

io_engine best_io_engine() noexcept;

The engine a fresh open uses on this machine, which is available_io_engines().front(). One FILE may still land lower: a filesystem can refuse the cache bypass, and a length the engine will not take asynchronously goes down a rung. probe_file_io() reports that, for a path.

compiled_io_engines

std::span<const io_engine> compiled_io_engines() noexcept;

The engines in this binary, best-first, ending with the synchronous rung the others degrade to. The list is the degradation ladder itself, read off the backend types the platform selected: each declares the engine it is and the rung it defers to. An engine appears only if its code is really here, so Windows reports the ring and the port where it has both, and the port alone where was not in the SDK.

available_io_engines

std::span<const io_engine> available_io_engines() noexcept;

The engines this kernel grants, best-first; never empty, and its front() is best_io_engine(). Answered by constructing the platform's own context with the smallest resources it will take and reading back which rung it engaged. The answer is kept only where the backend says it cannot change: a kernel without io_uring will not grow one, but a setup refused because the descriptor table was full is true only of that moment, and the next call probes again.

to_string

const char * to_string(io_engine e, io_direction d=io_direction::read) noexcept;

The engine's canonical lowercase name, the word a backend string starts with: "io_uring", "ioring", "iocp", "gcd", "aio", "pread", "readfile", "stdio", and the write spellings beside them.

Parameter
e Any engine.
d Which half; reads by default.

io_engine_from_string

std::optional<io_engine> io_engine_from_string(std::string_view name) noexcept;

Parses a name from to_string(), in either direction. Takes both spellings because the engine token of a backend string does not say which way the bytes went.

Parameter
name An engine name, as to_string() spells it.

Returns The engine, or std::nullopt for any other string.

is_async

bool is_async(io_engine e) noexcept;

True where the engine hands a transfer to the OS and collects a completion later, false for the rungs that transfer on the calling thread. These are the engines engine_mode::sync gives up. Filter compiled_io_engines() by this to name them for a build, as the tools do for their --no-async help text.

Parameter
e Any engine.

write_file

template <class Fill>
write_report write_file(const std::filesystem::path &path, std::uint64_t size, Fill &&fill, const file_write_options &opts={});

Generates a file of exactly size bytes on the calling thread, writing it through the platform's fastest path. fill is called as fill(std::span<std::byte> out, std::uint64_t offset), once per window and in file order, and must fill every byte of out. It may throw, and the file is then left as far as it got; the fill runs on this thread, so the exception propagates out of this call. The parallel_io.hpp overload runs the windows over a scheduler instead, where a throwing generator is carried by the chain rather than by the stack.

On success the file is exactly size bytes. On failure the file is left as far as it got: what lies past the last landed window is unspecified, and it is NOT truncated, because a length invented for bytes that were never produced would hide the failure.

blake3pp::write_file("seed.bin", 1 << 30,
                     [&](std::span<std::byte> out, std::uint64_t off) {
                       auto r = stream;
                       r.seek(off);
                       blake3pp::fill(r, out);
                     });
Parameter
path The file to create or truncate.
size How many bytes to generate.
fill The generator, called per window.
opts The geometry.

Returns The bytes written and the mechanism that carried them.

write_file

template <class Fill>
write_report write_file(const std::filesystem::path &path, Fill &&fill, const file_write_options &opts={});

Generates a file whose length the generator decides, on the calling thread. fill is called as std::size_t fill(std::span<std::byte> out, std::uint64_t offset), once per window and in file order, and returns how many bytes of out it produced. Anything short of the whole buffer, zero included, ends the file. It may throw, as in the length-taking form above.

Parameter
path The file to create or truncate.
fill The generator; returns the bytes it produced into each window, and a short fill ends the file.
opts The geometry.

Returns The bytes written and the mechanism that carried them.

write_file

template <class Fill>
write_report write_file(const std::filesystem::path &path, std::uint64_t size, Fill &&fill, std::error_code &ec, const file_write_options &opts={});

write_file() of a known size, reporting failure through ec.

Parameter
path The file to create or truncate.
size How many bytes to generate.
fill The generator, called per window.
ec Cleared on success; the I/O error otherwise, or errc::not_enough_memory for an allocation failure. What the generator throws propagates as thrown.
opts The geometry.

Returns What was written; bytes is 0 and backend empty when ec is set at setup, otherwise what got out before the failure.

write_file

template <class Fill>
write_report write_file(const std::filesystem::path &path, Fill &&fill, std::error_code &ec, const file_write_options &opts={});

write_file() of a generator-decided length, reporting failure through ec.

Parameter
path The file to create or truncate.
fill The generator; returns the bytes it produced into each window, and a short fill ends the file.
ec Cleared on success; the I/O error otherwise, or errc::not_enough_memory for an allocation failure. What the generator throws propagates as thrown.
opts The geometry.

Returns What was written; bytes is 0 and backend empty when ec is set at setup, otherwise what got out before the failure.

hash_file

digest hash_file(const std::filesystem::path &path, const hash_file_options &opts={});

One-shot digest of a file: a hasher shaped by opts (SIMD variant, and plain, keyed or key-derivation mode), the file streamed through it, finalized.

Parameter
path The file to hash.
opts The hasher's variant and mode, and the pipeline knobs.

hash_file

digest hash_file(const std::filesystem::path &path, std::error_code &ec, const hash_file_options &opts={}) noexcept;

One-shot digest of a file, reporting failure through ec instead of throwing.

Parameter
path The file to hash.
ec Cleared on success; the I/O error otherwise, or errc::not_enough_memory for an allocation failure.
opts The hasher's variant and mode, and the pipeline knobs.

Returns The digest, or an all-zero digest when ec is set.

standard_input

stream_handle standard_input() noexcept;

This process's standard input as a stream handle.

update_stream

std::uint64_t update_stream(hasher &h, stream_handle handle);

Streams an unseekable source -- a pipe, a socket, standard input -- into a hasher on the calling thread, until the stream ends. h keeps its mode and stays open for more input and for every finalize form, whatever it held before. A read a signal interrupts is retried, a handle in non-blocking mode is waited on rather than read as ended, and on Windows the size of each read adapts to what earlier reads returned. The handle is not closed, and its blocking mode is left as found. The scheduler form in <blake3pp/parallel_io.hpp> fans the windows out over a pool.

Parameter
h The hasher to stream into.
handle The stream to read; standard_input() for stdin.

Returns The bytes the stream delivered.

update_stream

std::uint64_t update_stream(hasher &h, stream_handle handle, std::error_code &ec) noexcept;

update_stream() reporting failure through ec instead of throwing.

Parameter
h The hasher to stream into.
handle The stream to read.
ec Cleared on success; the read error otherwise, or errc::not_enough_memory for an allocation failure.

Returns The bytes the stream delivered before the end or the failure.

update_file

template <detail::foreign_path P P>
void update_file(hasher &h, const P &path, const file_io_options &opts={});

update_file() for a path type from another filesystem library (e.g. boost::filesystem::path): anything with a native() the standard path accepts, bridged without transcoding.

Parameter
h The hasher to stream into.
path The file to read.
opts The pipeline knobs.

update_file

template <detail::foreign_path P P>
void update_file(hasher &h, const P &path, std::error_code &ec, const file_io_options &opts={});

update_file() for a foreign path type, reporting through ec.

Parameter
h The hasher to stream into.
path The file to read.
ec Cleared on success; the error otherwise.
opts The pipeline knobs.

hash_file

template <detail::foreign_path P P>
digest hash_file(const P &path, const hash_file_options &opts={});

hash_file() for a foreign path type.

Parameter
path The file to hash.
opts The hasher's variant and mode, and the pipeline knobs.

hash_file

template <detail::foreign_path P P>
digest hash_file(const P &path, std::error_code &ec, const hash_file_options &opts={});

hash_file() for a foreign path type, reporting through ec.

Parameter
path The file to hash.
ec Cleared on success; the error otherwise.
opts The hasher's variant and mode, and the pipeline knobs.

Returns The digest, or an all-zero digest when ec is set.

probe_file_io

template <detail::foreign_path P P>
file_io_probe probe_file_io(const P &path, const file_io_options &opts={});

probe_file_io() for a foreign path type.

Parameter
path The file to probe.
opts The pipeline knobs update_file() would be given.

probe_file_io

template <detail::foreign_path P P>
file_io_probe probe_file_io(const P &path, std::error_code &ec, const file_io_options &opts={});

probe_file_io() for a foreign path type, reporting through ec.

Parameter
path The file to probe.
ec Cleared on success; the error otherwise.
opts The pipeline knobs update_file() would be given.

write_file

template <detail::foreign_path P P, class Fill>
write_report write_file(const P &path, std::uint64_t size, Fill &&fill, const file_write_options &opts={});

write_file() of size bytes for a foreign path type.

Parameter
path The file to create or truncate.
size How many bytes to generate.
fill The generator, called per window.
opts The geometry.

write_file

template <detail::foreign_path P P, class Fill>
write_report write_file(const P &path, Fill &&fill, const file_write_options &opts={});

write_file() of what the generator produces for a foreign path type.

Parameter
path The file to create or truncate.
fill The generator; returns the bytes it produced into each window, and a short fill ends the file.
opts The geometry.

write_file

template <detail::foreign_path P P, class Fill>
write_report write_file(const P &path, std::uint64_t size, Fill &&fill, std::error_code &ec, const file_write_options &opts={});

write_file() of size bytes for a foreign path type, reporting through ec.

Parameter
path The file to create or truncate.
size How many bytes to generate.
fill The generator, called per window.
ec Cleared on success; the error otherwise.
opts The geometry.

write_file

template <detail::foreign_path P P, class Fill>
write_report write_file(const P &path, Fill &&fill, std::error_code &ec, const file_write_options &opts={});

write_file() of what the generator produces for a foreign path type, reporting through ec.

Parameter
path The file to create or truncate.
fill The generator; returns the bytes it produced into each window, and a short fill ends the file.
ec Cleared on success; the error otherwise.
opts The geometry.

Enumerations

io_mode

enum class io_mode {
    direct,
    buffered
};

How a file's bytes travel between the device and memory.

submit_mode

enum class submit_mode {
    offload,
    immediate
};

Where io_uring issues a request. Ignored where the platform has no such notion.

engine_mode

enum class engine_mode {
    async,
    sync
};

Whether transfers go to the platform's asynchronous engine.

windows_engine

enum class windows_engine {
    ioring,
    iocp
};

Which Windows engine asynchronous transfers use.

ntfs_allocation

enum class ntfs_allocation {
    sparse,
    valid_data
};

How a Windows write keeps NTFS from zeroing ahead of it; see file_write_options::allocation.

io_engine

enum class io_engine {
    BLAKE3PP_IO_ENGINE
};

An I/O engine: the mechanism that moves a window of bytes between the device and memory. A build carries one native engine per platform plus the synchronous rung it degrades to, except on Windows, which carries both the I/O ring and the completion port and chooses when a context opens. compiled_io_engines() lists what this binary has, available_io_engines() those the running kernel grants, and best_io_engine() the one a fresh open uses. None of the three needs a path; probe_file_io() is for what does.

The enumerators, their two name spellings and the preference order come from detail/io/io_engine.def, which documents each entry. Its line order is the ABI order and is append-only.

io_direction

enum class io_direction {
    read,
    write
};

Which half of an engine a name is being asked for. Three engines spell the two directions differently: "pread" against "pwrite", "readfile" against "writefile", and "gcd" against "gcd-write", because reads and writes take different paths through libdispatch. Pass it to to_string() where the bytes went the other way; the default is the read spelling.

Macros

BLAKE3PP_IO_ENGINE

#define BLAKE3PP_IO_ENGINE