Web-side compression decompression plug-in Jszip library usage

Source: Internet
Author: User

Jszip This library supports the creation of zip-format files on the Web, the official website is: http://stuk.github.io/jszip/

The official website demo is as follows:

<! DOCTYPE Html>"en"> <meta charset="UTF-8"> <title></title> <script src="Http://stuk.github.io/jszip/dist/jszip.js"></script> <script type="Text/javascript"Src="Http://stuk.github.io/jszip-utils/dist/jszip-utils.js"></script> <!--[ifIe]> <script type="Text/javascript"Src="Http://stuk.github.io/jszip-utils/dist/jszip-utils-ie.js"></script> <! [endif]--> <script src="Http://stuk.github.io/jszip/test/jquery-1.8.3.min.js"></script> <script src="Http://stuk.github.io/jszip/vendor/FileSaver.js"></script>varImgdata ="r0lgoddhbqafaiacaaaaap/eacwaaaaabqafaaacciwpkwerclibads="; varZip =NewJszip (); Zip.file ("Hello.txt","Hello world\n"); varimg = Zip.folder ("Images"); Img.file ("Smile.gif", Imgdata, {base64:true}); varContent = Zip.generate ({type:"blob"}); //See Filesaver.jsSaveAs (Content,"Example.zip");</script></body>

API is very friendly, but browser support is a big problem, browser to support the Btoa method, whether JS will error;

If the browser supports BLOBs, you can save the zip file like this:

var blob = zip.generate ({type:"blob""hello.zip  ");

If the browser supports the data URI, you can use this method to save the zip file:

location.href="data:application/zip;base64," + zip.generate ({type:"  Base64"});

IE8 is a uri-enabled = = "" http://caniuse.com/#search =data

IE8 Although supporting the data URI, but there is a problem, according to the Jszip official website, if the browser does not support blobs, using the data URI to download the zip file, I will not be able to implement the download function:

<! DOCTYPE Html>"en"> <meta charset="UTF-8"> <title></title> <script src="Http://stuk.github.io/jszip/dist/jszip.js"></script> <script type="Text/javascript"Src="Http://stuk.github.io/jszip-utils/dist/jszip-utils.js"></script> <!--[ifIe]> <script type="Text/javascript"Src="Http://stuk.github.io/jszip-utils/dist/jszip-utils-ie.js"></script> <! [endif]--> <script src="Http://stuk.github.io/jszip/test/jquery-1.8.3.min.js"></script> <script src="Http://stuk.github.io/jszip/vendor/FileSaver.js"></script>
<script>varZip =NewJszip (); Zip.file ("Hello.txt","Hello world\n"); varA = Document.createelement ("a"); A.innerhtml="Zip_file_hellow.txt"; A.href="Data:application/zip;base64,"+ zip.generate ({type:"Base64"}) ; Document.body.appendChild (a); varImgdata ="data:image/jpg;base64,/9j/4aaqskzjrgabaqeblaesaad/ 4qlqrxhpzgaasukqaeocaaasaqaaaqaaacwbaaabaaaaaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaa Aaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaae Bcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8aaaaaaebcdwaaaaaaqeipaaaaaabaqg8 Aggcagguaaqaaakaaaacdgguaaqaaakgaaaaiiamaaqaaaaaaaaaniamaagaaaaaaaaaakacabaaaadaymtackquaaqaaalaaaaabkguaaqaaalgaaaackgua Aqaaamaaaaadkguaaqaaamgaaaaekguaaqaaanaaaaafkguaaqaaangaaaagkguaaqaaaoaaaaahkgmaaqaaaaaaaaaikgmaaqaaaaaaaaajkgmaaqaaaaaaa Aakkguaaqaaaogaaaaboamaaqaaaaaaaaacoamaaqaaafuaaaadoamaaqaaafuaaaaooguaaqaaapaaaaapoguaaqaaapgaaaaqogmaaqaaaaaaaaavoguaaq Aaaaabaaaxogmaaqaaaaaaaaaaowmaaqaaaaaaaaabowmaaqaaaaaaaaaaaaaacaeaaaoaegedaaeaaaabaaaaggefaaeaaaaiaaaagwefaaeaaaaqaaaakae Daaeaaaacaaaapgefaaiaaaayaaaapwefaayaaaaoaaaaeqifaamaaabyaaaaewidaaeaaaaaaaaafaifaayaaabwaaaaayceaaeaaaaiaqaaaaaaap/sabfedwnreqabaaqaaaa8aad/4qntahr0cdovl25zlmfkb2jllmnvbs94yxavms4wlwa8p3hwywnrzxqgymvnaw49iu+ 7vyigawq9ilc1ttbncenlaglienjlu3povgn6a2m5zci/ Pia8edp4bxbtzxrhihhtbg5zong9imfkb2jlom5zom1ldgeviib4onhtchrrpsjbzg9izsbytvagq29yzsa1ljmtyzaxmsa2ni4xndu2njesidiwmtivmdivm dytmtq6nty6mjcgicagicagici+ idxyzgy6ukrgihhtbg5zonjkzj0iahr0cdovl3d3dy53my5vcmcvmtk5os8wmi8ymi1yzgytc3ludgf4lw5ziyi+ Idxyzgy6rgvzy3jpchrpb24gcmrmomfib3v0psiiihhtbg5zonhtce1npsjodhrwoi8vbnmuywrvymuuy29tl3hhcc8xljavbw0viib4bwxuczpzdfjlzj0ia Hr0cdovl25zlmfkb2jllmnvbs94yxavms4wl3nuexbll1jlc291cmnlumvmiyigeg1sbnm6eg1wpsjodhrwoi8vbnmuywrvymuuy29tl3hhcc8xljaviib4bx Bnttppcmlnaw5hbervy3vtzw50suq9inhtcc5kawq6nkfdoddfmeuymdvfrtixmtgyotncntk5rjawqkiwrtciihhtce1nokrvy3vtzw50suq9inhtcc5kawq 6njixrky1rdq4quq4mtffmjgwnji4neq4qzgxntewqtuiihhtce1nokluc3rhbmnlsuq9inhtcc5pawq6njixrky1rdm4quq4mtffmjgwnji4neq4qzgxntew Qtuiihhtcdpdcmvhdg9yvg9vbd0iqwrvymugughvdg9zag9wientnsbxaw5kb3dzij4gphhtce1nokrlcml2zwrgcm9tihn0umvmomluc3rhbmnlsuq9inhtc C5pawq6mjK1nkvgqjgymdhbrtixmtg2mdlgodi3nzk4rei2nkuiihn0umvmomrvy3vtzw50suq9inhtcc5kawq6nkfdoddfmeuymdvfrtixmtgyotncntk5rjawqkiwrtc ilz4gpc9yzgy6rgvzy3jpchrpb24+idwvcmrmoljerj4gpc94onhtcg1ldge+idw/ehbhy2tldcblbmq9iniipz7/ 2wbdaauebaqeawuebaqgbqugca0icachcbaldaknexauexiqehiufx0zfbycfhisgimahb4fisehfbkkjyqgjh0gisd/ 2wbdaqugbgghca8ica8gfrivicagicagicagicagicagicagicagicagicagicagicagicagicagicagicagicagicd/ waarcabvafudareaahebaxeb/8qaggaaawebaqeaaaaaaaaaaaaabqyhcaqca// eadkqaaedawmcbaubbwihaaaaaaecawqfbheabxitiqgimueuizjryruwfzncq3ghuoekjtdegpg0/8qafaebaaaaaaaaaaaaaaaaaaaaap/ eabqraqaaaaaaaaaaaaaaaaaaaad/2gamaweaahedeqa/aj5y9j7pxvd/ abtynyitdfu9vnkcp0x1osejunynhbcvzoftogc1lj8og4jnwxlqgxy1ukxsn6jynpiqjcaapqqz5ldsda+bf3/anjedm1414rqljgv/4+ mcac2lbh5uvbq8yhjtka/ 20albw2bksopvtczbh2g3t1kbbkzifruxaqibpd1ibcqeuhdnhzyou99bstxa5b14s7b3hsabvkxtou89bcn2eleerlvjmjbpfoqn0z76cc2jav5xta +/dt1p6cxcdsnsidkrkmoing44vqsrjnj27dvtom57i0e0qtliuq041svnplrh1195qcjrmivxwplq/ Pfquuk4ymdtboum7g23evzs82izppm5tko7ccnya42lmmhtdz6xxhsicolgscevh20bjcexavun4t7ztm7y44w5aoee+dd6exureounhpn/ahxjqsyo+ekzrf/sr5c+og8828a5x/rz/jqjw/ dj0lbndyxbfth9ebqmy6kpufasqtk98dqvsylua3d8iek0il0uoj1bu4xjqhu5yahbkfj9bk5jupbqmw1e1f7qtefarv+ 2pugptvsotbccfyxzpfq7kce2ekdvfql8d/ob4f8ahqlup/1uacpvg1lbjee9a3aqeatpvjpqqe5g+ ckm6ltkuvtgqa21lqvnv2b7abdupevdb657p24tuomrrkekoqqhwx4sf0+ e6ehbcdxekogvzispudta2otxd65tko25u4tn1wzwrpvqlcprdsj1ceybsuhmb6khsdagobf/ aluu249udnzcw1kfildcoxbhdupdvw0vkh6kvc1kawjou4ynakvbi1lfygq9+imq+z1nioiq6jazhtghrknilh45b+ by5hvk4unbsjlrpedxl2dmxjap9ofmjpgu6lhbju7xbutjopyffqrfphiq4qgl/vmsbghurj9svn1zjhdh+daf8vu6fut/ p0qny2jjbhrghwha4npdumponbyh7d2zy2tavhewd0la5xhqpqelcuhisvf4p59kdsz/i0e9txfduadgqy2cugwztvqyk/ gv9j5zv5eq6mfk7hsdnsdbya7y0o79m9vgbpdz2w/ Tas5jp9punxqes6hv8ugljklkx5wdnivopfotc4pt11ynvd39mlicbe9fmsqzh3fduo7bbicwulrksphdhqt20c9nucixnvtttze3vuznafynvlls2osyowac 4cfbxjvhpy1d1h7/ ag0hi77gsjaw59wazekwlygx7ufyhonikps5cs24pxteiuclrlg9mfsdao2ai8d2r4ivy1nwkrbd1souqbbptrs2uqzekfblau8t1elxlkifhtnog5bnvui2l Da7muoyqyzamwrkxdtngplvznpur8w0trcktlxcvajukexgpbqubdk59ka/edfhydu6lf1snhzlc6how70wqv/julpz6k9yc5pmhfqtmbxpdrsqo3taxsnc1mlucsgpk59lecca8voa4yd/ aojol9utkpddrjhg1diku2wafkzl11xpyb7g8vu5axokfuvdc2zrpnug2fubr6joydhu8hqjbkffthwdhiwatj3ggyim+ lcvbnnqsfwmrykzohs7om0dagtcn/mk155lrklofdvmfjqmsq7kpe1ft2zlq3ror0mykkzwxloffargrgvhyabskhkvisoipc/ Qdby6xvozmo6q3xlzgxhal0rfmug3i7ieqlqcclxhlxjy6pavlhotk6dlsbf62k5fv00ge/s/besiraoluj/mqyqffkzu6mqkce+ af4gz7aajcmw9xlkt64ow0nwuz6nclxsugxhtvn3e9nfce4ajufqwpxj+ 2gr1l0awqzuxql6muwps2ijdvjpfefuh2qc2li6rzdkeyewdgh7aa9dsswdt/ce5t+z6bu9+n1amq1qjpr+cjuojcy5u0rb4lzvkjjzopg2vx2 /t2741ce2rn7axvr18bhqsp1ezauoyotme5x6dvom71e7qnupshidlrvc59wgzrftxiwk1icjog+ k2ngapwewpfqfqxvhyfxgpnbsbdvxtdciuu1zc3ofby+hpbaahedvtqatpmtzau7zjo53iazudnpwp0se0i5jvgpxnmo+gupt+bqz/ q8nvcm26pvnvfde9tobnqs+7mhpkftmzb5jwx9awcczpfbtoaeq6lrs/ec4h7r2ozzivmmttw7jllhwc+ccv8ubzy7qxj+ bqw66kfvdzdudl6htrbj1swk1f1wgepie0djdceqt5cgfkle3podd+0iovjzq9kvudar0+ Owvtlimxrogdulrb5vnph0ecez8yvbqtkwktuhv4tmunb+2kttzs5kzcarcurbebqrcmtyfghob2vgz/qhqpfifp8qn7yu6hvllduiorayyy/eb8nwa0uosolod3coff+f8aggxdwlh2iheeh+ 2llq9gare1unyjmki7l119kmuooj7gjof7aadcvudqtn131vkahcdvx5tcnu0qonookjuhhskbzuqelrwop8vrofa+ txw7suil2lte5tbdtwqv41muvourlzbrxly8qiaf/hqgbf8ifyxrabvxr1fftwct1avu6ttitaug4cieon1/ Tonpbt7lwruxbaltrgpvrjpnvu1nmrlrzjlavzzucg8tyz6n00cza3ssuhwjtppuwdau2r8dxmlxpdjs07nv9bagkpyfjpuoffhoepyxslubanuavdfiv6 /jcr+pfq02eozzslyumonkoe5blae+bsej00hjy5d61x6l7az5u+ zjg3tjuieyw9znvs64xoi6kebi4jgcq7kpbqdvexsa9q78pewr7t1efat5spdcumrn8ptmedpicavc0/m7ja/ Zopdu7gzk2bnrdsv2qugbtntw0x2hliaurpww0ood+ Ngi5bofeuo3roctzb4bgtdtna3dwwleu0zldmhx2tueumunruktqksgkgqkco3rjqknw2lt2j2mlqsuqjtbaudddaevaxklvvlwhsitaaeskkhkoqi /iemgcxzcfvus1f3hwjx5o6y5ikvrnxw4ptymg/kywqv1sknhwex9q9tayqlz0m0alhrdttsfvdsbirhn41yhdjdx/ wc1cvjwrdecrocef8adv3rqo899329cwydwrlrs91lttl6lyi0wxepw4alsknofxtoeg/ ffzef7ucpsotlrb3sliklfp8x1k3upcgwlfdcuxcfjqxmi2/tt+/dvqakzqovujp9seqdfjprkbhkonfxibucaafk9z+ Tocmqixjtldoffonh2tnd3lllvlp6g4rfwqqprbcq72yogipy5bogk9ardu21e9y3eug/aha+46sizos6khthfdaqc1gceqclahepqsc4hm6cg7b7x25vjrbnrg5tl0fim2oy1id0ip8yg0uc+z4rssp4y+nuf9tb0wjcsfvs7nvpaeq79xvh2zdlvyygjrwivrkwqhepsu4k/x5b99bgk7y+ 5fyg1m3lordzoty1l8vw/zdu7qwplaxzwhjcy22hpkvcuqi+gyhpoppjpg1z9vt23d/ioudtbcemzkq8ziezyeb+ Psjwueiucbjt2gnbwpb9qrfg3tyrmebekzy9bkxmkmqonrlnpnyavjkaqc47eugzbetgzb98o7f7vxhubqoym1vjmihfxttjpvhv5acphmaumke3fggrtw8s1 5bvvfvottokdbjzidxgxxwlcqvufyaynv+nal29t3bsoefsktb/lkpdzuyttz4crlr7jgsrg0o8fhgqve+ 3yabyrn9wrtt4nrxpnwvitqlalubewnhgnrltd7iwiviabbcfycjywo/ 8afqcnlqtr5n77nqafubcvytcpbyln1gy66zdsskdvxkvafk0nnjcfyabmh2dt5ur0pl72ndnwvkdb8tfuul6tt92yaccvglqlt3zcxxhinagg0za283h /rvyats2fgxirtiyvwykktlustkjsv5ysr3p1ad4y5ldddre1tzu2hygumswbdmw62g5e1ptrupxakahtqhdhlh1kggz/ Aeogbu1xvckzbmhjunun1dcfuvvgeevccg3sagxflbsfprhwox5eaardty3rcuyvezl7cwvdp1dls0yo1qmhimjknrqcssvkoqvjkgcdyog7ajv1t6ps2b2g9 cmxzaapznsxgxw6zkyx3lohoaxvmoz5z8idawvefzu5e2w2/wbqa3nvg8xofuxlrdzakojpthsq+6li4pkk4sfe+gvn9yb12fd/yi+ 7at2vvlgb9uurp+nkkqvukf0koqb6d20fvsw/febujzzdytmx7cco/waqtcg3mlngoj7e8s769/ Udqhqxn8tdmsxv6ryg3r4jsqeeccsxf8ejyfv3j7dqkn43jaf4+ Fugxhfhut6q1nuxerfusblt99bdqht3so9mhijyfvojtyf57swbsfdcbftrkrwuwjpqpmdbhkohzdga4ejbaiunjjogd1egq9prv2m3rtx12vwqmhzzzm0htc vtfhejskjub5znzaczbg7jr2bt2c3mu3jhacgpzpnwbailbw23kjtkngvemsda4w5vovkb42zsrnkpve3r+iuca5ue/ oauw1updwoiso4yfan86cqeiy/tyquzutulnt+26fsqw78aw5tmldvxpd54kuezhm9mzynbp+ jueukua3mwlwt1dmouzpciutljlcvxoabnbtjgc49zommtbyh4n/1gmoeapg8s0h9vyl48t5eq78c47emgo7gxtukjd7srxbvkrua+ 1nid8w3upxedit8ogqss8in183+w0c24jj8b1o+f63u/axwekdnhtx9vb00h08mqqir1+ fgcsefsplwhexhpjh37z9f86d61ybopfhg2fq1nyd8qbxzmptkm+ aesh3vj5d3gqmjqwcj0sdvpdjem6tqz6d0xfqjxxjsuhdqu0lxthsbiyk8qpc5j0eutzbzd22ngbkuaaagbxr1md8tepalsw2ucv4aeoek8x9+/ b7achbuxfbnoegy77psrieu4qdchut/1hsor+usr8kajko6s9/ 8atoobxe1s063tzzlxxaipovazqy0qauagiho5lttvpvkeqgmfjqrm7l9o8dbtqwrizmfpfvyyl1vdxacn/i0ljprwd2a8ifbvk/ fqdf5wpa27sjun3s/ujfm0szotkn4rgicvsaskahzklzsm+2gpmwvivowfec7bf0tke6p+guyp+ hkb1rc1pa7kacux7y0h1v7wg3u5dzrlgprnkiw0cdvj5l/phmzhgmz9pxqsgyn+ 9xdurxfuwznhtqevle4vruuhkr17nv7aa9o8vg79sp0unyqntixjawy4ewualkkked7dtbx7ivu4bh8pozjvbfzbrwa8udm6jqwvtlkrjaz6hvjog01c9hw7d1zt6q1ph5yvb0stojbdkal0ehkgpqgujsfzoir4v77ug17vo9vuh5hec4wpte5ljiwvphtxxj +n6lacj7vboxbftutvzs4pmd2z5raaa8y0wlt0sttlsqhb3byhpf8av99bopcnpc9w9v8ayfxl9ikxtvss2afnktgqvtyd9u4lsm49e/ 30gnn27rrfw3s7tqo625ht1tlhghdysux2nfbauf5jj30fort93df3ghq1tun5l6rcrrefkstbsbpcgyked1ovhv8anqtlw/ 2xql73jluq5gx3okempzejzelz6ickp7j27nt+dbuhw/3vcg4m0uw5lkfacqlkl5ps2wg2kpsrcew0h//z"; varb = document.createelement ("a"); B.innerhtml="____img"; B.href=Imgdata; Document.body.appendChild (b);</script></body>

According to the official version of this plugin support ie6,7,8, but I feel a problem after testing ....

  

NONO
Source: http://www.cnblogs.com/diligenceday/
QQ: 287101329

Web-side compression decompression plug-in Jszip library usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.