title: Compressing a blob in javascript
body: <p>I need to send a blob to the server with ajax, but it can end up getting somewhat large, and I'd like to decrease upload time. I've tried jszip already, but that just gave me an empty file inside the zip. I've also tried btoa(), but it turns out that the encoded value just ends up being [object Blob] instead of the actual blob data. What are my options for compressing blobs? </p>
  
  <p>Here was the code I used for jszip:</p>
  
  <pre><code>var zip = new JSZip();
  zip.file("recording.wav", blobFile);
  var content = zip.generate();
  </code></pre>
  
  <p>I then appended "content" to a FormData object and sent it to the server. On the server side, I decoded the POST data (from base64). The zip file opened just fine, but recording.wav was a 0 length file.</p>
  
  <p>Additionally, I've tried using the LZW implementation found <a href="http://rosettacode.org/wiki/LZW_compression#JavaScript">here</a>. This was the additional code I used to compress it:</p>
  
  <pre><code>var compressed;
  var reader = new FileReader();
  reader.onload = function(event){
     compressed = LZW.compress(event.target.result);
  };
  reader.readAsText(blobFile);
  </code></pre>
  
  <p>However, decompressing it returns null.</p>