title: How to get a hash or checksum of a file from a stream in node js or javascript
body: <p>I am trying to get the checksum or the hash of a file from a server without download the whole file to my server or writing it on my disk like reading the data from the server and then getting the hash value.</p>
  
  <h1>Code</h1>
  
  <pre><code>var download = function (url, dest, callback) {
  
                  request.get(url)
                      .on('error', function (err) { console.log(err) })
                      .pipe(fs.createWriteStream(dest))
                      .on('close', callback);
  
              };
  
              final_list.forEach(function (str) {
                  var filename = str.split('/').pop();
  
                  console.log('Downloading ' + filename);
  
                  download(str, filename, function () { console.log('Finished Downloading' + "" + filename) });
              });
  </code></pre>
  
  <h1>hash</h1>
  
  <pre><code>   function generateChecksum(str, algorithm, encoding) {
          return crypto
              .createHash(algorithm || 'md5')
              .update(str, 'utf8')
              .digest(encoding || 'hex');
      }
  </code></pre>