我正在尝试解压缩使用 DEFLATE 算法压缩的文件并将其填充到vector<unsigned char>
. 从我到目前为止所做的研究来看,似乎我可以使用 aboost::iostreams::filtering_streambuf
然后使用boost::iostreams::copy()
将其放入 a 中boost::interprocess::basic_vectorstream<std::vector<unsigned char>>
,然后将底层向量从向量流中拉出。但是,我得到了大量的编译器错误,从这个开始:
/usr/include/boost/iostreams/copy.hpp: In function ‘std::streamsize boost::iostreams::detail::copy_impl(Source, Sink, std::streamsize) [with Source = boost::reference_wrapper<boost::iostreams::filtering_streambuf<boost::iostreams::input> >, Sink = boost::reference_wrapper<boost::interprocess::basic_vectorstream<std::vector<unsigned char> > >, std::streamsize = long int]’:
/usr/include/boost/iostreams/copy.hpp:245:79: instantiated from ‘std::streamsize boost::iostreams::copy(Source&, Sink&, std::streamsize, typename boost::enable_if<boost::iostreams::is_std_io<Source> >::type*, typename boost::enable_if<boost::iostreams::is_std_io<Sink> >::type*) [with Source = boost::iostreams::filtering_streambuf<boost::iostreams::input>, Sink = boost::interprocess::basic_vectorstream<std::vector<unsigned char> >, std::streamsize = long int, typename boost::enable_if<boost::iostreams::is_std_io<Source> >::type = void, typename boost::enable_if<boost::iostreams::is_std_io<Sink> >::type = void]’
ValueFileReader.cpp:92:41: instantiated from here
/usr/include/boost/iostreams/copy.hpp:178:5: error: static assertion failed: "(is_same<src_char, snk_char>::value)"
我正在使用的代码如下(为了简洁起见,缩短并执行“使用命名空间”):
using namespace boost::iostreams;
using namespace boost::interprocess;
filtering_streambuf<input> in;
std::ifstream file(filename, std::ifstream::in);
in.push(zlib_decompressor());
in.push(file);
basic_vectorstream<std::vector<unsigned char>> vectorStream;
copy(in, vectorStream);
std::vector<unsigned char> chars(vectorStream.vector());
我看过这个线程,但我不确定是否将所有内容复制到向量中,然后从向量中解压缩将是最有效的方法。
有没有更好的方法可以解决这个问题,还是我有正确的想法但代码中有一些错误?