我为Gzip方法提供了此代码,但它给了我错误,而且我不知道为什么。如果有人愿意帮助消除此错误,我将不胜感激!我从1小时开始寻找解决方案,但找不到任何东西,所以这就是我在这里写的原因。
public async System.Threading.Tasks.Task<byte[]> GZip(byte[] B, bool CM)
{
await Task.Delay(10000);
try
{
if (CM)
{
byte[] buffer = null;
using (System.IO.MemoryStream MS = new System.IO.MemoryStream())
{
System.IO.Compression.GZipStream Ziped = new System.IO.Compression.GZipStream(MS, System.IO.Compression.CompressionMode.Compress, true);
Ziped.Write(B, 0, B.Length);
Ziped.Dispose();
MS.Position = 0;
buffer = new byte[(System.Convert.ToInt32(MS.Length) + 1) - 1 + 1];
MS.Read(buffer, 0, buffer.Length);
MS.Dispose();
}
return buffer;
}
else
{
byte[] array = null;
using (System.IO.MemoryStream MS = new System.IO.MemoryStream(B))
{
System.IO.Compression.GZipStream Ziped = new System.IO.Compression.GZipStream(MS, System.IO.Compression.CompressionMode.Decompress);
byte[] buffer = new byte[4 - 1];
MS.Position = (MS.Length - 5);
MS.Read(buffer, 0, 4);
int count = BitConverter.ToInt32(buffer, 0);
MS.Position = 0;
array = new byte[((count - 1) + 1) - 1 + 1];
Ziped.Read(array, 0, count);
Ziped.Dispose();
MS.Dispose();
}
return array;
}
}
catch (Exception)
{
}
}