title: Save binary file from base64 data in Javascript
body: <p>I am trying to download xlsx spreadsheet with javascript. I have tested base64 data. I decode it like so:</p>
  
  <p><code>var data = atob(validBase64Data);</code></p>
  
  <p>After that, I do:</p>
  
  <pre><code>save(name, data, type) {
    const blob = new Blob([data], {type: type});
    let objectURL = window.URL.createObjectURL(blob);
    let anchor = document.createElement('a');
  
    anchor.href = objectURL;
    anchor.download = name;
    anchor.click();
  
    URL.revokeObjectURL(objectURL);
  }
  </code></pre>
  
  <p>Where name is a filename.xlsx, data is the decoded data and type is a mime-type string.</p>
  
  <p>The excel file is downloaded but would not open as excel. Data is corrupted somehow.</p>
  
  <p>In addition: I tested the same data with a unix terminal command to base64 decode and write the xlsx directly into that file, and that produced working file. Test was done like so:</p>
  
  <ol>
  <li>I saved base64 data to test_excel.txt`</li>
  <li>Ran command <code>base64 -D -i test_excel.txt -o test_excel.xlsx</code></li>
  <li>test_excel.xlsx is recognized by excel.</li>
  </ol>
  
  <p>What am I doing wrong with the code?</p>