diff options
| author | Maxime Coste <mawww@kakoune.org> | 2021-07-31 09:44:24 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2021-07-31 09:44:24 +1000 |
| commit | a566a22cbc4dd5c1f26256ae7bf380af93a62b14 (patch) | |
| tree | 0da34f21f970f35c9e77c1fd5d414d49c3224446 /src/file.cc | |
| parent | 914f4f8c192ca9b0742acb60869eca28702c2e7f (diff) | |
Expose BufferedWriter
Diffstat (limited to 'src/file.cc')
| -rw-r--r-- | src/file.cc | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/src/file.cc b/src/file.cc index 4c7658be..cca59393 100644 --- a/src/file.cc +++ b/src/file.cc @@ -279,43 +279,6 @@ void write_to_file(StringView filename, StringView data) write(fd, data); } -struct BufferedWriter -{ - BufferedWriter(int fd) - : m_fd{fd}, m_exception_count{std::uncaught_exceptions()} {} - - ~BufferedWriter() noexcept(false) - { - if (m_pos != 0 and m_exception_count == std::uncaught_exceptions()) - Kakoune::write(m_fd, {m_buffer, m_pos}); - } - - void write(StringView data) - { - while (not data.empty()) - { - const ByteCount length = data.length(); - const ByteCount write_len = std::min(length, size - m_pos); - memcpy(m_buffer + (int)m_pos, data.data(), (int)write_len); - m_pos += write_len; - if (m_pos == size) - { - Kakoune::write(m_fd, {m_buffer, size}); - m_pos = 0; - } - data = data.substr(write_len); - } - } - -private: - static constexpr ByteCount size = 4096; - int m_fd; - int m_exception_count; - ByteCount m_pos = 0; - char m_buffer[(int)size]; -}; - - void write_buffer_to_fd(Buffer& buffer, int fd) { auto eolformat = buffer.options()["eolformat"].get<EolFormat>(); |
