51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
|
|
namespace CPF.ReoGrid.Utility
|
|
{
|
|
public class ZipStreamHelper
|
|
{
|
|
public static byte[] Decompress(byte[] zippedData)
|
|
{
|
|
byte[] result;
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
{
|
|
using (MemoryStream memoryStream2 = new MemoryStream(zippedData))
|
|
{
|
|
using (GZipStream gzipStream = new GZipStream(memoryStream2, CompressionMode.Decompress))
|
|
{
|
|
byte[] array = new byte[4096];
|
|
int count;
|
|
while ((count = gzipStream.Read(array, 0, array.Length)) > 0)
|
|
{
|
|
memoryStream.Write(array, 0, count);
|
|
}
|
|
result = memoryStream.ToArray();
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static byte[] Compress(byte[] plainData)
|
|
{
|
|
bool flag = plainData == null;
|
|
if (flag)
|
|
{
|
|
throw new ArgumentNullException("Tried to compress null byte array - can't get smaller than zero!");
|
|
}
|
|
byte[] result = null;
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
{
|
|
using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
|
|
{
|
|
gzipStream.Write(plainData, 0, plainData.Length);
|
|
}
|
|
result = memoryStream.ToArray();
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|