title: Downloading generated binary content contains utf-8 encoded chars in disk-file
body: <p>I am trying to save a generated zip-file to disk from within a chrome extension with the follwing code:</p>
  
  <pre><code>function sendFile (nm, file) {
    var a = document.createElement('a');
    a.href = window.URL.createObjectURL(file);
    a.download = nm; // file name
    a.style.display = 'none';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
  }
  function downloadZip (nm) {
    window.URL = window.webkitURL || window.URL;
    var content;
    content = zip.generate();
    var file = new Blob ([content], {type:'application/base64'});
    sendFile ("x.b64", file);
    content = zip.generate({base64:false});
    var file = new Blob ([content], {type:'application/binary'});
    sendFile ("x.zip", file);
  }
  </code></pre>
  
  <p>Currently this saves the contents of my zip in two versions, the first one is base64 encoded, and when I decode it with <code>base64 -d</code> the resulting zip is ok.<br>
  The second version should just save the raw data (the zip file), but this raw data arrives utf-8 encoded on my disk. (each value >= 0x80 is preprended with 0xc2). So how to get rid of this utf-8 encoding? Tried various type-strings like <code>application/zip</code>, or ommitting the type info completely, it just arrives always with utf-8 encoding. I am also curious how to make the browser store/convert base64-data (the first case) by itself, so that they arrive as decoded binary data on my disk... I'm using Chrome Version 23.0.1271.95 m<br></p>
  
  <p>PS: The second content I analysed with a hexdump-utility inside the browser: it does not contain utf-8 encodings (or my hexdump calls something which does implicit conversion). For completeness (sorry, its just transposed from c, so it might not be that cool js-code), I append it here:</p>
  
  <pre><code>function hex (bytes, val) {
    var ret="";
    var tmp="";
    for (var i=0;i&lt;bytes;i++) {
      tmp=val.toString (16);
      if (tmp.length&lt;2)
        tmp="0"+tmp;
      ret=tmp+ret;
      val&gt;&gt;=8;
    }
    return ret;
  }
  function hexdump (buf, len) {
    var p=0;
    while (p&lt;len) {
      line=hex (2,p);
      var i;
      for (i=0;i&lt;16;i++) {
        if (i==8)
          line +=" ";
        if (p+i&lt;len)
          line+=" "+hex(1,buf.charCodeAt(p+i));
        else
          line+="   ";
      }
      line+=" |";
      for (i=0;i&lt;16;i++) {
        if (p+i&lt;len) {
          var cc=buf.charCodeAt (p+i);
          line+= ((cc&gt;=32)&amp;&amp;(cc&lt;=127)&amp;&amp;(cc!='|')?String.fromCharCode(cc):'.');
        }
      }
      p+=16;
      console.log (line);
    }
  }
  </code></pre>