[RawFiles]: Actually fix parse code

This commit is contained in:
FutureRave 2022-12-01 14:46:18 +00:00
parent 7778798f17
commit 1283abc4e7
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31

View File

@ -18,16 +18,16 @@ namespace Assets
return;
}
auto compressed_size = compressBound(rawFile.getBuffer().size());
asset->name = builder->getAllocator()->duplicateString(name);
asset->len = static_cast<int>(rawFile.getBuffer().size());
if (asset->len < static_cast<int>(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<char>(compressed_size);
compress2((Bytef*)(asset->buffer), &compressed_size, (const Bytef*)(rawFile.getBuffer().data()), rawFile.getBuffer().size(), Z_BEST_COMPRESSION);
asset->compressedLen = static_cast<int>(compressed_size);
asset->buffer = builder->getAllocator()->duplicateString(compressedData);
std::memcpy(const_cast<char*>(asset->buffer), compressedData.data(), compressedData.size());
asset->compressedLen = static_cast<int>(compressedData.size());
}
else
{
@ -36,8 +36,6 @@ namespace Assets
asset->compressedLen = 0;
}
asset->len = static_cast<int>(rawFile.getBuffer().size());
header->rawfile = asset;
}