15 std::ifstream file(resolved, std::ios::binary);
18 return std::unexpected(
Error::NotFound(std::format(
"failed to open {}", resolved.string())));
21 return std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
27 std::error_code ignored;
28 std::filesystem::create_directories(resolved.parent_path(), ignored);
30 std::ofstream file(resolved, std::ios::binary | std::ios::trunc);
33 return std::unexpected(
Error::Invalid(std::format(
"failed to open {}", resolved.string())));
36 file.write(text.data(),
static_cast<std::streamsize
>(text.size()));
39 return std::unexpected(
Error::Invalid(std::format(
"failed to write {}", resolved.string())));
std::filesystem::path ResolvePath(std::string_view relativePath)
a relative path against the base directory. If the path is already absolute, returns it as-is.
std::expected< void, Error > Status
std::expected< T, Error > Result
Result< std::string > ReadAllText(std::string_view path)
Read path (resolved via ResolvePath) into a string.
Status WriteAllText(std::string_view path, std::string_view text)
Write text to path (resolved via ResolvePath), creating its directory.
static Error Invalid(std::string detail)
static Error NotFound(std::string detail)