【发布时间】:2011-09-19 05:19:30
【问题描述】:
我设法集成了用于读取压缩文件的 boost Iostream API。我遵循了 boost 页面中的文档,到目前为止,我拥有以下代码:
std::stringstream outStr;
ifstream file("file.gz", ios_base::in | ios_base::binary);
try {
boost::iostreams::filtering_istreambuf in;
in.push(boost::iostreams::gzip_decompressor());
in.push(file);
boost::iostreams::copy(in, outStr);
}
catch(const boost::iostreams::gzip_error& exception) {
int error = exception.error();
if (error == boost::iostreams::gzip::zlib_error) {
//check for all error code
}
}
代码运行良好(所以请忽略上面的任何拼写错误和错误:))。
- 看起来上面的代码会在创建filtering_istreambuf时读取完整的文件并将其存储在内存中。这是真的吗,从我的调查来看,在我看来是这样吗?如果将文件读入内存,则此代码可能是大文件的问题(这就是我正在处理的问题)。
- 我当前的代码使用 gzgets API 从 zlib 中逐行读取 gzipped。有没有办法使用 boost API 逐行阅读?
【问题讨论】:
标签: c++ boost file-io gzip iostream