1 |
- /* @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */var saveAs=saveAs||navigator.msSaveBlob&&navigator.msSaveBlob.bind(navigator)||function(a){var b=a.document,c=a.URL||a.webkitURL||a,d=b.createElementNS("http://www.w3.org/1999/xhtml","a"),e="download"in d,g=function(c){var d=b.createEvent("MouseEvents");d.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null);c.dispatchEvent(d)},l=a.webkitRequestFileSystem,m=a.requestFileSystem||l||a.mozRequestFileSystem,k=function(b){(a.setImmediate||a.setTimeout)(function(){throw b;},0)},t=0,q=[],v=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"===typeof e)try{e.call(a,c||a)}catch(z){k(z)}}},r=function(b,c){var f=this,h=b.type,k=!1,y=function(){var c=(a.URL||a.webkitURL||a).createObjectURL(b);q.push(c);return c},x=function(){v(f,["writestart","progress","write","writeend"])},n=function(){if(k||!u)u=y(b);w&&(w.location.href=u);f.readyState=f.DONE;x()},p=function(a){return function(){if(f.readyState!==f.DONE)return a.apply(this,arguments)}},r={create:!0,exclusive:!1};f.readyState=f.INIT;c||(c="download");if(e){var u=y(b);d.href=u;d.download=c;g(d);f.readyState=f.DONE;x()}else{if(a.chrome&&h&&"application/octet-stream"!==h){var A=b.slice||b.webkitSlice;b=A.call(b,0,b.size,"application/octet-stream");k=!0}l&&"download"!==c&&(c+=".download");var w="application/octet-stream"===h||l?a:a.open();m?(t+=b.size,m(a.TEMPORARY,t,p(function(a){a.root.getDirectory("saved",r,p(function(a){var d=function(){a.getFile(c,r,p(function(a){a.createWriter(p(function(c){c.onwriteend=function(b){w.location.href=a.toURL();q.push(a);f.readyState=f.DONE;v(f,"writeend",b)};c.onerror=function(){var a=c.error;a.code!==a.ABORT_ERR&&n()};["writestart","progress","write","abort"].forEach(function(a){c["on"+a]=f["on"+a]});c.write(b);f.abort=function(){c.abort();f.readyState=f.DONE};f.readyState=f.WRITING}),n)}),n)};a.getFile(c,{create:!1},p(function(a){a.remove();d()}),p(function(a){a.code===a.NOT_FOUND_ERR?d():n()}))}),n)}),n)):n()}},h=r.prototype;h.abort=function(){this.readyState=this.DONE;v(this,"abort")};h.readyState=h.INIT=0;h.WRITING=1;h.DONE=2;h.error=h.onwritestart=h.onprogress=h.onwrite=h.onabort=h.onerror=h.onwriteend=null;a.addEventListener("unload",function(){for(var a=q.length;a--;){var b=q[a];"string"===typeof b?c.revokeObjectURL(b):b.remove()}q.length=0},!1);return function(a,b){return new r(a,b)}}(self),FILE=function(){return{toBase64:function(a){a=new Uint8Array(a);var b,c=a.length,d="";for(b=0;b<c;b+=3)d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[b]>>2],d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[b]&3)<<4|a[b+1]>>4],d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[b+1]&15)<<2|a[b+2]>>6],d+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[b+2]&63];2===c%3?d=d.substring(0,d.length-1)+"=":1===c%3&&(d=d.substring(0,d.length-2)+"==");return d},toArrayBuffer:function(a){var b=.75*a.length,c=a.length,d=0;"="===a[a.length-1]&&(b--,"="===a[a.length-2]&&b--);var e=new ArrayBuffer(b),g=new Uint8Array(e);for(b=0;b<c;b+=4){var l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a[b]);var m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a[b+1]);var k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a[b+2]);var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a[b+3]);g[d++]=l<<2|m>>4;g[d++]=(m&15)<<4|k>>2;g[d++]=(k&3)<<6|t&63}return e},Byte:{toWords:function(a){for(var b=[],c=0,d=0;c<a.length;c++,d+=8)b[d>>>5]|=(a[c]&255)<<24-d%32;return b},toHex:function(a){for(var b=[],c=0;c<a.length;c++)b.push((a[c]>>>4).toString(16)),b.push((a[c]&15).toString(16));return b.join("")},toBase64:function(a){if("function"==typeof btoa)return btoa(Binary.bytesToString(a));for(var b=[],c=0;c<a.length;c+=3)for(var d=a[c]<<16|a[c+1]<<8|a[c+2],e=0;4>e;e++)8*c+6*e<=8*a.length?b.push("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d>>>6*(3-e)&63)):b.push("=");return b.join("")},toUTFString:function(a){return decodeURIComponent(escape(Binary.bytesToString(a)))},toBinString:function(a){for(var b=[],c=0;c<a.length;c++)b.push(String.fromCharCode(a[c]));return b.join("")}},Hex:{toBytes:function(a){for(var b=[],c=0;c<a.length;c+=2)b.push(parseInt(a.substr(c,2),16));return b}},String:{toUTFBytes:function(a){return FILE().util.Byte.stringToBytes(unescape(encodeURIComponent(a)))},toBinBytes:function(a){for(var b=[],c=0;c<a.length;c++)b.push(a.charCodeAt(c)&255);return b},toWordBytes:function(a){for(var b=[],c=0;c<32*a.length;c+=8)b.push(a[c>>>5]>>>24-c%32&255);return b}},Base64:{encode:function(a){var b="",c=0;for(a=Base64._utf8_encode(a);c<a.length;){var d=a.charCodeAt(c++);var e=a.charCodeAt(c++);var g=a.charCodeAt(c++);var l=d>>2;d=(d&3)<<4|e>>4;var m=(e&15)<<2|g>>6;var k=g&63;isNaN(e)?m=k=64:isNaN(g)&&(k=64);b=b+this.base64map.charAt(l)+this.base64map.charAt(d)+this.base64map.charAt(m)+this.base64map.charAt(k)}return b},decode:function(a){var b="",c=0;for(a=a.replace(/[^A-Za-z0-9\+\/=]/g,"");c<a.length;){var d=this.base64map.indexOf(a.charAt(c++));var e=this.base64map.indexOf(a.charAt(c++));var g=this.base64map.indexOf(a.charAt(c++));var l=this.base64map.indexOf(a.charAt(c++));d=d<<2|e>>4;e=(e&15)<<4|g>>2;var m=(g&3)<<6|l;b+=String.fromCharCode(d);64!=g&&(b+=String.fromCharCode(e));64!=l&&(b+=String.fromCharCode(m))}return b=Base64._utf8_decode(b)},_utf8_encode:function(a){a=a.replace(/\r\n/g,"\n");for(var b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);128>d?b+=String.fromCharCode(d):(127<d&&2048>d?b+=String.fromCharCode(d>>6|192):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128)),b+=String.fromCharCode(d&63|128))}return b},_utf8_decode:function(a){for(var b="",c=0,d,e,g;c<a.length;)d=a.charCodeAt(c),128>d?(b+=String.fromCharCode(d),c++):191<d&&224>d?(e=a.charCodeAt(c+1),b+=String.fromCharCode((d&31)<<6|e&63),c+=2):(e=a.charCodeAt(c+1),g=a.charCodeAt(c+2),b+=String.fromCharCode((d&15)<<12|(e&63)<<6|g&63),c+=3);return b}}}};
|