I was hoping to see if there was an easy way for me to do this. I’m grabbing a GZip compressed file with an Http request and attempting to parse the contents into a protobuf class. Since I can’t be sure of the size of the file once decompressed, what I’ve been doing is setting the array size to be much larger than what is expected. The problem I’m encountering is that the data can only parse into the protobuf class if the Array containing the decompressed data is exactly the correct size. Is there a way to access this and then trim the array down to the correct size?
This is the code where I’m using zlib to decompress the file:
TArray<uint8> data = Response->GetContent();
TArray<uint8> decompressedData;
decompressedData.SetNum(1884); //This is the exact size of the decompressed file
UE_LOG(LogTemp, Warning, TEXT("Decompressing..."));
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
infstream.avail_in = data.Num();
infstream.next_in = (Bytef *)data.GetData();
infstream.avail_out = decompressedData.Num();
infstream.next_out = (Bytef *)decompressedData.GetData();
// the actual DE-compression work.
inflateInit2(&infstream, 16+MAX_WBITS);
int err = inflate(&infstream, Z_FINISH);
inflateEnd(&infstream);
if (err == Z_STREAM_END) {
UE_LOG(LogTemp, Warning, TEXT("decompressed!"));
} else {
UE_LOG(LogTemp, Error, TEXT("Error decompressing"));
}