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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With