1
0
mirror of https://github.com/ScrelliCopter/tmx2gba.git synced 2025-02-21 03:29:25 +11:00

gzip support for miniz

This commit is contained in:
2024-04-07 09:41:19 +10:00
parent a7617f3a3a
commit f8a6b976c9
4 changed files with 183 additions and 4 deletions

View File

@@ -29,10 +29,14 @@ source distribution.
#include "tmxlite/FreeFuncs.hpp"
#include "tmxlite/TileLayer.hpp"
#include "tmxlite/detail/Log.hpp"
#ifndef USE_ZLIB
# include "tmxlite/detail/gzip.hpp"
#endif
#include <pugixml.hpp>
#include <zstd.h>
#include <sstream>
#include <span>
using namespace tmx;
@@ -140,8 +144,18 @@ void TileLayer::parseBase64(const pugi::xml_node& node)
break;
case CompressionType::GZip:
#ifndef USE_ZLIB
Logger::log("Library must be built with USE_ZLIB for GZip compression", Logger::Type::Error);
return {};
{
byteData.resize(expectedSize);
const auto source = std::span(reinterpret_cast<const uint8_t*>(dataString.data()), dataString.size());
GZipReader reader;
if (!reader.OpenMemory(source) || !reader.Read(byteData) || !reader.Check())
{
LOG("Failed to decompress layer data, node skipped.", Logger::Type::Error);
return {};
}
}
break;
#endif
//[[fallthrough]];
case CompressionType::Zlib: