Frage

This is what I have:

        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);

It throws SharpZipBaseException: Header checksum illegal and unexpected EOF exception, and data.Position is 2 by the end.

Can anyone tell me what might be the problem and how to fix it? Thanks in advance.

War es hilfreich?

Lösung

InflaterInputStream expects the data to be in the "deflate" format. You've only written two bytes of data, which isn't a valid "deflate" file.

Put it this way - if you gave WinZip some random blob of two bytes and asked it to unzip that, what would you expect it to do?

The error message is pretty clear here: your file isn't long enough (unexpected EOF exception) and starts in the wrong way for the file form (Header checksum illegal). When in doubt, always look at the error message and think about why you'd be getting that error.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top