How to get binary data from boost::asio::streambuf
How can I flush data from streambuf to file? I've tried
read(*socket_, streamBuf, boost::asio::transfer_at_least(694784))
std::istream is(&streamBuf);
std::ofstream out开发者_运维问答file;
outfile.open ("test.exe");
is >> outfile;
outfile.close()
but that didn't work. Any clue how to do that?
You might try a 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() );
精彩评论