8#include "byte_string.hpp"
9#include "architecture.hpp"
17enum class seek_whence {
23enum class access_mode {
35 write_through = 0x8000,
36 create_directories = 0x10000,
38 open_for_read = open | read,
39 open_for_read_and_write = open | read | write,
40 truncate_or_create_for_write = create_directories | open | create | truncate | write
43[[nodiscard]]
inline access_mode
operator|(access_mode lhs, access_mode rhs)
noexcept
45 return static_cast<access_mode
>(
static_cast<int>(lhs) |
static_cast<int>(rhs));
48[[nodiscard]]
inline access_mode operator&(access_mode lhs, access_mode rhs)
noexcept
50 return static_cast<access_mode
>(
static_cast<int>(lhs) &
static_cast<int>(rhs));
55[[nodiscard]]
inline bool operator>=(access_mode lhs, access_mode rhs)
noexcept
57 return (lhs & rhs) == rhs;
68 file(
URL const& location, access_mode accessMode);
74 file &operator=(
file const &other) = delete;
75 file &operator=(
file &&other) = delete;
94 void rename(
URL const &destination,
bool overwrite_existing=true);
110 return seek(0, seek_whence::current);
132 return write(
reinterpret_cast<std::byte
const *
>(data),
size, offset);
144 return write(
reinterpret_cast<std::byte
const *
>(data),
size, offset);
156 return write(bytes.data(), std::ssize(bytes), offset);
168 return write(text.data(), std::ssize(text), offset);
180 return write(text.
data(), std::ssize(text), offset);
191 return write(text.data(), std::ssize(text));
206 return read(
reinterpret_cast<std::byte *
>(data),
size, offset);
251 static void create_directory(
URL const &url,
bool hierarchy=
false);
253 static void create_directory_hierarchy(
URL const &url);
258 access_mode _access_mode;
266 file_handle _file_handle;
constexpr alignment operator|(vertical_alignment lhs, horizontal_alignment rhs) noexcept
Combine vertical and horizontal alignment.
Definition alignment.hpp:91
A File object.
Definition file.hpp:62
static size_t file_size(URL const &url)
Get the size of a file on the file system.
ssize_t get_seek()
Get the current seek location.
Definition file.hpp:109
void close()
Close the file.
ssize_t seek(ssize_t offset, seek_whence whence=seek_whence::begin)
Set the seek location.
ssize_t write(bstring const &text, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:178
ssize_t write(std::span< std::byte const > bytes, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:154
std::u8string read_u8string(ssize_t max_size=10 '000 '000)
Read the whole file as a UTF-8 string.
ssize_t read(std::byte *data, ssize_t size, ssize_t offset=-1)
Read data from a file.
void flush()
Flush and block until all data is physically written to disk.
ssize_t write(std::byte const *data, ssize_t size, ssize_t offset=-1)
Write data to a file.
ssize_t write(void const *data, ssize_t size, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:131
size_t size() const
Return the size of the file.
bstring read_bstring(ssize_t size=10 '000 '000, ssize_t offset=-1)
Read bytes from the file.
std::string read_string(ssize_t max_size=10 '000 '000)
Read the whole file as a UTF-8 string.
ssize_t write(std::string_view text)
Write data to a file.
Definition file.hpp:189
file(URL const &location, access_mode accessMode)
Open a file at location.
ssize_t write(char const *data, ssize_t size, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:143
ssize_t write(bstring_view text, ssize_t offset=-1)
Write data to a file.
Definition file.hpp:166
Definition file_mapping.hpp:19
Definition file_view.hpp:15