forked from btcpayserver/btcpayserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZipUtils.cs
34 lines (32 loc) · 994 Bytes
/
ZipUtils.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace BTCPayServer
{
public class ZipUtils
{
public static byte[] Zip(string unzipped)
{
MemoryStream ms = new MemoryStream();
using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compress))
{
StreamWriter writer = new StreamWriter(gzip, Encoding.UTF8);
writer.Write(unzipped);
writer.Flush();
}
return ms.ToArray();
}
public static string Unzip(byte[] bytes)
{
MemoryStream ms = new MemoryStream(bytes);
using (GZipStream gzip = new GZipStream(ms, CompressionMode.Decompress))
{
StreamReader reader = new StreamReader(gzip, Encoding.UTF8);
var unzipped = reader.ReadToEnd();
return unzipped;
}
}
}
}