ICS中的ICSharpCode… InflaterInputStream的反向动作
我正在使用ICSharpCode.SharpZipLib.dll来压缩和解压缩数据。
我有以下代码执行数据膨胀:
public static byte[] ZLibDecompress(byte[] zLibCompressedBuffer)
{
byte[] resBuffer = null;
MemoryStream mInStream = new MemoryStream(zLibCompressedBuffer);
MemoryStream mOutStream = new MemoryStream(zLibCompressedBuffer.Length);
InflaterInputStream infStream = new InflaterInputStream(mInStream);
mInStream.Position = 0;
try
{
byte[] tmpBuffer = new byte[zLibCompressedBuffer.Length];
int read = 0;
do
{
read = infStream.Read(tmpBuffer, 0, tmpBuffer.Length);
if (read > 0)
mOutStream.Write(tmpBuffer, 0, read);
} while (read > 0);
resBuffer = mOutStream.ToArray();
}
finally
{
infStream.Close();
mInStream.Close();
mOutStream.Close();
}
return resBuffer;
}
这段代码实际上有效,现在我想压缩结果。
所以这是我的代码:
public static byte[] ZLibCompress(byte[] buffer)
{
byte[] resBuffer = null;
MemoryStream mOutStream = new MemoryStream(buffer.Length);
DeflaterOutputStream defStream = new DeflaterOutputStream(mOutStream);
try
{
defStream.Write(buffer, 0, buffer.Length);
defStream.Flush();
defStream.Finish();
resBuffer = mOutStream.ToArray();
}
finally
{
defStream.Close();
mOutStream.Close();
}
return resBuffer;
}
但是两个函数的两个结果数组并不相等:
byte[] unCompBuffer = ZipUtils.ZLibDecompress(zLibBuffer);
byte[] compBuffer = ZipUtils.ZLibCompress(unCompBuffer);
bool eq = compBuffer.SequenceEqual(zLibBuffer);
eq是假的。
有任何想法吗?
谢谢你提前。
没有找到相关结果
已邀请:
1 个回复
肺鬼耙扮群