Can I "push" a boost::iterator onto a boost iostream

525 Views Asked by At

I managed to get working:

1) a base 64 encoder/decoder using boost::archive::iterators derived from Base64 encode using boost throw exception

2) a compressor using boost::iostreams as shown here: boost zlib problem

So code the looks like this:

#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/copy.hpp>

#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/insert_linebreaks.hpp>
#include <boost/archive/iterators/remove_whitespace.hpp>

namespace io = boost::iostreams;
namespace it = boost::archive::iterators;

typedef it::transform_width< it::binary_from_base64<std::string::const_iterator >, 8, 6 > it_binary_t;
typedef it::base64_from_binary<it::transform_width<std::string::const_iterator ,6,8> > it_base64_t;


// Compress
std::stringstream binary_in;
binary_in << data...;
std::stringstream binary_out;
io::filtering_streambuf<io::output> outStream; 
outStream.push(io::zlib_compressor()); 
outStream.push(binary_out); 
io::copy(binary_in, outStream); 

// base64 Encode
std::string s = binary_out.str();
unsigned int writePaddChars = (3-s.length()%3)%3;
std::string base64(it_base64_t(s.begin()),it_base64_t(s.end()));
base64.append(writePaddChars,'=');

That seems to much copying data.

Is there a way to push the base64 encoder onto the iostream?

0

There are 0 best solutions below