如何解压字节数组数据?
一。
public byte[] Unzip(byte[] data)
{
MemoryStream mstream = new MemoryStream(data);
ZipInputStream zipInputStream = new ZipInputStream(mstream);
byte[] byteUncompressed = new byte[zipInputStream.Length];
zipInputStream.Read(byteUncompressed, 0, (int)byteUncompressed.Length);
zipInputStream.Close();
mstream.Close();
return byteUncompressed;
}
二。
public static byte[] DeCompression(byte[] compressedByte)
{
MemoryStream ms = new MemoryStream();
byte[] writeData = new byte[4096];
using (Stream s2 = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new MemoryStream(compressedByte)))
{
while (true)
{
int size = s2.Read(writeData, 0, writeData.Length);
if (size > 0)
{
ms.Write(writeData, 0, size);
}
else
{
break;
}
}
s2.Close();
}
return ms.ToArray();
}
网上找了一堆相关代码,都是有问题。
不是什么幻数,就是未知块等错误,给看看有什么方法解决。