Merge pull request #615 from diamante0018/develop

[RawFiles]: Actually fix parse code
This commit is contained in:
Edo 2022-12-01 14:52:09 +00:00 committed by GitHub
commit d7afbd72e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;
}