final working code is here....
public static byte[] ToGZip( this string source )
{
using( var stream = new MemoryStream( ) )
{
using( var compressor = new GZipStream( stream, CompressionMode.Compress ) )
{
var bytes = System.Text.UTF8Encoding.UTF8.GetBytes( source );
compressor.Write( bytes, 0, bytes.Length );
}
return stream.ToArray( );
}
}
public static string FromGZipToString( this byte[] source )
{
using( MemoryStream stream = new MemoryStream( ) )
{
stream.Write( source, 0, source.Length );
stream.Seek(0, SeekOrigin.Begin);
using (var gzipstream = new GZipStream(stream, CompressionMode.Decompress))
using (var reader = new StreamReader(gzipstream))
{
return reader.ReadToEnd( );
}
}
}
seekorigin code can be found here:
http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/6d207e3d-ee4b-4780-80dd-bf1a278a57cd