=========================================================================== Flushes all pending output into the compressed file. The parameter flush is as in the deflate() function. */
(file, flush)
| 708 | flush is as in the deflate() function. |
| 709 | */ |
| 710 | local int do_flush (file, flush) |
| 711 | gzFile file; |
| 712 | int flush; |
| 713 | { |
| 714 | uInt len; |
| 715 | int done = 0; |
| 716 | gz_stream *s = (gz_stream*)file; |
| 717 | |
| 718 | if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; |
| 719 | |
| 720 | s->stream.avail_in = 0; /* should be zero already anyway */ |
| 721 | |
| 722 | for (;;) { |
| 723 | len = Z_BUFSIZE - s->stream.avail_out; |
| 724 | |
| 725 | if (len != 0) { |
| 726 | if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) { |
| 727 | s->z_err = Z_ERRNO; |
| 728 | return Z_ERRNO; |
| 729 | } |
| 730 | s->stream.next_out = s->outbuf; |
| 731 | s->stream.avail_out = Z_BUFSIZE; |
| 732 | } |
| 733 | if (done) break; |
| 734 | s->out += s->stream.avail_out; |
| 735 | s->z_err = deflate(&(s->stream), flush); |
| 736 | s->out -= s->stream.avail_out; |
| 737 | |
| 738 | /* Ignore the second of two consecutive flushes: */ |
| 739 | if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK; |
| 740 | |
| 741 | /* deflate has finished flushing only when it hasn't used up |
| 742 | * all the available space in the output buffer: |
| 743 | */ |
| 744 | done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END); |
| 745 | |
| 746 | if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break; |
| 747 | } |
| 748 | return s->z_err == Z_STREAM_END ? Z_OK : s->z_err; |
| 749 | } |
| 750 | |
| 751 | int ZEXPORT gzflush (file, flush) |
| 752 | gzFile file; |