title: Problem downloading a PDF blob in JavaScript
body: <p>I've created a function that takes a <code>blob</code> and <code>fileName</code> which is supposed to download that blob implemented as follows:</p>
  
  <pre><code>const blobToBase64 = (blob, callback) =&gt; {
    const reader = new FileReader();
    reader.onloadend = () =&gt; {
      const base64 = reader.result;
      console.log({ base64 });
      callback(base64);
    };
    reader.readAsDataURL(blob);
  };
  
  const downloadFile = (blob, fileName) =&gt; () =&gt; {
    const link = document.createElement('a');
    blobToBase64(blob, (base64) =&gt; {
      link.href = base64;
      link.download = fileName;
      link.click();
    });
  };
  
  
  downloadFile(myBlob, myFileName);
  </code></pre>
  
  <p>To try debug this I've made a <code>console.log</code> to log out the value of <code>base64</code> which is created by <code>reader.result</code>.</p>
  
  <p>That <code>base64</code> value is <code>data:application/octet-stream;base64,Mzc4MDY4...</code></p>
  
  <p>My PDF file get's downloaded but it's corrupted. What am I doing wrong in my file download implementation?</p>
  
  <p>Let me know if there are any additional details that might help with this? I'm 100% sure that the blob itself is not a corrupted file. </p>