【发布时间】:2013-04-01 20:03:31
【问题描述】:
我正在尝试使用 boost::iostreams(1.53.0) 解压缩 HTTP 请求正文并稍后处理它。 但是当我运行以下代码时会崩溃。
try {
using namespace boost::iostreams;
ifstream file(argv[1], std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_istream in;
in.push(gzip_decompressor());
in.push(file);
std::stringstream strstream;
boost::iostreams::copy(in, strstream);
} catch (std::exception& e) {
cout << e.what() << endl;
}
崩溃发生在 gzip_decompressor(),更具体地说是在 boost 的 gzip.hpp 中的 gzip_header() { reset(); }(通过查看调用堆栈)。
我自己编译了 boost::iostreams 库,还尝试使用 macports 的 boost,但发生了同样的崩溃。我也尝试过使用gzstream library,但在构造函数中也会崩溃,更具体地说是在igzstream 的构造函数中。
我倾向于认为这是一个与 zlib 相关的问题。 我没有具体说明,我使用的是带有 Mountain Lion 和 xCode 4.6 的 MacBook Pro 来构建和运行代码。
你们之前有遇到过这样的问题吗?
【问题讨论】:
-
你能附加一个调试器并发布崩溃的堆栈跟踪吗?
-
你确认 argv[1] 确实指向一个文件吗?
-
@Zac gzip_decompressor() 崩溃与提供的 argv 无关。不过,它指向正确的文件路径。
标签: c++ boost gzip boost-iostreams compression