diff --git a/src/Components/Modules/AssetInterfaces/IRawFile.cpp b/src/Components/Modules/AssetInterfaces/IRawFile.cpp index 603a4d7c..f9e7e69c 100644 --- a/src/Components/Modules/AssetInterfaces/IRawFile.cpp +++ b/src/Components/Modules/AssetInterfaces/IRawFile.cpp @@ -18,16 +18,16 @@ namespace Assets return; } - auto compressed_size = compressBound(rawFile.getBuffer().size()); - asset->name = builder->getAllocator()->duplicateString(name); asset->len = static_cast(rawFile.getBuffer().size()); - if (asset->len < static_cast(compressed_size)) + const auto compressedData = Utils::Compression::ZLib::Compress(rawFile.getBuffer()); + // Only save the compressed buffer if we gained space + if (compressedData.size() < rawFile.getBuffer().size()) { - asset->buffer = builder->getAllocator()->allocateArray(compressed_size); - compress2((Bytef*)(asset->buffer), &compressed_size, (const Bytef*)(rawFile.getBuffer().data()), rawFile.getBuffer().size(), Z_BEST_COMPRESSION); - asset->compressedLen = static_cast(compressed_size); + asset->buffer = builder->getAllocator()->duplicateString(compressedData); + std::memcpy(const_cast(asset->buffer), compressedData.data(), compressedData.size()); + asset->compressedLen = static_cast(compressedData.size()); } else { @@ -36,8 +36,6 @@ namespace Assets asset->compressedLen = 0; } - asset->len = static_cast(rawFile.getBuffer().size()); - header->rawfile = asset; }