13 #include <boost/asio.hpp>
33 , m_filename(filename)
35 , m_stream(
std::make_shared<
std::fstream>(
40 |
std::ios_base::binary))
43 inline bool valid() {
return !!m_stream; }
45 template<
class Callback>
46 void read(
int maxSize, Callback readCallback) {
49 [stream=m_stream, maxSize, readCallback=std::move(readCallback)]() {
50 auto buf = std::vector<char>(maxSize,
'\0');
52 auto actualSize =
int{};
55 stream->read(buf.data(), maxSize);
57 actualSize = stream->gcount();
59 data =
FileContent(buf.begin(), buf.begin() + actualSize);
60 }
catch (
const std::exception &) {
67 }
else if (stream->eof()) {
75 template<
class Callback>
79 [stream=m_stream, data, writeCallback=std::move(writeCallback)]() {
81 auto buf = std::vector<char>(data.begin(), data.end());
82 stream->write(buf.data(), buf.size());
83 }
catch (
const std::exception &) {
98 std::string m_filename;
100 std::shared_ptr<std::fstream> m_stream;
118 , m_filename(filename)
132 std::string m_filename;
Definition: asio-std-file-handler.hpp:137
AsioStdFileProvider< Exec > FileProviderT
Definition: asio-std-file-handler.hpp:139
AsioStdFileHandler(Exec exec)
Constructor.
Definition: asio-std-file-handler.hpp:147
FileProviderT getProviderFor(FileDesc desc) const
Get the FileProvider for desc.
Definition: asio-std-file-handler.hpp:157
Definition: asio-std-file-handler.hpp:105
FileStreamT getStream(FileOpenMode mode) const
Get the FileStream provided by this.
Definition: asio-std-file-handler.hpp:126
AsioStdFileProvider(Exec exec, std::string filename)
Constructor.
Definition: asio-std-file-handler.hpp:116
AsioStdFileStream< Exec > FileStreamT
Definition: asio-std-file-handler.hpp:107
Definition: asio-std-file-handler.hpp:21
FileContent DataT
Definition: asio-std-file-handler.hpp:23
bool valid()
Definition: asio-std-file-handler.hpp:43
AsioStdFileStream(Exec exec, std::string filename, FileOpenMode mode)
Constructor.
Definition: asio-std-file-handler.hpp:31
void write(DataT data, Callback writeCallback)
Definition: asio-std-file-handler.hpp:76
void read(int maxSize, Callback readCallback)
Definition: asio-std-file-handler.hpp:46
Definition: file-desc.hpp:225
std::optional< std::string > name() const
Get the name for this FileDesc.
Definition: file-desc.hpp:258
Definition: location.hpp:10
AsioStdFileHandler(Exec) -> AsioStdFileHandler< Exec >
immer::flex_vector< char > FileContent
Definition: file-desc.hpp:33
FileOpenMode
Definition: file-desc.hpp:28
Definition: clientutil.hpp:217