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?
These are wrapper streams.
You can create a
GzipStreamaround any existing stream to read or write compressed data to the inner stream.