[英]Uncompressing zlib data using boost::iostreams::filtering_streambuf trouble
I'm trying to write a small class that will load the chunk data from part of a minecraft world file. 我正在尝试编写一个小类,该类将从Minecraft世界文件的一部分加载块数据。 I'm to the point where I have stored some data in a char array which was compressed with zlib and need to decompress it.
我已经将一些数据存储在用zlib压缩的char数组中,需要对其进行解压缩。
I'm trying to use the boost filtering_streambuf
to do this. 我正在尝试使用增强的
filtering_streambuf
来做到这一点。
char * rawChunk = new char[length - 1];
// Load chunk data
stringstream ssRawChunk(rawChunk);
boost::iostreams::filtering_istream in;
in.push(boost::iostreams::zlib_decompressor());
in.push(ssRawChunk);
stringstream ssOut;
boost::iostreams::copy(in, ssOut);
My problem is that rawChunk
contains null
data, so when coping data from (char*) rawChunk
to (stringstream) ssRawChunk
, it terminates at ~257 instead of the expected length 2154. 我的问题是
rawChunk
包含null
数据,因此当将数据从(char*) rawChunk
到(stringstream) ssRawChunk
,它终止于(stringstream) ssRawChunk
,而不是预期的长度2154。
Is there any way to use filtering_streambuf without stringstream to allow for null data or is there a way to stop stringstream to not terminate on null data? 有没有办法在没有stringstream的情况下使用filtering_streambuf允许空数据,或者有没有办法停止stringstream不终止于空数据?
您应该将rawChunk
存储到允许空字符的std::string
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.