Inflater FlushType.Sync Example?

Apr 14, 2014 at 11:39 AM
Edited Apr 14, 2014 at 11:48 AM
Hi,
I have been trying to implement Zlib Inflater with Z_SYNC_FLUSH.
This is my Code:
        private ZlibCodec decompress = new ZlibCodec(CompressionMode.Decompress);

    private byte[] DecompressSync(byte[] input)
        {
            byte[] outBytes = new byte[input.Length * 100];
            decompress.InputBuffer = input;
            decompress.NextIn = input.Length;

            decompress.OutputBuffer = outBytes;
            decompress.NextOut = outBytes.Length;
            

            int retval = 0;
            do
            {
                retval = decompress.SyncInflate();
                //retval = decompress.Inflate(FlushType.Sync);
                switch (retval)
                {
                    case Ionic.Zlib.ZlibConstants.Z_OK:
                    // completed decompression, lets copy data and get out
                        break;
                        break;
                    default:
                        Debug.WriteLine("Error= " + retval);
                        break;
                }
            } while (decompress.AvailableBytesIn > 0);
            return outBytes.Take(decompress.AvailableBytesOut).ToArray();
        }
I get IndexOutOfRangeException at decompress.SyncInflate(); or decompress.Inflate(FlushType.Sync); This is an example of its implementation in java.

I have to use Zlib SYNC_FLUSH only and cannot use any other approach (required by the RFB protocol) Can someone please provide me some example of this in C#?