2

I'm trying to write a small class that will load the chunk data from part of a minecraft world file. 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.

I'm trying to use the boost filtering_streambuf to do this.

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.

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?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982

1 Answers1

0

You should store rawChunk into std::string which allows null-characters.

zvrba
  • 24,186
  • 3
  • 55
  • 65
  • I tried using a `string` first, then putting that into a `stringstream`, but it would still terminate at the first `null` value like in my first example. I'm trying the example given in the comment above, but am having trouble. – GuitaringEgg Mar 21 '12 at 00:45