========================================================================= */
(strm, flush)
| 550 | |
| 551 | /* ========================================================================= */ |
| 552 | int ZEXPORT deflate (strm, flush) |
| 553 | z_streamp strm; |
| 554 | int flush; |
| 555 | { |
| 556 | int old_flush; /* value of flush param for previous deflate call */ |
| 557 | deflate_state *s; |
| 558 | |
| 559 | if (strm == Z_NULL || strm->state == Z_NULL || |
| 560 | flush > Z_FINISH || flush < 0) { |
| 561 | return Z_STREAM_ERROR; |
| 562 | } |
| 563 | s = strm->state; |
| 564 | |
| 565 | if (strm->next_out == Z_NULL || |
| 566 | (strm->next_in == Z_NULL && strm->avail_in != 0) || |
| 567 | (s->status == FINISH_STATE && flush != Z_FINISH)) { |
| 568 | ERR_RETURN(strm, Z_STREAM_ERROR); |
| 569 | } |
| 570 | if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); |
| 571 | |
| 572 | s->strm = strm; /* just in case */ |
| 573 | old_flush = s->last_flush; |
| 574 | s->last_flush = flush; |
| 575 | |
| 576 | /* Write the header */ |
| 577 | if (s->status == INIT_STATE) { |
| 578 | #ifdef GZIP |
| 579 | if (s->wrap == 2) { |
| 580 | strm->adler = crc32(0L, Z_NULL, 0); |
| 581 | put_byte(s, 31); |
| 582 | put_byte(s, 139); |
| 583 | put_byte(s, 8); |
| 584 | if (s->gzhead == NULL) { |
| 585 | put_byte(s, 0); |
| 586 | put_byte(s, 0); |
| 587 | put_byte(s, 0); |
| 588 | put_byte(s, 0); |
| 589 | put_byte(s, 0); |
| 590 | put_byte(s, s->level == 9 ? 2 : |
| 591 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? |
| 592 | 4 : 0)); |
| 593 | put_byte(s, OS_CODE); |
| 594 | s->status = BUSY_STATE; |
| 595 | } |
| 596 | else { |
| 597 | put_byte(s, (s->gzhead->text ? 1 : 0) + |
| 598 | (s->gzhead->hcrc ? 2 : 0) + |
| 599 | (s->gzhead->extra == Z_NULL ? 0 : 4) + |
| 600 | (s->gzhead->name == Z_NULL ? 0 : 8) + |
| 601 | (s->gzhead->comment == Z_NULL ? 0 : 16) |
| 602 | ); |
| 603 | put_byte(s, (Byte)(s->gzhead->time & 0xff)); |
| 604 | put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); |
| 605 | put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); |
| 606 | put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); |
| 607 | put_byte(s, s->level == 9 ? 2 : |
| 608 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? |
| 609 | 4 : 0)); |
no test coverage detected