hytos / ID2.Manager / ID2.Manager.Common / Helpers / CompressHelper.cs @ 98fdb329
이력 | 보기 | 이력해설 | 다운로드 (1.31 KB)
1 | 43ceb5b3 | taeseongkim | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.IO; |
||
4 | using System.IO.Compression; |
||
5 | using System.Linq; |
||
6 | using System.Text; |
||
7 | using System.Threading.Tasks; |
||
8 | |||
9 | namespace ID2.Manager.Common.Helpers |
||
10 | { |
||
11 | public static class CompressHelper |
||
12 | { |
||
13 | public static string CompressString(string str) |
||
14 | { |
||
15 | string result = null; |
||
16 | |||
17 | using (MemoryStream outStream = new MemoryStream()) |
||
18 | { |
||
19 | using (GZipStream gzipStream = new GZipStream(outStream, CompressionMode.Compress)) |
||
20 | using (MemoryStream srcStream = new MemoryStream(Encoding.UTF8.GetBytes(str))) |
||
21 | srcStream.CopyTo(gzipStream); |
||
22 | |||
23 | result = Convert.ToBase64String(outStream.ToArray()); |
||
24 | } |
||
25 | |||
26 | return result; |
||
27 | } |
||
28 | |||
29 | public static string DecompressString(string str) |
||
30 | { |
||
31 | string result = null; |
||
32 | |||
33 | byte[] buffer = Convert.FromBase64String(str); |
||
34 | using (MemoryStream outStream = new MemoryStream()) |
||
35 | { |
||
36 | using (GZipStream gzipStream = new GZipStream(new MemoryStream(buffer), CompressionMode.Decompress)) |
||
37 | gzipStream.CopyTo(outStream); |
||
38 | |||
39 | result = Encoding.UTF8.GetString(outStream.ToArray()); |
||
40 | } |
||
41 | |||
42 | return result; |
||
43 | } |
||
44 | } |
||
45 | } |