C ++ Boost和Lzma解压缩 [英] C++ Boost and Lzma decompression
问题描述
我正在尝试使用
- 在Linux平台上提升库1.67.0
具有以下代码:
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)
The code compiles, but I get a runtime exception (lzma_error) raised by the copy method
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
我很幸运地尝试使用filter_streambuf过滤器,该过滤器的代码块与gzip示例的代码非常相似
I tried with no luck to use a filtering_streambuf filter with a chunk of code very similar to the one for the gzip example
https://www .boost.org/doc/libs/1_67_0/libs/iostreams/doc/classes/gzip.html#examples
但是,我能够解压缩使用gzip和上述代码压缩的文件. 看来问题仅限于LZMA算法.
However I am able to decompress a file compressed with gzip and with the above code. It seems that the issue is limited to LZMA algorithm.
有人遇到同样的问题吗?有什么想法吗?
Anyone with the same issue? Any ideas?
谢谢
推荐答案
我可以确认相同的问题.
I can confirm the same issue.
使用其他工具解压缩lzma文件没有问题.可能存在版本控制问题,或者可能存在错误.这是代码的清理版本,没有太多的干扰,消除了一些可疑的样式(using namespace std
),并尝试获取更多错误信息:
No problem decompressing the lzma file using other tools. There might be a versioning thing at play, or maybe there's a bug. Here's a cleaned up version of the code that doesn't have as much noise, irons out some dubious style (using namespace std
) and tries to get more error information:
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/lzma.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <fstream>
#include <iostream>
namespace io = boost::iostreams;
void foo(std::string input_file_path, std::string output_file_path) {
namespace io = boost::iostreams;
std::ifstream file(input_file_path, std::ios::binary);
std::ofstream out(output_file_path, std::ios::binary);
boost::iostreams::filtering_istreambuf in;
in.push(io::lzma_decompressor());
in.push(file);
try {
io::copy(in, out);
} catch(io::lzma_error const& e) {
std::cout << boost::diagnostic_information(e, true);
std::cout << e.code() << ": " << e.code().message() << "\n";
} catch(boost::exception const& e) {
std::cout << boost::diagnostic_information(e, true);
}
}
int main() {
foo("test.cpp.lzma", "output.txt");
}
在我的系统上,我已经验证了测试程序和/usr/bin/lzma都链接到该库的完全相同的版本,因此此时似乎不太可能出现版本问题:
On my system I have verified that that both the test program and /usr/bin/lzma link to the exact same version of the library, so versioning problems seem pretty unlikely at this point:
我认为应该在上游报告此问题(在 boost Trac ,邮件列表或 github问题)
I think the problem should be reported upstream (at the boost Trac, mailing list or github issue)
这篇关于C ++ Boost和Lzma解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!