~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ServiceStack/src/ServiceStack.Common/Support/NetDeflateProvider.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 NetDeflateProvider : IDeflateProvider
 
12
    {
 
13
        public byte[] Deflate(string text)
 
14
        {
 
15
            var buffer = Encoding.UTF8.GetBytes(text);
 
16
            using(var ms = new MemoryStream())
 
17
            using (var zipStream = new DeflateStream(ms, CompressionMode.Compress))
 
18
            {
 
19
                zipStream.Write(buffer, 0, buffer.Length);
 
20
                zipStream.Close();
 
21
 
 
22
                return ms.ToArray();
 
23
            }
 
24
        }
 
25
 
 
26
        public string Inflate(byte[] gzBuffer)
 
27
        {
 
28
            using (var compressedStream = new MemoryStream(gzBuffer))
 
29
            using (var zipStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
 
30
            {
 
31
                var utf8Bytes = zipStream.ReadFully();
 
32
                return Encoding.UTF8.GetString(utf8Bytes);
 
33
            }
 
34
        }
 
35
 
 
36
    }
 
37
}
 
38
#endif
 
 
b'\\ No newline at end of file'