title: Obtaining the hash of a file using the stream capabilities of crypto module (ie: without hash.update and hash.digest)
body: <p>The <a href="http://nodejs.org/docs/v0.10.18/api/crypto.html"><code>crypto</code></a> module of node.js (at the time of this writing at least) is not still deemed stable and so the API may change. In fact, the methods that everyone in the internet use to get the hash (md5, sha1, ...) of a file are considered legacy (from the documentation of <a href="http://nodejs.org/docs/v0.10.18/api/crypto.html#crypto_class_hash"><code>Hash</code> class</a>) (note: emphasis mine):</p>
  
  <blockquote>
    <p>Class: Hash</p>
    
    <p>The class for creating hash digests of data.</p>
    
    <p>It is a stream that is both readable and writable. The written data is
    used to compute the hash. Once the writable side of the stream is
    ended, use the read() method to get the computed hash digest. The
    <strong>legacy update and digest methods</strong> are also supported.</p>
    
    <p>Returned by crypto.createHash.</p>
  </blockquote>
  
  <p>Despite <code>hash.update</code> and <code>hash.digest</code> being considered legacy, the example shown just above the quoted snippet is using them.</p>
  
  <p>What's the correct way of obtaining hashes without using those legacy methods?</p>