25 if (buffer_has_write_data())
35 if (buffer.
index == read_buffer_size)
63 const size_t asked = std::min(destination.buffer.size,
size_t(size - done));
64 const size_t received = pread(destination.buffer.data, asked, start + done);
67 reading_past_end_of_file();
69 destination.pwrite(destination.buffer.data, received, start + done);
70 done += int64_t(received);
85 for (int64_t current = from; current < until;)
87 const size_t half_buffer_size = Buffered_File::buffer.size / 2;
89 const size_t n0 = pread
91 destination.buffer.data,
100 const size_t n = destination.pread
102 destination.buffer.data + half_buffer_size + n1,
117 reading_past_end_of_file();
119 const int diff = std::memcmp
121 destination.buffer.data,
122 destination.buffer.data + half_buffer_size,
129 current += int64_t(n0);
139 compact_write<size_t>(s.size());
147 const size_t size = compact_read<size_t>();
148 std::string s(size, 0);
158 const int64_t size = compact_read<int64_t>();
159 if (size > 0 && size < max_size)
161 s.resize(
size_t(size));
171 if (buffer_has_write_data())
174 try { write_buffer(); }
catch (...) {}
182 Async_Reader reader(*
this, blob.get_position(), blob.get_end());
183 std::string result(
size_t(blob.get_size()), 0);
184 reader.
read(result.data(), result.size());
186 reading_past_end_of_file();
size_t read(char *buffer, size_t capacity)
bool is_end_of_file() const
virtual void copy_to(Buffered_File &destination, int64_t start, int64_t size) const
void set_position(int64_t position)
virtual bool equal_to(Buffered_File &destination, int64_t from, int64_t until) const
size_t read_data(char *data, const size_t n)
void write_string(const std::string &s)
std::string read_string()
void destructor_flush() noexcept
void write_data(const char *data, size_t n)
std::string safe_read_string(int64_t max_size)
Buffered_File(Open_Mode mode)
static void write(const char *message) noexcept
void sequential_seek(int64_t new_position)
@ shared_write
like write_existing_or_create_new, but does not lock the file, and does not fail if locked
@ read_existing
fails if does not exist