title: Read huge files in browser using FileReader (web api)
body: <p>I'm trying to read the first byte of the selected file.</p>
  
  <p>But when I select a large file (>100Mb) I get an error: "NotReadableError".</p>
  
  <p>See the code below. Is "array buffer" really a buffer or it just loads the whole stuff into the memory and I MUST use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice" rel="noreferrer">file#slice</a>?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function readFile(file) {
    var reader = new FileReader();
    
    reader.onload = function() {
      var buffer = reader.result;
      var view = new Int8Array(buffer);
      try {
        view.forEach(function(v, index, array) {
          console.log(v);
          alert("ok - " + v);
          throw "BreakException";
        })
      } catch (e) {
        if (e!=="BreakException") throw e;
      }
    }
    
    reader.onerror = function() {
      alert("error");
      console.log(reader.error);
    }
    
    reader.readAsArrayBuffer(file);
  }
  
  var fileField = document.getElementById("file");
  
  fileField.onchange = function(e) {
    var file = e.target.files[0];
    readFile(file);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form&gt;
    &lt;input id="file" type="file"/&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>