Beispiel #1
0
        /// <exception cref="System.IO.IOException"></exception>
        public override void Write(byte[] b, int off, int len)
        {
            if (len == 0)
            {
                return;
            }
            int err;

            z.next_in       = b;
            z.next_in_index = off;
            z.avail_in      = len;
            do
            {
                z.next_out       = buf;
                z.next_out_index = 0;
                z.avail_out      = bufsize;
                if (compress)
                {
                    err = z.Deflate(flush);
                }
                else
                {
                    err = z.Inflate(flush);
                }
                if (err != JZlib.Z_OK)
                {
                    throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg);
                }
                @out.Write(buf, 0, bufsize - z.avail_out);
            }while (z.avail_in > 0 || z.avail_out == 0);
        }
Beispiel #2
0
        /// <exception cref="System.IO.IOException"></exception>
        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))
                {
                    // if buffer is empty and more input is avaiable, refill it
                    z.next_in_index = 0;
                    z.avail_in      = @in.Read(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 == JZlib.Z_BUF_ERROR))
                {
                    return(-1);
                }
                if (err != JZlib.Z_OK && err != JZlib.Z_STREAM_END)
                {
                    throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg);
                }
                if ((nomoreinput || err == JZlib.Z_STREAM_END) && (z.avail_out == len))
                {
                    return(-1);
                }
            }while (z.avail_out == len && err == JZlib.Z_OK);
            //System.err.print("("+(len-z.avail_out)+")");
            return(len - z.avail_out);
        }
Beispiel #3
0
		internal int DeflateParams(ZStream strm, int _level, int _strategy)
		{
			int err = Z_OK;
			if (_level == Z_DEFAULT_COMPRESSION)
			{
				_level = 6;
			}
			if (_level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY)
			{
				return Z_STREAM_ERROR;
			}
			if (config_table[level].func != config_table[_level].func && strm.total_in != 0)
			{
				// Flush the last buffer:
				err = strm.Deflate(Z_PARTIAL_FLUSH);
			}
			if (level != _level)
			{
				level = _level;
				max_lazy_match = config_table[level].max_lazy;
				good_match = config_table[level].good_length;
				nice_match = config_table[level].nice_length;
				max_chain_length = config_table[level].max_chain;
			}
			strategy = _strategy;
			return err;
		}