Hello,
I am looking for some recommendations about compressing data in .NET, aside from using the GZipStream class. I am looking for fast and high compression of byte arrays to be able to send them via tcp.
Thank you.
Hello,
I am looking for some recommendations about compressing data in .NET, aside from using the GZipStream class. I am looking for fast and high compression of byte arrays to be able to send them via tcp.
Thank you.
SharpZipLib is an alternative. It's said that it's written more thoughtfully than the framework library GZipStream
If you are compressing data, then you might look at high-density serialization, rather than compression. Something like protobuf. There are a few C# implementations here. For existing objects, protobuf-net is IMO the simplest to implement (disclosure: I'm the author - but it is free etc). You just serialize to the stream, or if you want a byte[]
, a separate MemoryStream
.
For continuous use over a socket (rather than the discreet request/response of HTTP), I would suggest looking at the Serializer.SerializeWithLengthPrefix
/ Serializer.DeserializeWithLengthPrefix
operations (protobuf doesn't itself include a terminator, so a length-prefix is necessary to handle separate messages).
.NET 3+ has built-in Zip support now, with the ZipPackage class.
LZMA is supposed to be among the best for compression. 7-Zip is a public domain SDK implementation of LZMA, freely downloadable here:
Wikipedia on compression algorithms:
7z's LZMA algorithm reaches a higher compression ratio than RAR, except for "multimedia" files like .wav and .bmp files where RAR uses specialized routines that outperform LZMA.[7] Other free compression software such as NanoZip and FreeArc usually outperform WinRAR.[8]