I've found hundreds of solutions about compressing files on disk, but in my case I want to compress/decompress data placed in memory, without any loss.

For example, is there a way of compressing PropertyBag contents on the fly? The purpose is to transfer through winsock less bytes than the original (1MB of the data I am talking can be less than 40kb in zip).