Inflater FlushType.Sync Example?

Apr 14, 2014 at 12:39 PM
Edited Apr 14, 2014 at 12:48 PM
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;
                retval = decompress.SyncInflate();
                //retval = decompress.Inflate(FlushType.Sync);
                switch (retval)
                    case Ionic.Zlib.ZlibConstants.Z_OK:
                    // completed decompression, lets copy data and get out
                        Debug.WriteLine("Error= " + retval);
            } 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#?