title: Reading line-by-line file in JavaScript on client side
body: <p>Could you please help me with following issue.</p>
  
  <p><strong>Goal</strong></p>
  
  <p>Read file on client side (in browser via JS and HTML5 classes) line by line, without loading whole file to memory.</p>
  
  <p><strong>Scenario</strong></p>
  
  <p>I'm working on web page which should parse files on client side. Currently, I'm reading file as it described in this <a href="http://www.html5rocks.com/en/tutorials/file/dndfiles/">article</a>.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="file" id="files" name="files[]" /&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>$("#files").on('change', function(evt){
      // creating FileReader
      var reader = new FileReader();
  
      // assigning handler
      reader.onloadend = function(evt) {      
          lines = evt.target.result.split(/\r?\n/);
  
          lines.forEach(function (line) {
              parseLine(...);
          }); 
      };
  
      // getting File instance
      var file = evt.target.files[0];
  
      // start reading
      reader.readAsText(file);
  }
  </code></pre>
  
  <p>The problem is that FileReader reads whole file at once, which causes crashed tab for big files (size >= 300 MB). Using <code>reader.onprogress</code> doesn't solve a problem, as it just increments a result till it will hit the limit.</p>
  
  <p><strong>Inventing a wheel</strong></p>
  
  <p>I've done some research in internet and have found no simple way to do this (there are bunch of articles describing this exact functionality but on server side for node.js).</p>
  
  <p>As only way to solve it I see only following:</p>
  
  <ol>
  <li>Split file by chunks (via <code>File.split(startByte, endByte)</code> method)</li>
  <li>Find last new line character in that chunk ('/n')</li>
  <li>Read that chunk except part after last new line character and convert it to the string and split by lines</li>
  <li>Read next chunk starting from last new line character found on step 2</li>
  </ol>
  
  <p>But I'll better use something already existing to avoid entropy growth. </p>