title: How to load a file into a byte array in JavaScript
body: <p>I'm am developing a mobile application with cordova. The applications needs in some point to be off-line which means that it has to have data in an internal database.</p>
  
  <p>The data consists on a bunch of fields some of them are links to files. For example:</p>
  
  <pre><code>var restaurant = {
     name: 'Restaurant X'
     address: 'So far'
     logo: http://www.restaurantX.com/logo.png
     image: pics/restaurant-x.jpg
  }
  </code></pre>
  
  <p>When the user decides to be off-line we should extract all the relevant information from the database (This point is cleared) and download all the related images (This is where I am stuck). At this point I thought in two options the first one is download all the files to the mobile as files or as data in the database, however, the project chief said that It was mandatory that images were saved as blob on the database.</p>
  
  <p>I've been looking for a function to <em>convert the content of the file</em> into a <em>byte Array</em> for saving it into the database but I need a syncronous function since I have to wait for the pictures before of saving the row in the database.</p>
  
  <pre><code>function(tx, row){
      var query = "INSERT INTO Restaurants (name, address, logo, image) values (?,?,?,?)";
      var logo = null; // I need to fill it with the logo
      var picture = null; // I need to fill it with the picture
      tx.executeSql(query, [row["nombre"], row["address"],logo,picture], onSuccess, onError);
  });
  </code></pre>
  
  <p>I'm sorry if the question is too basis, I'm practically new at JavaScript.</p>