{"id":1583,"date":"2017-07-05T14:07:12","date_gmt":"2017-07-05T06:07:12","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1583"},"modified":"2017-07-05T14:07:12","modified_gmt":"2017-07-05T06:07:12","slug":"jszip-%e4%b8%8e-blob","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1583","title":{"rendered":"JSZip \u4e0e Blob"},"content":{"rendered":"<p>\n\t<a href=\"http:\/\/stuk.github.io\/jszip\/\" name=\"jszip\" target=\"_blank\" title=\"jszip\">jszip<\/a> \u662f\u4e00\u4e2a JavaScript \u5e93\uff0c\u53ef\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e0a\u521b\u5efa zip \u538b\u7f29\u6863\u3002\n<\/p>\n<p>\n\t\u767e\u5ea6\u767e\u79d1\u76ee\u524d\u8fd8\u6ca1\u6709\u76f8\u5173\u7684\u6536\u5f55\u8d44\u6599\u3002\u4ece\u8fd9\u4e00\u65b9\u9762\u6765\u8bf4\u7528\u7684\u4eba\u8fd8\u4e0d\u662f\u5f88\u591a\u3002\u4eca\u5929\u6211\u7814\u7a76\u5230\u4e86\uff0c\u5c31\u5206\u4eab\u4e00\u4e0b\u3002\n<\/p>\n<p>\n\tjszip \u5b98\u65b9\u7f51\u5740\u662f\uff1a<a href=\"http:\/\/stuk.github.io\/jszip\/\" name=\"jszip\" target=\"_blank\" title=\"jszip\">http:\/\/stuk.github.io\/jszip\/<\/a>\n<\/p>\n<h2>\n\tJSZip \u5b89\u88c5<br \/>\n<\/h2>\n<ul>\n<li>\n\t\tWith npm : npm install jszip\n\t<\/li>\n<li>\n\t\tWith bower : bower install Stuk\/jszip\n\t<\/li>\n<li>\n\t\tWith component : component install Stuk\/jszip\n\t<\/li>\n<li>\n\t\tManually : <a href=\"https:\/\/codeload.github.com\/Stuk\/jszip\/legacy.zip\/master\" name=\"jszip \u4e0b\u8f7d\u5730\u5740\" target=\"_blank\" title=\"jszip \u4e0b\u8f7d\u5730\u5740\">download JSZip<\/a> and include the file dist\/jszip.js or dist\/jszip.min.js\n\t<\/li>\n<\/ul>\n<p>\n\tJSZip \u7684\u4f7f\u7528\n<\/p>\n<p>\n\tJSZip\u7684\u4f7f\u7528\u975e\u5e38\u7b80\u5355\u3002\u4f7f\u7528\u5982\u4e0b\u7684\u4ee3\u7801\u5373\u53ef\u5b9e\u73b0\u7b80\u5355\u7684\u538b\u7f29\u3002\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar zip = new JSZip();\r\nzip.file(&quot;Hello.txt&quot;, &quot;Hello World\\n&quot;);\r\nvar img = zip.folder(&quot;images&quot;);\r\nimg.file(&quot;smile.gif&quot;, imgData, {base64: true});\r\nzip.generateAsync({type:&quot;blob&quot;})\r\n.then(function(content) {\r\n    \/\/ see FileSaver.js\r\n    saveAs(content, &quot;example.zip&quot;);\r\n});<\/pre>\n<p>\n\t\u6d4f\u89c8\u5668\u5bf9 JSZip\u7684\u652f\u6301\u60c5\u51b5\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\u6d4f\u89c8\u5668\u5bf9 JSZip \u7684\u652f\u6301\u5217\u8868\" src=\"http:\/\/img.bbs.csdn.net\/upload\/201707\/05\/1499234177_243335.png\" style=\"width: 899px; height: 294px;\" \/>\n<\/p>\n<p>\n\t\u6709\u4e9b\u9879\u76ee\u9700\u8981\u7528\u5230\u7684\u5982\u4e0b\u64cd\u4f5c\uff1a\n<\/p>\n<ol>\n<li>\n\t\t\u7528\u6237\u901a\u8fc7\u62d6\u62fd\u6216\u8005\u9009\u62e9\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u5c06\u6587\u4ef6\u590d\u5236\u5230\u672c\u5730\n\t<\/li>\n<li>\n\t\t\u5c06\u7528\u6237\u751f\u6210\u7684\u5185\u5bb9\u4fdd\u5b58\u4e3a\u672c\u5730\u6587\u4ef6\n\t<\/li>\n<li>\n\t\t\u5c06\u7528\u6237\u751f\u6210\u7684\u6240\u6709\u5185\u5bb9\uff08html\u3001js\u3001css\u3001\u56fe\u7247\u3001\u89c6\u9891\u7b49\uff09\u5b58\u5165\u4e00\u4e2a\u538b\u7f29\u5305\uff0c\u4ea4\u7ed9\u7528\u6237\u4e0b\u8f7d\n\t<\/li>\n<\/ol>\n<p>\n\t\u538b\u7f29\u65b9\u9762\u6211\u4eec\u5c31\u53ef\u4ee5\u7528\u5230\u4e0a\u9762\u7684JSZip\u63d2\u4ef6\u3002\n<\/p>\n<p>\n\t\u6700\u5f00\u59cb\uff0c\u6211\u6309\u7167\u5b98\u7f51\u4ecb\u7ecd\u4f7f\u7528 location \u89e6\u53d1\u4e0b\u8f7d\uff0c\u5c0f\u5bb9\u91cf\u5185\u5bb9\u6d4b\u8bd5\u65f6\u4e00\u5207\u90fd\u597d\uff0c\u6b63\u5f0f\u5bfc\u51fa\u65f6Chrome\u5c31\u53cd\u590d\u5d29\u6e83\u3002Google\u4e4b\uff0c\u539f\u6765Chrome\u7684URL\u4e0a\u9650\u662f2M\uff0c\u5f53\u538b\u7f29\u540e\u7684\u5185\u5bb9\u8d85\u8fc72M\u540e\uff0c\u5c31\u4e0d\u80fd\u518d\u901a\u8fc7 location \u89e6\u53d1\u4e0b\u8f7d\u4e86\u3002\u6ca1\u529e\u6cd5\u7ee7\u7eedGoogle\uff0c\u4ece\u56fd\u5916\u4e00\u4e2a\u5927\u4fa0\u7684\u535a\u5ba2\u4e2d\u627e\u5230\u4e86\u514b\u654c\u5236\u80dc\u7684\u6cd5\u5b9d\uff1aUint8Array \u548c ArrayBuffer\u3002\n<\/p>\n<p>\n\tUint8Array \u548c ArrayBuffer \u4e5f\u662f\u65b0\u6807\u51c6\u5e26\u6765\u7684\u597d\u4e1c\u897f\u3002\u524d\u8005\u8868\u793a\u4e00\u4e2a\u75318\u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u540e\u8005\u5219\u4ee3\u8868\u4e00\u6bb5\u4e8c\u8fdb\u5236\u6570\u636e\u7f13\u51b2\uff0c\u8fd9\u6837\u8bf4\u5927\u5bb6\u53ef\u80fd\u4e0d\u660e\u767d\uff0c\u6309\u7167\u6211\u7684\u7406\u89e3\u548c\u7528\u6cd5\uff0c\u5c31\u662f\u5b58\u50a8\u5728 Uint8Array\uff08JavaScript \u7c7b\u578b\u6570\u7ec4\u7684\u4e00\u79cd\uff09\u7684\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u5176 ArrayBuffer \u5c5e\u6027\u6765\u8f6c\u5316\u6210\u4e8c\u8fdb\u5236\u5bf9\u8c61\u3002\u524d\u6587\u7684\u4ee3\u7801\u7ecf\u4fee\u6539\u5df2\u7ecf\u53ef\u4ee5\u652f\u6301\u4e8c\u8fdb\u5236\u5185\u5bb9\u7684\u5199\u5165\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002\n<\/p>\n<p>\n\t\u76f8\u6bd4\u5916\u56fd\u5927\u4fa0\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u8fd9\u6837\u5c06zip\u6587\u4ef6\u4fdd\u5b58\u5230\u672c\u5730\u7684\u505a\u6cd5\uff0c\u727a\u7272\u4e86\u90e8\u5206\u6d4f\u89c8\u5668\u517c\u5bb9\u6027\uff08\u76ee\u524d\u53ea\u6709Chrome\u652f\u6301File API\uff09\uff0c\u4f46\u662f\u6587\u4ef6\u540d\u53ef\u8bfb\u6027\u8981\u597d\u7684\u591a\uff0c\u4e5f\u65b9\u4fbf\u901a\u8fc7 XHR2 \u5c06\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u76f8\u4fe1\u65e5\u540e\u4f1a\u6709\u66f4\u591a\u5e94\u7528\u9009\u62e9\u6211\u7684\u8fd9\u79cd\u65b9\u5f0f\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=1583\">JSZip \u4e0e Blob<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>jszip \u662f\u4e00\u4e2a JavaScript \u5e93\uff0c\u53ef\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e0a\u521b\u5efa zip \u538b\u7f29\u6863\u3002 \u767e\u5ea6\u767e\u79d1\u76ee\u524d\u8fd8\u6ca1\u6709\u76f8\u5173\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1324,1202,1322,1323,1325],"class_list":["post-1583","post","type-post","status-publish","format-standard","hentry","category-html5","tag-arraybuffer","tag-blob","tag-jszip","tag-js","tag-uint8array"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1583"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1583\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1583\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}