工作中,有时候需要直接截获网络数据进行解压,SharpZip中的ZipInputStream不适用此场合,于是使用InflaterInputStream代替:
string strStream = string.Empty;
MemoryStream sourceStream = new MemoryStream();
sourceStream.Write(byte_zipCode, 0, byte_zipCode.Length);
byte[] buffer = new byte[2048];
sourceStream.Position = 0;
InflaterInputStream ZipCompession = new InflaterInputStream(sourceStream);
while(true)
{
int iCount = ZipCompession.Read(buffer, 0, buffer.Length);
if (iCount == 0)
{
break;
}
}
strStream = Encoding.Default.GetString(buffer).Trim();
写个小测试工具既解决了麻烦,又留下铁证找开发切磋^_^