Reputation: 7102
I am writing a simple client-server application, and looking the MSDN docs, I came across some interesting stream types...
http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx
Apparently, there is such a thing as a compressed stream! Naturally, this is very attractive, considering we are dealing with networking. However, most unfortunately, TcpClient.GetStream() only returns a NetworkStream -- Not any form of compressed stream.
I was wondering if it is possible to wire a compressed stream to redirect to the NetworkStream, meaning I could write the the compressed stream and that stream would write its compressed output to my NetworkStream. I'd also need to know how to do the reverse, get a compressed stream to read from a NetworkStream.
On the side, which do you recommend I do -- Which offers the fastest compression, GZip or Deflate? And what is the difference in compression between the two?
Upvotes: 1
Views: 2079
Reputation: 3299
Checkout networkComms.net, an open source network communication library which includes the option of using many different types of compression when sending data. All you have to do is change the NetworkComms.DefaultCompressor property. You can choose from:
In order to to support these plus any further number of different compression methods networkComms.net uses a basic networkStream at the base and just makes sure everything has been compressed before it reaches that point.
Upvotes: 0
Reputation: 888017
These are wrapper streams.
You can create a GzipStream
around any existing stream to read or write compressed data to the inner stream.
Upvotes: 5