Files
NKC/NKC_WF/Compressor.cs
T
2021-09-17 14:51:27 +02:00

46 lines
1.4 KiB
C#

using System.IO;
using System.IO.Compression;
namespace NKC_WF
{
public static class Compressor
{
#region Public Methods
public static byte[] Compress(byte[] data)
{
MemoryStream output = new MemoryStream();
GZipStream gzip = new GZipStream(output,
CompressionMode.Compress, true);
gzip.Write(data, 0, data.Length);
gzip.Close();
return output.ToArray();
}
public static byte[] Decompress(byte[] data)
{
byte[] answ = new byte[1];
MemoryStream input = new MemoryStream();
input.Write(data, 0, data.Length);
input.Position = 0;
GZipStream gzip = new GZipStream(input,
CompressionMode.Decompress, true);
using (MemoryStream output = new MemoryStream())
{
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while (read > 0)
{
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
answ = output.ToArray();
}
return answ;
}
#endregion Public Methods
}
}