btcpayserver/BTCPayServer.Common/ZipUtils.cs

35 lines
994 B
C#
Raw Normal View History

2017-09-13 08:47:34 +02:00
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace BTCPayServer
{
2019-05-24 11:42:22 +02:00
public class ZipUtils
2017-09-13 08:47:34 +02:00
{
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();
}
2017-09-13 08:47:34 +02:00
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;
}
}
}
2017-09-13 08:47:34 +02:00
}