title: Saving Uint8array to a sqlite file
body: <p>I am using <a href="https://github.com/kripken/sql.js/" rel="nofollow">sql.js</a> as an admin interface for a SQLITE3 database.</p>
  
  <p>Basically sql.js provides an export method that returns a <strong>Uint8Array</strong> for the developer to further handle. </p>
  
  <p><strong>Goal:</strong> Have the user press a button and a "Save As" dialogue pops up to save a file that is a valid sqlite3 database.</p>
  
  <p><strong>What I've tried:</strong> This save code block I've found in various parts of the web researching this issue.</p>
  
  <pre><code>        /* Uint8Array */
          var binArray = db.export();
  
          var saveData = (function () {
              var a = document.createElement("a");
              document.body.appendChild(a);
              a.style = "display: none";
              return function (data, fileName) {
  
                  /* Is JSON.stringify necessary? */
                  var json = JSON.stringify(data),
  
                      /* Is type: "octet/stream" correct? */
                      blob = new Blob([json], {type: "octet/stream"}),
                      url = window.URL.createObjectURL(blob);
                  a.href = url;
                  a.download = fileName;
                  a.click();
                  window.URL.revokeObjectURL(url);
              };
          }());
  
          saveData(binArray, "sqldb.sql");
  </code></pre>
  
  <p>It properly saves a file called "sqldb.sql", but I get "Invalid file format" error from a database client software.</p>