Tuesday, February 12, 2008

Compression and Serialization - Part I

If you've ever serialized an object to a Stream in .NET before(and you may have done so without realising), and wondered whether there is some simple way to use compression in order to save some stream-juice, read on.

In my case stream-juice is network bandwidth. I'm serializaing objects over a NetworkStream, but, saving stream-juice should never be laughed at or overlooked, regardless of typeof(stream). If you're serializing objects to a FileStream, compression can save a significant amount of disk space(stream-juice).

The System.IO.Compression namespace(framework version 2) provides classes that makes this very easy. The trick is to hook into the framework's serialization process and compress/decompress the object being serialized/deserialized.

To be continued...

BTW: the image is evidence of life on another planet. It's encrypted though(Rijndael).

No comments:

Archive of Spooky Doom