Example #1
0
        public override byte[] Uncompress(byte[] buffer, int start, int[] length)
        {
            int inflated_end = 0;

            stream.next_in       = buffer;
            stream.next_in_index = start;
            stream.avail_in      = length[0];
            while (true)
            {
                stream.next_out       = tmpbuf;
                stream.next_out_index = 0;
                stream.avail_out      = BUF_SIZE;
                int status = stream.Inflate(JZlib.Z_PARTIAL_FLUSH);
                switch (status)
                {
                case JZlib.Z_OK:
                {
                    if (inflated_buf.Length < inflated_end + BUF_SIZE - stream.avail_out)
                    {
                        byte[] foo = new byte[inflated_end + BUF_SIZE - stream.avail_out];
                        System.Array.Copy(inflated_buf, 0, foo, 0, inflated_end);
                        inflated_buf = foo;
                    }
                    System.Array.Copy(tmpbuf, 0, inflated_buf, inflated_end, BUF_SIZE - stream.avail_out
                                      );
                    inflated_end += (BUF_SIZE - stream.avail_out);
                    length[0]     = inflated_end;
                    break;
                }

                case JZlib.Z_BUF_ERROR:
                {
                    if (inflated_end > buffer.Length - start)
                    {
                        byte[] foo = new byte[inflated_end + start];
                        System.Array.Copy(buffer, 0, foo, 0, start);
                        System.Array.Copy(inflated_buf, 0, foo, start, inflated_end);
                        buffer = foo;
                    }
                    else
                    {
                        System.Array.Copy(inflated_buf, 0, buffer, start, inflated_end);
                    }
                    length[0] = inflated_end;
                    return(buffer);
                }

                default:
                {
                    System.Console.Error.WriteLine("uncompress: inflate returnd " + status);
                    return(null);

                    break;
                }
                }
            }
        }