Exemple #1
0
        public override int Compress(byte[] buf, int start, int len)
        {
            stream.next_in       = buf;
            stream.next_in_index = start;
            stream.avail_in      = len - start;
            int status;
            int outputlen = start;

            do
            {
                stream.next_out       = tmpbuf;
                stream.next_out_index = 0;
                stream.avail_out      = BUF_SIZE;
                status = stream.Deflate(JZlib.Z_PARTIAL_FLUSH);
                switch (status)
                {
                case JZlib.Z_OK:
                {
                    System.Array.Copy(tmpbuf, 0, buf, outputlen, BUF_SIZE - stream.avail_out);
                    outputlen += (BUF_SIZE - stream.avail_out);
                    break;
                }

                default:
                {
                    System.Console.Error.WriteLine("compress: deflate returnd " + status);
                    break;
                }
                }
            }while (stream.avail_out == 0);
            return(outputlen);
        }
        public override byte[] Compress(byte[] buf, int start, int[] len)
        {
            stream.next_in       = buf;
            stream.next_in_index = start;
            stream.avail_in      = len[0] - start;
            int status;
            int outputlen = start;

            byte[] outputbuf = buf;
            int    tmp       = 0;

            do
            {
                stream.next_out       = tmpbuf;
                stream.next_out_index = 0;
                stream.avail_out      = BUF_SIZE;
                status = stream.Deflate(JZlib.Z_PARTIAL_FLUSH);
                switch (status)
                {
                case JZlib.Z_OK:
                {
                    tmp = BUF_SIZE - stream.avail_out;
                    if (outputbuf.Length < outputlen + tmp + buffer_margin)
                    {
                        byte[] foo = new byte[(outputlen + tmp + buffer_margin) * 2];
                        System.Array.Copy(outputbuf, 0, foo, 0, outputbuf.Length);
                        outputbuf = foo;
                    }
                    System.Array.Copy(tmpbuf, 0, outputbuf, outputlen, tmp);
                    outputlen += tmp;
                    break;
                }

                default:
                {
                    System.Console.Error.WriteLine("compress: deflate returnd " + status);
                    break;
                }
                }
            }while (stream.avail_out == 0);
            len[0] = outputlen;
            return(outputbuf);
        }