Skip to main content
 首页 » 编程设计

c#之InflaterInputStream.Read 导致错误

2024年02月20日20dudu

这是我的:

        byte[] buff = new byte[1]; 
        byte[] buffer = { 10, 20, 30, 40 }; 
        Stream data = new MemoryStream();             
        data.Write(buffer, 2, 2); 
        data.Position = 0; 
        InflaterInputStream _inflater;             
        _inflater = new InflaterInputStream(data); 
        int count = _inflater.Read(buff, 0, 1); 

抛出SharpZipBaseException: Header checksum illegal and unexpected EOF异常,最后data.Position为2

谁能告诉我可能是什么问题以及如何解决它?提前致谢。

请您参考如下方法:

InflaterInputStream 期望数据为“deflate”格式。您只写入了两个字节的数据,这不是有效的“压缩”文件。

这样说 - 如果您给 WinZip 一些随机的两个字节的 blob 并要求它解压缩,您希望它做什么?

此处的错误消息非常清楚:您的文件不够长(意外的 EOF 异常)并且以错误的方式开始文件格式( header 校验和非法)。如有疑问,请始终查看错误消息并思考为什么您会收到该错误。