=========================================================================== Writes the given number of uncompressed bytes into the compressed file. gzwrite returns the number of bytes actually written (0 in case of error). */
(file, buf, len)
| 562 | gzwrite returns the number of bytes actually written (0 in case of error). |
| 563 | */ |
| 564 | int ZEXPORT gzwrite (file, buf, len) |
| 565 | gzFile file; |
| 566 | voidpc buf; |
| 567 | unsigned len; |
| 568 | { |
| 569 | gz_stream *s = (gz_stream*)file; |
| 570 | |
| 571 | if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR; |
| 572 | |
| 573 | s->stream.next_in = (Bytef*)buf; |
| 574 | s->stream.avail_in = len; |
| 575 | |
| 576 | while (s->stream.avail_in != 0) { |
| 577 | |
| 578 | if (s->stream.avail_out == 0) { |
| 579 | |
| 580 | s->stream.next_out = s->outbuf; |
| 581 | if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) { |
| 582 | s->z_err = Z_ERRNO; |
| 583 | break; |
| 584 | } |
| 585 | s->stream.avail_out = Z_BUFSIZE; |
| 586 | } |
| 587 | s->in += s->stream.avail_in; |
| 588 | s->out += s->stream.avail_out; |
| 589 | s->z_err = deflate(&(s->stream), Z_NO_FLUSH); |
| 590 | s->in -= s->stream.avail_in; |
| 591 | s->out -= s->stream.avail_out; |
| 592 | if (s->z_err != Z_OK) break; |
| 593 | } |
| 594 | s->crc = crc32(s->crc, (const Bytef *)buf, len); |
| 595 | |
| 596 | return (int)(len - s->stream.avail_in); |
| 597 | } |
| 598 | |
| 599 | |
| 600 | /* =========================================================================== |