title: Reading binary data into JavaScript
body: <p>I've got a <code>WebGL</code> application which requires me to load a lot of <code>x,y</code> vertex data, but to minimise bandwidth usage I want to also compress the data (on a one off basis) using <code>gzip</code>.</p>
  
  <p>Below is the code I will use to load in the data. I want to retrieve data from a server and pass it straight into a <code>Float32Array</code>.</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  xhr.open('GET', 'array.gz', true);
  xhr.responseType = 'arraybuffer';
  xhr.onload = function(data) {
      console.log("loaded");
      var dataArray = new Float32Array(this.response);
  
  xhr.onprogress = function(e) {
  };
  xhr.onerror = function(error) {
      console.log('error!');
  };
  xhr.send();
  </code></pre>
  
  <p>Now my problem isn't linked to the code directly, but to the file format supported. In what format (i.e. <code>csv</code>, <code>json</code>, <code>xml</code>) does the data need to be in, before being gzipped so that this method can properly consume it?</p>
  
  <p>I've played around to find that if I <code>JSON.stringify</code> a <code>Float32Array</code> and place the content in a file, then load it in, it works fine. However, to load in all my uncompressed data into a JavaScript array, before copying all its contents back into a new file to be compressed isn't very feasible. So I'm really looking for an alternative way to this (<em>assuming this file format is the only one supported</em>).</p>