How to get binary data from boost :: asio :: streambuf

How can I clear data from streambuf to file? I tried

read(*socket_, streamBuf, boost::asio::transfer_at_least(694784))
std::istream is(&streamBuf);
std::ofstream outfile;
outfile.open ("test.exe");
is >> outfile;
outfile.close()

but it didn’t work. Any clue how to do this?

+3
source share
1 answer

You can try it buffer_cast. Here is an example:

boost::asio::streambuf buf;
size_t bytes = read( *socket_, buf, boost::asio::transfer_at_least(694784) );
buf.commit( bytes );

std::ofstream outfile( "test.exe" );
outfile << boost::asio::buffer_cast<const char*>( buf.data() );
+4
source

Source: https://habr.com/ru/post/1789954/


All Articles