これらのメソッドを使用して、バイト配列を圧縮および解凍してみてください。
private static byte[] Compress(byte[] data)
{
byte[] retVal;
using (MemoryStream compressedMemoryStream = new MemoryStream())
{
DeflateStream compressStream = new DeflateStream(compressedMemoryStream, CompressionMode.Compress, true);
compressStream.Write(data, 0, data.Length);
compressStream.Close();
retVal = new byte[compressedMemoryStream.Length];
compressedMemoryStream.Position = 0L;
compressedMemoryStream.Read(retVal, 0, retVal.Length);
compressedMemoryStream.Close();
compressStream.Close();
}
return retVal;
}
private static byte[] Decompress(byte[] data)
{
byte[] retVal;
using (MemoryStream compressedMemoryStream = new MemoryStream())
{
compressedMemoryStream.Write(data, 0, data.Length);
compressedMemoryStream.Position = 0L;
MemoryStream decompressedMemoryStream = new MemoryStream();
DeflateStream decompressStream = new DeflateStream(compressedMemoryStream, CompressionMode.Decompress);
decompressStream.CopyTo(decompressedMemoryStream);
retVal = new byte[decompressedMemoryStream.Length];
decompressedMemoryStream.Position = 0L;
decompressedMemoryStream.Read(retVal, 0, retVal.Length);
compressedMemoryStream.Close();
decompressedMemoryStream.Close();
decompressStream.Close();
}
return retVal;
}