我需要实现一个特殊的ZLib实现,它应该在.Net和Mono下运行。 数据/字符串消息通过套接字接收,因此校验和丢失。 这是关于原始字符串数据,而不是关于文件。Zlib for Mono/.Net没有一个已知的校验和
unsigned char zlib_header[]={
// custom additional Zlib Id
'Z', // Our own ID
// The normal GZIP header
0x1f,
0x8b, // GZIP ID
0x08, // Deflated
0x00, // Flags
0, 0, 0, 0, // Timestamp,
0x00, // Extra flags
0x00, // OS identifier
// afterwards compressed data without a checksum
};
我曾尝试与解压缩和GZipStream的DeflateStream数据,但我认为GZStream失败,因为缺少校验和。我也尝试了各种补偿,但没有运气。 不使用校验和,因为无论如何都是通过套接字接收数据的 - 因此ZLib校验和会是额外的开销。 我错过了什么,或者你能解释我如何添加校验和并调用正确的库,或者我应该看看支持Mono和.Net的第三方库吗? 编辑:性能非常关键,因为这至少每秒完成一次。你会推荐我最后通过Interop使用C-Lib吗? 我现在总是收到无效数据异常,并且我认为它与错误的校验和有关。 这是我尝试没有成功使用的实际代码:
const int HeaderSize = 1;
System.IO.MemoryStream ms = new System.IO.MemoryStream(compressedBuffer, HeaderSize, compressedBuffer.Length-HeaderSize);//remove the additional Z from the header
GZipStream zipStream = new GZipStream(ms, CompressionMode.Decompress,true);
byte[] deCompressedBytes = new byte[actualBufferLength* 10];
int resultSize=zipStream.Read(deCompressedBytes, 0, actualBufferLength);//get rid of the header
UTF8Encoding enc = new UTF8Encoding();
string result = enc.GetString(deCompressedBytes, 0, resultSize);
我正在与远程位置的第三方进行整合,他们的软件中显然存在一个错误 - 他们没有正确刷新网络流。还是要谢谢你的帮助。 – weismat 2009-05-10 05:51:22