Merge branch 'issue/9-windows-bounded-read'

This commit is contained in:
selikhov committed 2026-12-03 09:45:15 +03:00
commit 3cade95a32
2 files changed
+88

No files matched your search

+12
View File
@@ -288,6 +288,18 @@ private:
#endif
/// Read up to `options.max_bytes` from `path` cleanly with typed errors.
///
/// The file is opened once and read through that single handle. The size is
/// checked before allocation and every chunk is checked again while reading,
/// so a file that grows after the initial size check still fails with
/// `limit_exceeded` and never returns partial contents.
///
/// Sharing: POSIX opens read-only; Windows opens with
/// `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`, so another process
/// may append, rename or replace the path while a background read is pending.
/// The read continues from the already opened handle and sees one coherent
/// version of the file (the one that was opened), not a mixture with the
/// replacement. On both platforms the path is resolved once at open time.
[[nodiscard]] inline Void::Result::Result<std::string, Void::Result::Error>
read_file_bounded(const std::filesystem::path& path,
ReadFileOptions options = {})