31 void open(
const filesystem::path& path);
43 void read_at(
void* buffer,
size_t bytes, uint64_t offset)
const;
50 void* handle_ =
nullptr;
72 void open(
const filesystem::path& tmp_path);
78 void write(
const void* buffer,
size_t bytes);
87 filesystem::path tmp_path_;
89 bool finalized_ =
false;
94void atomic_rename(
const filesystem::path& from,
const filesystem::path& to);
118 vector<vector<string_view>>
rows;
125 [[nodiscard]]
Result read(
const filesystem::path& path)
const;
134 void parse(
Result& out)
const;
CsvReader(Config c)
Constructs a reader with the given configuration.
Definition io_utilities.h:122
Result read(const filesystem::path &path) const
Reads and parses the CSV file at the given path.
Result read_string(string_view csv_text) const
Parses a CSV string already held in memory.
void close()
Closes the underlying file handle, if any.
void read_at(void *buffer, size_t bytes, uint64_t offset) const
Reads bytes from a specific offset into the provided buffer (thread-safe).
bool is_open() const
Returns true while the underlying handle is open.
FileReader(const FileReader &)=delete
void open(const filesystem::path &path)
Opens the file at the given path for reading.
uint64_t file_size() const
Returns the total size of the open file in bytes.
FileReader & operator=(FileReader &&)=delete
FileReader(FileReader &&)=delete
FileReader & operator=(const FileReader &)=delete
FileWriter(FileWriter &&)=delete
FileWriter & operator=(const FileWriter &)=delete
void write(const void *buffer, size_t bytes)
Appends the given byte range to the open file.
void abort()
Closes and deletes the tmp file, discarding any written data.
FileWriter & operator=(FileWriter &&)=delete
void open(const filesystem::path &tmp_path)
Opens a temporary file to which subsequent write() calls are appended.
bool is_open() const
Returns true while the underlying stream is open.
FileWriter(const FileWriter &)=delete
void finish_with_rename(const filesystem::path &final_path)
Closes the stream and atomically renames the tmp file to final_path.
Definition adaptive_moment_estimation.h:14
void atomic_rename(const filesystem::path &from, const filesystem::path &to)
Atomically renames a file, replacing the destination if needed.
Reader configuration: field separator and an optional per-line validator.
Definition io_utilities.h:109
function< void(string_view)> line_validator
Definition io_utilities.h:111
char separator
Definition io_utilities.h:110
Parsed CSV result; owns the source buffer that backs all row views.
Definition io_utilities.h:116
vector< vector< string_view > > rows
Definition io_utilities.h:118
string buffer
Definition io_utilities.h:117