Hi David,
Streams handle reading and writing of bytes.
Write ( byte[] buffer, int offset, int count); and Read(byte[] buffer, int offset, int count); are the basic ways of doing the job.
So to compress a string convert it to an array of bytes and write it to a stream that compresses. You use System.Text.Encoding to do that kind of thing usually, ASCIIEncoding and UTF8Encoding are specific encoders you could use.
Of the top of my head you could do something like the following for a gzip blob handled in memory.
string inText = "Hello world";
byte[] textBytes = System.Text.Encoding.UTF8.GetBytes(inText);
MemoryStream rawDataStream = new MemoryStream();
ICSharpCode.SharpZipLib.GZip.GZipOutputStream gzipOut = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(rawDataStream);
gzipOut.IsStreamOwner = false;
gzipOut.Write(textBytes, 0, textBytes.Length);
gzipOut.Close();
// About here the raw data could be grabbed in the following manner to store as required.
byte[] compressed = rawDataStream.ToArray();
// This just reuses the original stream but you could get the raw bytes and make a new stream also.
rawDataStream.Seek(0,
SeekOrigin.Begin);
ICSharpCode.SharpZipLib.GZip.GZipInputStream zin = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(rawDataStream);
byte[] inBuffer = new byte[1024];
int bytesRead = zin.Read(inBuffer, 0, 1024);
string outText = System.Text.Encoding.UTF8.GetString(inBuffer, 0, bytesRead);
MessageBox.Show(outText, inText);
Hopefully that gives you a rough idea of what might be required. It might even work more or less although it has no error checking of course.
Cheers, -jr-