// Write compressed to network stream example - not compiled or tested.
using(NetworkStream ns = new NetworkStream(socket))
using ( GZipStream gz = new GZipStream(, CompressionMode.Compress, true) )
{
gz.Write(...); // Write bytes to compressed stream, which will
in-turn send the compressed bytes to the network stream.
// other work..
gz.Flush();
}
One issue with sending compressed streams over the network like this is you
don't know the stream size before hand so you can't prepend len bytes so the
other side know how many bytes to expect. So you either have to use some
kind of unique delimiter sequence (which could have some issues) or compress
the stream before hand and send that (which brings you back to same issue).
Small-to-Medium files could be compressed to a MemoryStream as long as RAM
is not an issue (but that is an unknown in most cases and probably not
something to count on).
--
William Stacey [MVP]
"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:e4*************@TK2MSFTNGP14.phx.gbl...
I used use SharpZipLib to compress files in disk.
But now I want to compress stream into another stream in memory(the stream
not associated with disk file)
My pseudo is:
Stream InputStream;
Stream OutPutStream;
DataSet1.WriteXml(InputStream);
OutPutStream=ZipStream(InputStream);
How can I do that?