Skip to content

Commit

Permalink
enable zlib for all compression modes
Browse files Browse the repository at this point in the history
  • Loading branch information
ldornbusch committed Feb 12, 2023
1 parent fcc4979 commit 4d61d98
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tmxlite/src/FreeFuncs.cpp
Expand Up @@ -24,8 +24,12 @@ and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any
source distribution.
*********************************************************************/
#ifdef USE_ZIP_LIB
#include <zlib.h>
#else
#include "miniz.h"
#endif // ZIP_LIB_USED

#include "miniz.h"
#include <tmxlite/FreeFuncs.hpp>
#include <tmxlite/detail/Log.hpp>

Expand All @@ -50,12 +54,17 @@ bool tmx::decompress(const char* source, std::vector<unsigned char>& dest, std::
stream.next_out = (Bytef*)byteArray.data();
stream.avail_out = static_cast<unsigned int>(expectedSize);

//we'd prefer to use inflateInit2 but it appears
//we'd prefer to use inflateInit2 but it appears
//to be incorrect in miniz. This is fine for zlib
//compressed data, but gzip compressed streams
//will fail to inflate. IMO still preferable to
//trying to build/link zlib
if (inflateInit(&stream/*, 15 + 32*/) != Z_OK)
#ifdef USE_ZIP_LIB
if (inflateInit2(&stream, 15 + 32) != Z_OK)
#else
if (inflateInit(&stream) != Z_OK)
#endif // ZIP_LIB_USED

{
LOG("inflate init failed", Logger::Type::Error);
return false;
Expand Down Expand Up @@ -112,4 +121,4 @@ bool tmx::decompress(const char* source, std::vector<unsigned char>& dest, std::
dest.insert(dest.begin(), byteArray.begin(), byteArray.end());

return true;
}
}

0 comments on commit 4d61d98

Please sign in to comment.