markus / ConvertService / ServiceController / Markus.Service.Extensions / Helper / Compress.cs @ 3035602a
이력 | 보기 | 이력해설 | 다운로드 (1.25 KB)
1 | 5c387707 | semi | 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 Markus.Service.Helper |
||
10 | { |
||
11 | public static class CompressHelper |
||
12 | { |
||
13 | public static Byte[] Compress(Byte[] buffer) |
||
14 | { |
||
15 | Byte[] compressedByte; |
||
16 | using (MemoryStream ms = new MemoryStream()) |
||
17 | { |
||
18 | using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress)) |
||
19 | { |
||
20 | ds.Write(buffer, 0, buffer.Length); |
||
21 | } |
||
22 | |||
23 | compressedByte = ms.ToArray(); |
||
24 | } |
||
25 | return compressedByte; |
||
26 | } |
||
27 | public static Byte[] Decompress(Byte[] buffer) |
||
28 | { |
||
29 | MemoryStream resultStream = new MemoryStream(); |
||
30 | |||
31 | using (MemoryStream ms = new MemoryStream(buffer)) |
||
32 | { |
||
33 | using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress)) |
||
34 | { |
||
35 | ds.CopyTo(resultStream); |
||
36 | ds.Close(); |
||
37 | } |
||
38 | } |
||
39 | Byte[] decompressedByte = resultStream.ToArray(); |
||
40 | resultStream.Dispose(); |
||
41 | return decompressedByte; |
||
42 | } |
||
43 | } |
||
44 | } |