title: How to add multiple files to a zip with zip.js?
body: <p>I am using the javascript <a href="http://gildas-lormeau.github.io/zip.js/">zip.js</a> library. I've seach all around I a cannot find an example where more than one file is added to the zip.</p>
  
  <p>Here is my code, but it generates a "corrupted" zip.</p>
  
  <pre><code>var len = results.rows.length, i;
  var k=1;
  zip.createWriter(new zip.BlobWriter(), function(writer) {
      for (i = 0; i &lt; len; i++){
          // get the image url from a sqlite request
          url = results.rows.item(i).url;
  
  
          var img = new Image();
          img.onload = function() {
              var a = document.createElement('a');
              a.href = this.src;
              var filename= a.pathname.split('/').pop(); // filename.php
              timest = new Date().getTime();
              // use a TextReader to read the String to add
  
                  writer.add(timest+".jpg", new zip.Data64URIReader(getBase64Image(img)), function() {
                  // onsuccess callback
                      k++;
                      if(k==len){
                          setTimeout(function(){
                          writer.close(function(blob) {
  
                              // blob contains the zip file as a Blob object
                              $('#test').attr("href", window.URL.createObjectURL(blob));
                              $('#test').attr("download", "woeii.zip");
  
                          });
                          },1000);
                      }
                  }, function(currentIndex, totalIndex) {
                  // onprogress callback
                  });
  
  
  
          };
          img.src = url;
      }
  });
  </code></pre>
  
  <p>Any idea to make it work? :)</p>