title: javascript convert to utf8 the result of readAsBinaryString
body: <p>I have a file in the following format:</p>
  
  <pre><code>utf-8 encoded text block
  separator 
  binary data block
  </code></pre>
  
  <p>I use JavaScript's FileReader to read the file as a binary string using </p>
  
  <p>FileReader.readAsBinaryString like so:</p>
  
  <pre><code>var reader = new FileReader();
  
  reader.onload  = function(evt){
      // Here I use the separator position to divide the file content into
      // header and binary
      ...
      console.log(header);
  
  };
  FileReader.onerror = function (evt) {
      onFailure(evt.target.error.code);
  }
  
  reader.readAsBinaryString(blobFile);
  </code></pre>
  
  <p>The header is not parsed as UTF-8. I know that FileReader.readAsText takes the encoding of the file into account while FileReader.readAsBinaryString reads the file byte by byte.</p>
  
  <p>How do I convert the header to utf8? reading the file twice, once as binary string to read the binary data and again as text to get the first block as utf8 encoded don't appeal to me.</p>