feat(System): bounded Windows read through one handle, with coverage (#9)

The Windows read_file_bounded path was implemented together with #3 using
a single CreateFileW handle. This adds the #9 acceptance coverage and
documents the contract:

- The size is checked before allocation and every chunk is re-checked, so
  growth after the initial size check still fails with limit_exceeded and
  never returns partial contents.
- Windows shares read/write/delete, so another process may append,
  rename or replace the path while a background read is pending; the
  read continues from the opened handle and sees one coherent version.
- Tests: empty, binary, Unicode path, exact limit, over limit before
  reading, and (POSIX) a stream that grows past the limit mid-read.
This commit is contained in:
selikhov committed 2026-12-03 09:45:14 +03:00
1 parent 51ceb081ac
commit f3176c2b54
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 = {})