forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetGZipProvider.cs
More file actions
35 lines (32 loc) · 1 KB
/
NetGZipProvider.cs
File metadata and controls
35 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#if !SILVERLIGHT && !MONOTOUCH && !XBOX
using System.IO;
using System.IO.Compression;
using System.Text;
using ServiceStack.Caching;
namespace ServiceStack.Support
{
public class NetGZipProvider : IGZipProvider
{
public byte[] GZip(string text)
{
var buffer = Encoding.UTF8.GetBytes(text);
using (var ms = new MemoryStream())
using (var zipStream = new GZipStream(ms, CompressionMode.Compress))
{
zipStream.Write(buffer, 0, buffer.Length);
zipStream.Close();
return ms.ToArray();
}
}
public string GUnzip(byte[] gzBuffer)
{
using (var compressedStream = new MemoryStream(gzBuffer))
using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
{
var utf8Bytes = zipStream.ReadFully();
return Encoding.UTF8.GetString(utf8Bytes);
}
}
}
}
#endif