C++ serialize compressed?

I’ve managed to serialize data successfully. I’ve been looking into serializing data compressed but I haven’t found any good examples of doing it. I’ve serialized a struct by using the << operator and I haven’t found anything yet about compressing the data from the << operator. I’d appreciate any clear examples and explanations. Thanks!

I solved this by using FArchiveSaveCompressedProxy and FArchiveLoadCompressedProxy to save and load compressed data. You serialize normally and use the array of bytes which contains all the data to compress.

Includes are:

#include "Serialization/ArchiveSaveCompressedProxy.h"

#include "Serialization/ArchiveLoadCompressedProxy.h"

Code to compress data:

FArchiveSaveCompressedProxy Compressor(ArrayOfBytesToWriteTo, CompressionFormat);

Compressor << ArrayOfBytesToCompress;

Code to uncompress data:

FArchiveLoadCompressedProxy Uncompressor(CompressedArrayOfBytesToLoad, CompressionFormat);

Uncompressor << UncompressedArrayOfBytes;

Reference:
https://www.gamedev.net/forums/topic/693727-zlib-compression-from-ue4-to-boost/