#Yay!
Glad I could help out!
Below is my tutorial showing how to write and read compressed binary files containing any data of your choosing.
I also discuss overloading the << operator to make this process very easy.
#Tutorial Finished
For the sake of those looking on the UDN in the future,
Here is the link!
Writing and Reading Compressed Binary Files of Any Data of Your Choosing
#Sample Code
A small sample from the tutorial:
#Saving Compressed Binary
bool ControllerClass::SaveGameDataToFileCompressed(const FString& FullFilePath,
int32& SaveDataInt32,
FVector& SaveDataVector,
TArray& SaveDataRotatorArray
){
FBufferArchive ToBinary;
SaveLoadData(ToBinary,NumGemsCollected,PlayerLocation,ArrayOfRotationsOfTheStars);
//Pre Compressed Size
ClientMessage("~ PreCompressed Size ~");
ClientMessage(FString::FromInt(ToBinary.Num()));
//~~~
//~~~ Compress File ~~~
//tmp compressed data array
TArray CompressedData;
FArchiveSaveCompressedProxy Compressor =
FArchiveSaveCompressedProxy(CompressedData, ECompressionFlags::COMPRESS_ZLIB);
//Send entire binary array/archive to compressor
Compressor << ToBinary;
//send archive serialized data to binary array
Compressor.Flush();
//~~~
//Compressed Size
ClientMessage("~ Compressed Size ~");
ClientMessage(FString::FromInt(CompressedData.Num()));
if (!GFileManager) return false;
//vibes to file, return successful or not
if (FFileHelper::SaveArrayToFile(CompressedData, * FullFilePath))
{
//~~~ Free Binary Arrays ~~~
Compressor.FlushCache();
CompressedData.Empty();
ToBinary.FlushCache();
ToBinary.Empty();
//~~~ Close Buffer ~~~
ToBinary.Close();
ClientMessage("File Save Success!");
return true;
//~~~~~~~~~~~~~~~
}
else
{
//~~~ Free Binary Array ~~~
ToBinary.FlushCache();
ToBinary.Empty();
//~~~ Close Buffer ~~~
ToBinary.Close();
ClientMessage("File Could Not Be Saved!");
return false;
//~~~~~~~~~~~~~~~
}
}