title: Where in the zlib compress/deflate code does the library decide that a block should be copied as uncompressed into the compressed stream?
body: <p>In the &quot;Maximum Expansion Factor&quot; section of the <a href="https://www.zlib.net/zlib_tech.html" rel="nofollow noreferrer">zlib technical details</a> it is stated &quot;In the worst possible case, where the other block types would expand the data, deflation falls back to stored (uncompressed) blocks.&quot;</p>
  <p>I am having a hard time figuring out where in the zlib <a href="https://github.com/madler/zlib/blob/master/compress.c" rel="nofollow noreferrer">compress</a>/<a href="https://github.com/madler/zlib/blob/master/deflate.c" rel="nofollow noreferrer">deflate</a> code this decision actually happens. I can see that <code>deflate_stored</code> is called when the selected <code>level</code> is 0, which makes sense, but besides that I don't see it being used.</p>
  <p>If someone can point me in the right direction that would be helpful.</p>
  <p>Also, what is the block granularity (in terms of the uncompressed data) that these decisions are taken? I understand that in deflate the uncompressed block can be upto 64KB, but there is no defined block size for the compressed chunks. Clearly it has to do with how useful the huffman codes are for the blocks but it would be nice to know if there was a block size at which these decisions are taken.</p>