示例#1
0
        public virtual void Finish()
        {
            do
            {
                z.next_out       = buf;
                z.next_out_index = 0;
                z.avail_out      = buf.Length;

                int err = compress
                                        ?       z.deflate(JZlib.Z_FINISH)
                                        :       z.inflate(JZlib.Z_FINISH);

                if (err != JZlib.Z_STREAM_END && err != JZlib.Z_OK)
                {
                    throw new IOException((compress ? "de" : "in") + "flating: " + z.msg);
                }

                int count = buf.Length - z.avail_out;
                if (count > 0)
                {
                    output.Write(buf, 0, count);
                }
            }while (z.avail_in > 0 || z.avail_out == 0);

            Flush();
        }
示例#2
0
        public override int Read(byte[] b, int off, int len)
        {
            if (len == 0)
            {
                return(0);
            }

            z.next_out       = b;
            z.next_out_index = off;
            z.avail_out      = len;

            int err;

            do
            {
                if (z.avail_in == 0 && !nomoreinput)
                {
                    z.next_in_index = 0;
                    z.avail_in      = input.Read(buf, 0, buf.Length);

                    if (z.avail_in <= 0)
                    {
                        z.avail_in  = 0;
                        nomoreinput = true;
                    }
                }

                err = compress
                                        ?       z.deflate(flushLevel)
                                        :       z.inflate(flushLevel);

                if (nomoreinput && err == JZlib.Z_BUF_ERROR)
                {
                    return(0);
                }
                if (err != JZlib.Z_OK && err != JZlib.Z_STREAM_END)
                {
                    throw new IOException((compress ? "de" : "in") + "flating: " + z.msg);
                }
                if ((nomoreinput || err == JZlib.Z_STREAM_END) && z.avail_out == len)
                {
                    return(0);
                }
            }while(z.avail_out == len && err == JZlib.Z_OK);

            return(len - z.avail_out);
        }
示例#3
0
        public override 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))
                {
                    z.next_in_index = 0;
                    z.avail_in      = inp.Read(buf, 0, BUFSIZE);
                    if (z.avail_in <= 0)
                    {
                        z.avail_in  = 0;
                        nomoreinput = true;
                    }
                }
                err = z.inflate(flushLevel);
                if (nomoreinput && (err == JZlib.Z_BUF_ERROR))
                {
                    return(0);
                }
                if (err != JZlib.Z_OK && err != JZlib.Z_STREAM_END)
                {
                    throw new IOException("inflating: " + z.msg);
                }
                if ((nomoreinput || err == JZlib.Z_STREAM_END) && (z.avail_out == len))
                {
                    return(0);
                }
            }while(z.avail_out == len && err == JZlib.Z_OK);

            return(len - z.avail_out);
        }