MCPcopy Create free account
hub / github.com/F-Stack/f-stack / deflateBound

Function deflateBound

freebsd/contrib/zlib/deflate.c:655–712  ·  view source on GitHub ↗

========================================================================= * For the default windowBits of 15 and memLevel of 8, this function returns * a close to exact, as well as small, upper bound on the compressed size. * They are coded as constants here for a reason--if the #define's are * changed, then this function needs to be changed as well. The return * value for 15 and 8 only work

(strm, sourceLen)

Source from the content-addressed store, hash-verified

653 * allocation.
654 */
655uLong ZEXPORT deflateBound(strm, sourceLen)
656 z_streamp strm;
657 uLong sourceLen;
658{
659 deflate_state *s;
660 uLong complen, wraplen;
661
662 /* conservative upper bound for compressed data */
663 complen = sourceLen +
664 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
665
666 /* if can't get parameters, return conservative bound plus zlib wrapper */
667 if (deflateStateCheck(strm))
668 return complen + 6;
669
670 /* compute wrapper length */
671 s = strm->state;
672 switch (s->wrap) {
673 case 0: /* raw deflate */
674 wraplen = 0;
675 break;
676 case 1: /* zlib wrapper */
677 wraplen = 6 + (s->strstart ? 4 : 0);
678 break;
679#ifdef GZIP
680 case 2: /* gzip wrapper */
681 wraplen = 18;
682 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */
683 Bytef *str;
684 if (s->gzhead->extra != Z_NULL)
685 wraplen += 2 + s->gzhead->extra_len;
686 str = s->gzhead->name;
687 if (str != Z_NULL)
688 do {
689 wraplen++;
690 } while (*str++);
691 str = s->gzhead->comment;
692 if (str != Z_NULL)
693 do {
694 wraplen++;
695 } while (*str++);
696 if (s->gzhead->hcrc)
697 wraplen += 2;
698 }
699 break;
700#endif
701 default: /* for compiler happiness */
702 wraplen = 6;
703 }
704
705 /* if not default parameters, return conservative bound */
706 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
707 return complen + wraplen;
708
709 /* default settings: return tight bound for that case */
710 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
711 (sourceLen >> 25) + 13 - 6 + wraplen;
712}

Callers 1

zstd_zlibwrapper.cFile · 0.85

Calls 1

deflateStateCheckFunction · 0.85

Tested by

no test coverage detected