1

我设法开始工作:

1) base 64 编码器/解码器使用 boost::archive::iterators 从 Base64 派生的编码器使用 boost throw 异常

2) 使用 boost::iostreams 的压缩器,如下所示: boost zlib 问题

所以代码看起来像这样:

#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,'=');

这似乎复制了很多数据。

有没有办法将 base64 编码器推送到 iostream 上?

4

0 回答 0