I use C# SharpZipLib for compression. I create a stream object of type InflaterInputStream. When the .Net BinaryFormatter deserializes this stream it calls the InflaterInputStream's Read(byte[ buffer, int offset, int count) method. The problem I encounter is that sometimes the BinaryFormatter passes a zero length buffer in the Read method. When this happens an Exception with message"Don't know what to do" is thrown by the method. Here is the code:
publicoverrideintRead(byte[ b,int off,int len){for(;;){int count;try{
count = inf.Inflate(b, off, len);}catch(Exception e){thrownewSharpZipBaseException(e.ToString());}if(count >0){return count;}if(inf.IsNeedingDictionary){thrownewSharpZipBaseException("Need a dictionary");}elseif(inf.IsFinished){return0;}elseif(inf.IsNeedingInput){Fill();}else{thrownewInvalidOperationException("Don't know what to do");}}}
Should there be an "if" code block on top of the method so that it checks first if byte is zero? If it's zero then it would just return 0 something like:
publicoverrideintRead(byte[ b,int off,int len){//empty bytes should not go into Inflate method.if(b.Length==0){return0;}