title: How to calculate the CRC of an arrayBuffer (From FileReader in javascript) compatible with the CRC32 function in php?
body: <p>On the client side (Javascript) I'm using the FileReader() Object to read a local file from a browser and this file is sent to the server (PHP) thanks to the XMLHttpRequest() object. The object I recover thanks to the FileReader object is an arrayBuffer. This ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer and its content can not be manipulate directly.
  To optimize the transfer I split the file in several chunk. I want to check the integrity of each chunk transferred (Each chunk is about 100KB). The idea is to calculate the CRC on the javascript side and the server side, then compare the two CRC to check the integrity and retry the transfer if needed.</p>
  
  <p><strong>JAVASCRIPT</strong></p>
  
  <pre><code>var fileReader = new FileReader();
  fileReader.onload = function(event){
  
      var arrayBuffer = event.target.result;
      // 
      // TODO : calculate the crc of this arrayBuffer
  
      var xhr = new XMLHttpRequest();
      ...
      xhr.open(YourMethod,YourUrl,true);
      ...
      xhr.addEventListener('loadend', function (event) {
  
      var CRCFromPhp = event.target.responseText;
  
      // TODO : compare the CRC from php with the CRC from javascript
  
      }
  
  
  }
  fileReader.readAsArrayBuffer(blob);
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>    $file_crc = hash_file("crc32b",$target_file,FALSE);
      $file_crc = sprintf('%u',hexdec($file_crc));
      echo $file_crc; 
  </code></pre>