我正在尝试使用boost库1.67.0在Linux平台上解压缩.7z(或.xz或.lzma)文件,代码如下:
vector<T> readFromCompressedFile(string input_file_path, string output_file_path)
{
namespace io = boost::iostreams;
stringstream strstream;
ifstream file(input_file_path.c_str(), ios_base::in | ios_base::binary);
ofstream out(output_file_path, ios_base::out | ios_base::binary);
boost::iostreams::filtering_istream in;
in.push(io::lzma_decompressor());
in.push(file);
io::copy(in, out);
cout<<strstream.str()<<endl;
代码编译成功,但在复制方法中出现运行时异常(lzma_error)。
warning: GDB: Failed to set controlling terminal: Operation not permitted
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::iostreams::lzma_error> >'
what(): lzma error: iostream error
我尝试使用filtering_streambuf过滤器,但运气不佳。这段代码与gzip示例非常相似。
https://www.boost.org/doc/libs/1_67_0/libs/iostreams/doc/classes/gzip.html#examples
然而,我能够使用上述代码解压缩使用gzip压缩的文件。似乎问题仅限于LZMA算法。
有相同问题的人吗?有任何想法吗?
谢谢
xz
和lzma
是不同的压缩格式。 - TCSGrad