Пример #1
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (count <= 0)
            {
                return;
            }

            int err;

            var b = new byte[buffer.Length];

            Array.Copy(buffer, 0, b, 0, buffer.Length);

            z.next_in       = b;
            z.next_in_index = offset;
            z.avail_in      = count;

            do
            {
                z.next_out       = this.Buffer;
                z.next_out_index = 0;
                z.avail_out      = BufferSize;

                if (this.Compressing == true)
                {
                    err = z.deflate(this._FlushMode);
                }
                else
                {
                    err = z.inflate(this._FlushMode);
                }

                if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END)
                {
                    throw new ZStreamException((this.Compressing ? "de" : "in") + "flating: " + z.msg);
                }

                this.Output.Write(this.Buffer, 0, this.BufferSize - z.avail_out);
            }while (z.avail_in > 0 || z.avail_out == 0);
        }
        public int read(byte[] b, int off, int len)
        {
            if (len == 0)
            {
                return(0);
            }
            int err;

            z.next_out       = b;
            z.next_out_index = off;
            z.avail_out      = len;
            do
            {
                if ((z.avail_in == 0) && (!nomoreinput))
                {
                    // if buffer is empty and more input is avaiable, refill it
                    z.next_in_index = 0;
                    z.avail_in      = SupportClass.ReadInput(in_Renamed, buf, 0, bufsize);                //(bufsize<z.avail_out ? bufsize : z.avail_out));
                    if (z.avail_in == -1)
                    {
                        z.avail_in  = 0;
                        nomoreinput = true;
                    }
                }
                if (compress)
                {
                    err = z.deflate(flush);
                }
                else
                {
                    err = z.inflate(flush);
                }
                if (nomoreinput && (err == zlibConst.Z_BUF_ERROR))
                {
                    return(-1);
                }
                if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END)
                {
                    throw new ZStreamException((compress?"de":"in") + "flating: " + z.msg);
                }
                if (nomoreinput && (z.avail_out == len))
                {
                    return(-1);
                }
            }while (z.avail_out == len && err == zlibConst.Z_OK);
            //System.err.print("("+(len-z.avail_out)+")");
            return(len - z.avail_out);
        }