title: Memory usage by DEFLATE algorithm
body: <p>Many implementations of the DEFLATE algorithm allow for stream-based inputs. An example is Java's <code>java.util.zip.ZipOutputStream</code>. As far as I'm aware, DEFLATE builds a Huffman tree prior to compression and writes this tree at the BEGINNING of a .zip file.</p>
  <p>However, in order to build a Huffman tree, the program needs counts of the most frequently occurring characters, which it has only after reading the file. If the stream is so large that it cannot fit in memory at once, how is the Huffman tree built?</p>