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); }