title: Javascript reading local file to UInt8Array fast
body: <p>How to read local binary file to UInt8Array fast. in below code</p>
  
  <pre><code>function readAllBytesAsUInt8Array(path) {
      var req = new XMLHttpRequest();
      req.open("GET", path, false);
      req.overrideMimeType("text/plain; charset=binary-data");
      req.send(null);
      if (req.status !== 200) {
          console.log("error");
          return null;
      }
      var text = req.responseText;
      var resultArray = new Uint8Array(text.length);
      for(var i = 0; i &lt; text.length;i++){
      resultArray[i] = (text[i].charCodeAt() &amp; 255) &amp; 255;
      }
      return resultArray.buffer;
   }
  </code></pre>
  
  <p><code>var text = req.responseText;</code> is executed less than a second,meanwhile this part </p>
  
  <pre><code>var resultArray = new Uint8Array(text.length);
  for(var i = 0; i &lt; text.length;i++){
      resultArray[i] = (text[i].charCodeAt() &amp; 255) &amp; 255;
  }
  </code></pre>
  
  <p>takes around 10sec for 50MB of binary file, 
  <em>Is there a way to read binary file to UInt8Array faster ?</em></p>