MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / deflate

Function deflate

extern/zlib/src/deflate.c:946–1255  ·  view source on GitHub ↗

========================================================================= */

Source from the content-addressed store, hash-verified

944
945/* ========================================================================= */
946int ZEXPORT deflate(z_streamp strm, int flush) {
947 int old_flush; /* value of flush param for previous deflate call */
948 deflate_state *s;
949
950 if (deflateStateCheck(strm) || flush > Z_BLOCK || flush < 0) {
951 return Z_STREAM_ERROR;
952 }
953 s = strm->state;
954
955 if (strm->next_out == Z_NULL ||
956 (strm->avail_in != 0 && strm->next_in == Z_NULL) ||
957 (s->status == FINISH_STATE && flush != Z_FINISH)) {
958 ERR_RETURN(strm, Z_STREAM_ERROR);
959 }
960 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
961
962 old_flush = s->last_flush;
963 s->last_flush = flush;
964
965 /* Flush as much pending output as possible */
966 if (s->pending != 0) {
967 flush_pending(strm);
968 if (strm->avail_out == 0) {
969 /* Since avail_out is 0, deflate will be called again with
970 * more output space, but possibly with both pending and
971 * avail_in equal to zero. There won't be anything to do,
972 * but this is not an error situation so make sure we
973 * return OK instead of BUF_ERROR at next call of deflate:
974 */
975 s->last_flush = -1;
976 return Z_OK;
977 }
978
979 /* Make sure there is something to do and avoid duplicate consecutive
980 * flushes. For repeated and useless calls with Z_FINISH, we keep
981 * returning Z_STREAM_END instead of Z_BUF_ERROR.
982 */
983 } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) &&
984 flush != Z_FINISH) {
985 ERR_RETURN(strm, Z_BUF_ERROR);
986 }
987
988 /* User must not provide more input after the first FINISH: */
989 if (s->status == FINISH_STATE && strm->avail_in != 0) {
990 ERR_RETURN(strm, Z_BUF_ERROR);
991 }
992
993 /* Write the header */
994 if (s->status == INIT_STATE && s->wrap == 0)
995 s->status = BUSY_STATE;
996 if (s->status == INIT_STATE) {
997 /* zlib header */
998 uInt header = (Z_DEFLATED + ((s->w_bits - 8) << 4)) << 8;
999 uInt level_flags;
1000
1001 if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
1002 level_flags = 0;
1003 else if (s->level < 6)

Callers 5

gz_compFunction · 0.85
compress2Function · 0.85
deflateParamsFunction · 0.85
write_bufferFunction · 0.85
processMethod · 0.85

Calls 11

deflateStateCheckFunction · 0.85
flush_pendingFunction · 0.85
putShortMSBFunction · 0.85
adler32Function · 0.85
crc32Function · 0.85
zmemcpyFunction · 0.85
deflate_storedFunction · 0.85
deflate_huffFunction · 0.85
deflate_rleFunction · 0.85
_tr_alignFunction · 0.85
_tr_stored_blockFunction · 0.85

Tested by

no test coverage detected