title: Best practice for comparing two large files in Node.js
body: <p>I want to <strong>compare two large files</strong>(5GB+) and find if they are the same or not. One solution I considered is <strong>hashing both</strong> with crypto and then comparing the hashes. But this would take a lot of time since I will have to go through the entire files instead of stopping when a difference is found. <br>
  Another solution I thought was to compare the file as they are being streamed with <code>fs.createReadStream()</code> and break when a difference is found.</p>
  <pre><code>stream.on('data', (data) =&gt; {
     //compare the data from this stream with the other stream
  })
  </code></pre>
  <p>But I am not quite sure how I can have two streams that are synchronized.</p>