bool GenericCompressedData::decompress(uint8_t* destination, size_t bufferSize, size_t* decompressedByteCount) { if (decompressedByteCount) *decompressedByteCount = 0; z_stream stream; memset(&stream, 0, sizeof(stream)); stream.zalloc = zAlloc; stream.zfree = zFree; stream.data_type = Z_BINARY; stream.opaque = Z_NULL; stream.next_out = destination; stream.avail_out = bufferSize; stream.next_in = m_data; stream.avail_in = compressedSize(); if (inflateInit(&stream) != Z_OK) { ASSERT_NOT_REACHED(); return false; } int inflateResult = inflate(&stream, Z_FINISH); inflateEnd(&stream); ASSERT(stream.total_out <= bufferSize); if (decompressedByteCount) *decompressedByteCount = stream.total_out; if (inflateResult != Z_STREAM_END) { ASSERT_NOT_REACHED(); return false; } return true; }
int cartesianIndex( const int compressedElementIndex ) const { assert( compressedElementIndex >= 0 && compressedElementIndex < compressedSize() ); return grid_.globalCell()[ compressedElementIndex ]; }