wavelength 1.0.0
Loading...
Searching...
No Matches
fileio.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <filesystem>
6#include <span>
7#include <string>
8#include <string_view>
9#include <vector>
10
11#include "error.h"
12
13namespace Tools::Common {
14
21std::expected<std::vector<std::uint8_t>, Error> readFile(const std::filesystem::path &path);
22
29std::expected<std::vector<std::string>, Error> readLines(const std::filesystem::path &path);
30
38std::expected<void, Error> writeLines(const std::filesystem::path &path,
39 const std::vector<std::string> &lines);
40
48std::expected<void, Error> writeFile(const std::filesystem::path &path,
49 std::span<const std::uint8_t> data);
50
58std::expected<void, Error> writeFile(const std::filesystem::path &path, std::string_view text);
59
60} // namespace Tools::Common
Code that the host tools share.
Definition byteorder.h:7
std::expected< std::vector< std::string >, Error > readLines(const std::filesystem::path &path)
Read the lines of a text file, without their line endings, skipping empty lines.
std::expected< std::vector< std::uint8_t >, Error > readFile(const std::filesystem::path &path)
Read a whole file.
std::expected< void, Error > writeFile(const std::filesystem::path &path, std::span< const std::uint8_t > data)
Replace a file with the given bytes.
std::expected< void, Error > writeLines(const std::filesystem::path &path, const std::vector< std::string > &lines)
Write lines to a text file, each ending with a line feed.
Failure returned through std::expected.
Definition error.h:17