How to zip multiple zip files in Javascript? -


problem

i want generate zip file contains multiples other zip files in javascript. use jszip don't manage add zip files 1 zip file.

example

i have multiple text files :

  • player 1 - file 1.txt
  • player 1 - file 2.txt
  • player 2 - file 1.txt
  • player 2 - file 2.txt

i want generate zip file :

  • example.zip
    • player 1.zip
      • player 1 - file 1.txt
      • player 1 - file 2.txt
    • player 2.zip
      • player 2 - file 1.txt
      • player 2 - file 2.txt

thank help.

fiddle: https://mikethedj4.github.io/kodeweave/editor/#ca2d1692722e8f6c321c322cd33ed246

after many hours , failed attempts got work jszip!

note: i'm using jszip v2.6.0 outdated , not work current version 3.0 time of posting.

javascript:

// set sample url document.getelementbyid("zipurl").value = "https://mikethedj4.github.io/kodeweave/editor/zips/font-awesome.zip";  $(".loadzipurl").on("click", function() {   if ( (!document.getelementbyid("zipurl").value) ) {     // nothing     alertify.error("unable perform operation value blank!");   } else {     if ( (document.getelementbyid("zipurl").value.tolowercase().substring(0,7) === "http://" ) || (document.getelementbyid("zipurl").value.tolowercase().substring(0,8) === "https://") ) {       jsziputils.getbinarycontent(document.getelementbyid("zipurl").value, function(error, repofiles) {         if(error) {           throw error // or handle err         }          var webappzipbinary = repofiles;          // download windows app         jsziputils.getbinarycontent("https://mikethedj4.github.io/kodeweave/editor/zips/yourlinapp.zip", function(err, data) {           if(err) {             throw err // or handle err           }            alertify.message("creating application!");           var zip = new jszip();           zip.load(data);            // web application           zip.folder("hellomommy/").load(webappzipbinary);            // 32bit windows application           zip.file("package.json", '{\n  "main"  : "index.html",\n  "name"  : "test",\n  "window": {\n      "toolbar" : false,\n      "icon"    : "app/icons/128.png",\n      "width"   : 1000,\n      "height"  : 600,\n      "position": "center"\n  }\n}');           zip.file("index.html", '<!doctype html>\n<html>\n <head>\n    <title>test</title>\n    <style>\n      iframe {\n        position: absolute;\n        top: 0;\n        left: 0;\n        width: 100%;\n        height: 100%;\n        overflow: visible;\n        border: 0;\n      }\n    </style>\n  </head>\n <body>\n    <iframe src="app/index.html"></iframe>\n  </body>\n</html>');            // export application           var content = zip.generate({type:"blob"});           saveas(content, "test-win.zip");           return false;         });       });     } else {       alertify.error("error! \"http://\" , \"https://\" urls supported!");     }   } }); 

html:

<input type="text" id="zipurl" placeholder="http://"> <button class="loadzipurl">export application</button> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -