1 #if !SILVERLIGHT && !MONOTOUCH && !XBOX 2 using System; 3 using System.IO; 4 using System.IO.Compression; 5 using System.Text; 6 using ServiceStack.CacheAccess; 7 using ServiceStack.Text; 8 9 namespace ServiceStack.Common.Support 10 { 11 public class NetGZipProvider : IGZipProvider 12 { GZip(string text)13 public byte[] GZip(string text) 14 { 15 var buffer = Encoding.UTF8.GetBytes(text); 16 using (var ms = new MemoryStream()) 17 using (var zipStream = new GZipStream(ms, CompressionMode.Compress)) 18 { 19 zipStream.Write(buffer, 0, buffer.Length); 20 zipStream.Close(); 21 22 return ms.ToArray(); 23 } 24 } 25 GUnzip(byte[] gzBuffer)26 public string GUnzip(byte[] gzBuffer) 27 { 28 using (var compressedStream = new MemoryStream(gzBuffer)) 29 using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress)) 30 { 31 var utf8Bytes = zipStream.ReadFully(); 32 return Encoding.UTF8.GetString(utf8Bytes); 33 } 34 } 35 } 36 } 37 #endif