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) { // TODO // throw new ZStreamException((compress?"de":"in")+"flating: "+z.msg); 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(); }
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) { // if buffer is empty and more input is available, refill it z.next_in_index = 0; z.avail_in = input.Read(buf, 0, buf.Length); //(bufsize<z.avail_out ? bufsize : z.avail_out)); 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) { // TODO // throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg); 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); //Console.Error.WriteLine("("+(len-z.avail_out)+")"); return(len - z.avail_out); }
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 = inp.Read(buf, 0, BUFSIZE);//(BUFSIZE<z.avail_out ? BUFSIZE : z.avail_out)); 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); //System.err.print("("+(len-z.avail_out)+")"); return(len - z.avail_out); }