对大数据使用提升filtering_streambuf
Using boost filtering_streambuf on large data
我正在尝试通过filtering_streambuf使用boost gzip压缩来压缩一些数据。然后将压缩版本写入光盘。问题是数据的大小超过 10GB,我相信字符串流空间不足。假设我可以将这些数据分解成碎片,那么使用字符串流和filtering_streambuf压缩所有数据的正确方法是什么?
我尝试将数据分解为多个部分,其中我将最大块大小设置为 std::string::max_size((/2 并将多个字符串流对象推送到filtering_streambuf对象,但这似乎不是filtering_streambuf的工作方式:)我还尝试使用bio::copy((反复复制每个数据块。我附加了一个示例代码,它不是我的确切代码(无法访问它 atm(,但除了压缩是文件流之外,想法是相同的。我提到的某些东西可能实际上有效,我只是在我的代码中有一个错误,但如果是这种情况,那么我会找到这个错误。只需要知道什么被认为是压缩大量数据的正确方法。
编辑:添加了我编写的实际代码。出于某种原因,这无法编译,因为 write 不是一个有效的函数?另外,也不能声明filtering_ostream。也许这个版本的提升已经过时了?正在写入的变量是字符。
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::gzip_compressor());
out.push(boost::iostreams::file_sink(fileName.c_str()));
out.write(&sizeof_sizet, 1);
out.write(&sizeof_int, 1);
out.write(&sizeof_double, 1);
out.write(&sizeof_Int, 1);
编辑2: 这可能就是我想要实现的目标。编译但尚未测试。
boost::iostreams::filtering_ostreambuf buf;
buf.push(boost::iostreams::gzip_compressor());
buf.push(boost::iostreams::file_sink(fileName.c_str()));
std::ostream out(&buf);
out.write(&sizeof_sizet, 1);
out.write(&sizeof_int, 1);
out.write(&sizeof_double, 1);
out.write(&sizeof_Int, 1);
使用filtering_stream
而不是filtering_streambuf
直接写入文件,以避免在完成之前将整个压缩结果缓冲在内存中。
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
boost::iostreams::filtering_ostream out;
out.push(boost::iostreams::gzip_compressor());
out.push(boost::iostreams::file_sink("test.gz"));
std::string test_string("FOO BAR BAZ....n");
out.write(test_string.c_str(), test_string.size() + 1);
}
我可以运行它,然后尝试解压缩它创建的文件:
>ls test.gz
ls: test.gz: No such file or directory
>test.exe
>ls test.gz
test.gz
>gzip -cd test.gz
FOO BAR BAZ....
相关文章:
- 将 boost 序列化对象的 asio::streambuf 表示转换为 Beast 的 DynamicBody req.body()
- Writing uin32_t to asio::streambuf
- Boost::asio::streambuf consumption() 不清空缓冲区
- c++ directx 9 textute filtering error using IDirect3DDevice9
- 字符 - 'pub' 在 std::streambuf::p ubsetbuf() 方法中是什么意思?
- 取得 streambuf/stringbuf 数据的所有权
- 将 std::string 转换为 boost::asio::streambuf
- 在发送/获取结构时使用 streambuf
- Boost ASIO ForwardIterator for streambuf
- boost::asio::streambuf::consume-注入垃圾字符
- 从boost asio streambuf读取会将字节保持在缓冲区中
- 是否可以将字符串的 streambuf 直接传递给 filebuf?
- 如何访问boost :: asio :: streamBuf输入作为字符串
- 如何复制或重复使用boost :: asio :: streambuf
- 为gzipped流编写自定义streambuf的问题
- boost::asio::streambuf-如何重用缓冲区
- BOOST :: ASIO :: StreamBuf收缩到合适
- 可以将STD :: StreamBuf的自定义实现中的异常交付给流用户
- 用 std::streambuf 包装 libcurl 以进行上传
- 正确实现 std::streambuf::overflow