我正在尝试使用filtering_streams将一些对象的序列化压缩到array_sink或类似的设备中,在那里我可以确定压缩输出的长度,并将其复制到另一个流中,比如文件。但是,在filtering_ostream上使用ostream::tellp会导致boost抛出运行时异常。我真的不知道我做错了什么。
using namespace boost::iostreams;
char *buffer = new char[4096*255];
array_sink zipStream(buffer, 4096*255);
filtering_ostream tempOut;
tempOut.push(zlib_compressor());
tempOut.push(zipStream);
column->Serialize(tempOut); // Object::Serialize(ostream&)
tempOut.flush(); // ?
int zipSize = tempOut.tellp();
// Do stuff with zipStream...发布于 2012-05-10 21:27:29
问题是,tellp是根据底层流缓冲区pubseekoff实现的,与当前写磁头位置的偏移量为0(基本上,这只是一个糟糕的设计)。现在,这里的关键点是zlib_compressor不能与output_seekable接收器一起工作(可以在文档中看到)。这是相当自然的,因为改变写入头几乎肯定会导致损坏的数据。如果你尝试解压,你也会遇到同样的问题。
https://stackoverflow.com/questions/10533170
复制相似问题