filer/dist/filer.min.js

4 lines
92 KiB
JavaScript
Raw Permalink Normal View History

2014-05-28 20:00:10 +00:00
/*! filer 0.0.8 2014-05-28 */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.Filer=t()}}(function(){var t;return function n(t,e,r){function i(a,s){if(!e[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var c=e[a]={exports:{}};t[a][0].call(c.exports,function(n){var e=t[a][1][n];return i(e?e:n)},c,c.exports,n,t,e,r)}return e[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({1:[function(n,e){(function(n){(function(){function r(t){var n=!1;return function(){if(n)throw Error("Callback was already called.");n=!0,t.apply(i,arguments)}}var i,o,a={};i=this,null!=i&&(o=i.async),a.noConflict=function(){return i.async=o,a};var s=function(t,n){if(t.forEach)return t.forEach(n);for(var e=0;t.length>e;e+=1)n(t[e],e,t)},u=function(t,n){if(t.map)return t.map(n);var e=[];return s(t,function(t,r,i){e.push(n(t,r,i))}),e},c=function(t,n,e){return t.reduce?t.reduce(n,e):(s(t,function(t,r,i){e=n(e,t,r,i)}),e)},f=function(t){if(Object.keys)return Object.keys(t);var n=[];for(var e in t)t.hasOwnProperty(e)&&n.push(e);return n};void 0!==n&&n.nextTick?(a.nextTick=n.nextTick,a.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:a.nextTick):"function"==typeof setImmediate?(a.nextTick=function(t){setImmediate(t)},a.setImmediate=a.nextTick):(a.nextTick=function(t){setTimeout(t,0)},a.setImmediate=a.nextTick),a.each=function(t,n,e){if(e=e||function(){},!t.length)return e();var i=0;s(t,function(o){n(o,r(function(n){n?(e(n),e=function(){}):(i+=1,i>=t.length&&e(null))}))})},a.forEach=a.each,a.eachSeries=function(t,n,e){if(e=e||function(){},!t.length)return e();var r=0,i=function(){n(t[r],function(n){n?(e(n),e=function(){}):(r+=1,r>=t.length?e(null):i())})};i()},a.forEachSeries=a.eachSeries,a.eachLimit=function(t,n,e,r){var i=l(n);i.apply(null,[t,e,r])},a.forEachLimit=a.eachLimit;var l=function(t){return function(n,e,r){if(r=r||function(){},!n.length||0>=t)return r();var i=0,o=0,a=0;(function s(){if(i>=n.length)return r();for(;t>a&&n.length>o;)o+=1,a+=1,e(n[o-1],function(t){t?(r(t),r=function(){}):(i+=1,a-=1,i>=n.length?r():s())})})()}},h=function(t){return function(){var n=Array.prototype.slice.call(arguments);return t.apply(null,[a.each].concat(n))}},p=function(t,n){return function(){var e=Array.prototype.slice.call(arguments);return n.apply(null,[l(t)].concat(e))}},d=function(t){return function(){var n=Array.prototype.slice.call(arguments);return t.apply(null,[a.eachSeries].concat(n))}},g=function(t,n,e,r){var i=[];n=u(n,function(t,n){return{index:n,value:t}}),t(n,function(t,n){e(t.value,function(e,r){i[t.index]=r,n(e)})},function(t){r(t,i)})};a.map=h(g),a.mapSeries=d(g),a.mapLimit=function(t,n,e,r){return v(n)(t,e,r)};var v=function(t){return p(t,g)};a.reduce=function(t,n,e,r){a.eachSeries(t,function(t,r){e(n,t,function(t,e){n=e,r(t)})},function(t){r(t,n)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(t,n,e,r){var i=u(t,function(t){return t}).reverse();a.reduce(i,n,e,r)},a.foldr=a.reduceRight;var m=function(t,n,e,r){var i=[];n=u(n,function(t,n){return{index:n,value:t}}),t(n,function(t,n){e(t.value,function(e){e&&i.push(t),n()})},function(){r(u(i.sort(function(t,n){return t.index-n.index}),function(t){return t.value}))})};a.filter=h(m),a.filterSeries=d(m),a.select=a.filter,a.selectSeries=a.filterSeries;var y=function(t,n,e,r){var i=[];n=u(n,function(t,n){return{index:n,value:t}}),t(n,function(t,n){e(t.value,function(e){e||i.push(t),n()})},function(){r(u(i.sort(function(t,n){return t.index-n.index}),function(t){return t.value}))})};a.reject=h(y),a.rejectSeries=d(y);var E=function(t,n,e,r){t(n,function(t,n){e(t,function(e){e?(r(t),r=function(){}):n()})},function(){r()})};a.detect=h(E),a.detectSeries=d(E),a.some=function(t,n,e){a.each(t,function(t,r){n(t,function(t){t&&(e(!0),e=function(){}),r()})},f
else if(256===T)break;this.c=b.finish(),this.e=this.c.length;break;case k:var S,x,N,D,R,j,L,M,F,U,C,P,V,B,z,Y=new n(E?new Uint8Array(this.c.buffer):this.c,this.e),W=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],X=Array(19);for(S=k,Y.b(1,1,m),Y.b(S,2,m),x=s(this,o),j=c(this.p,15),L=l(j),M=c(this.o,7),F=l(M),N=286;N>257&&0===j[N-1];N--);for(D=30;D>1&&0===M[D-1];D--);var q,Z,H,J,G,Q,K=N,$=D,tn=new(E?Uint32Array:Array)(K+$),nn=new(E?Uint32Array:Array)(316),en=new(E?Uint8Array:Array)(19);for(q=Z=0;K>q;q++)tn[Z++]=j[q];for(q=0;$>q;q++)tn[Z++]=M[q];if(!E)for(q=0,J=en.length;J>q;++q)en[q]=0;for(q=G=0,J=tn.length;J>q;q+=Z){for(Z=1;J>q+Z&&tn[q+Z]===tn[q];++Z);if(H=Z,0===tn[q])if(3>H)for(;H-->0;)nn[G++]=0,en[0]++;else for(;H>0;)Q=138>H?H:138,Q>H-3&&H>Q&&(Q=H-3),10>=Q?(nn[G++]=17,nn[G++]=Q-3,en[17]++):(nn[G++]=18,nn[G++]=Q-11,en[18]++),H-=Q;else if(nn[G++]=tn[q],en[tn[q]]++,H--,3>H)for(;H-->0;)nn[G++]=tn[q],en[tn[q]]++;else for(;H>0;)Q=6>H?H:6,Q>H-3&&H>Q&&(Q=H-3),nn[G++]=16,nn[G++]=Q-3,en[16]++,H-=Q}for(t=E?nn.subarray(0,G):nn.slice(0,G),U=c(en,7),B=0;19>B;B++)X[B]=U[W[B]];for(R=19;R>4&&0===X[R-1];R--);for(C=l(U),Y.b(N-257,5,m),Y.b(D-1,5,m),Y.b(R-4,4,m),B=0;R>B;B++)Y.b(X[B],3,m);for(B=0,z=t.length;z>B;B++)if(P=t[B],Y.b(C[P],U[P],m),P>=16){switch(B++,P){case 16:V=2;break;case 17:V=3;break;case 18:V=7;break;default:throw"invalid code: "+P}Y.b(t[B],V,m)}var rn,on,an,sn,un,cn,fn,ln,hn=[L,j],pn=[F,M];for(un=hn[0],cn=hn[1],fn=pn[0],ln=pn[1],rn=0,on=x.length;on>rn;++rn)if(an=x[rn],Y.b(un[an],cn[an],m),an>256)Y.b(x[++rn],x[++rn],m),sn=x[++rn],Y.b(fn[sn],ln[sn],m),Y.b(x[++rn],x[++rn],m);else if(256===an)break;this.c=Y.finish(),this.e=this.c.length;break;default:throw"invalid compression type"}return this.c};var D=function(){function t(t){switch(m){case 3===t:return[257,t-3,0];case 4===t:return[258,t-4,0];case 5===t:return[259,t-5,0];case 6===t:return[260,t-6,0];case 7===t:return[261,t-7,0];case 8===t:return[262,t-8,0];case 9===t:return[263,t-9,0];case 10===t:return[264,t-10,0];case 12>=t:return[265,t-11,1];case 14>=t:return[266,t-13,1];case 16>=t:return[267,t-15,1];case 18>=t:return[268,t-17,1];case 22>=t:return[269,t-19,2];case 26>=t:return[270,t-23,2];case 30>=t:return[271,t-27,2];case 34>=t:return[272,t-31,2];case 42>=t:return[273,t-35,3];case 50>=t:return[274,t-43,3];case 58>=t:return[275,t-51,3];case 66>=t:return[276,t-59,3];case 82>=t:return[277,t-67,4];case 98>=t:return[278,t-83,4];case 114>=t:return[279,t-99,4];case 130>=t:return[280,t-115,4];case 162>=t:return[281,t-131,5];case 194>=t:return[282,t-163,5];case 226>=t:return[283,t-195,5];case 257>=t:return[284,t-227,5];case 258===t:return[285,t-258,0];default:throw"invalid length: "+t}}var n,e,r=[];for(n=3;258>=n;n++)e=t(n),r[n]=e[2]<<24|e[1]<<16|e[0];return r}(),R=E?new Uint32Array(D):D,j=[80,75,1,2],L=[80,75,3,4],M=[80,75,5,6];h.prototype.m=function(t,n){n=n||{};var e,i=t.length,a=0;if(E&&t instanceof Array&&(t=new Uint8Array(t)),"number"!=typeof n.compressionMethod&&(n.compressionMethod=8),n.compress)switch(n.compressionMethod){case 0:break;case 8:a=r(t),t=new o(t,n.deflateOption).g(),e=m;break;default:throw Error("unknown compression method:"+n.compressionMethod)}this.files.push({buffer:t,a:n,j:e,r:!1,size:i,h:a})},h.prototype.q=function(t){this.i=t},h.prototype.g=function(){var t,n,e,i,a,s,u,c,f,l,h,g,y,w,b,A,O,T,I,S,x,N,k,_,D=this.files,R=0,F=0;for(x=0,N=D.length;N>x;++x){if(t=D[x],y=t.a.filename?t.a.filename.length:0,w=t.a.comment?t.a.comment.length:0,!t.j)switch(t.h=r(t.buffer),t.a.compressionMethod){case 0:break;case 8:t.buffer=new o(t.buffer,t.a.deflateOption).g(),t.j=m;break;default:throw Error("unknown compression method:"+t.a.compressionMethod)}if(t.a.password!==v||this.i!==v){var U=t.a.password||this.i,C=[305419896,591751049,878082192],P=v,V=v;for(E&&(C=new Uint32Array(C)),P=0,V=U.length;V>P;++P)d(C,255&U[P]);for(S=C,T=t.buffer,E?(I=new Uint8Array(T.length+12),I.set(T,12),T=I):T.unshift(0,0,0,0,0,0,0,0,0,0,0,0),k=0;12>k;++k)T[k]=p(S,11===x?255&t.h:0|256*Math.random());for(_=T.length;_>k;++k)T[k]=p(S,T[k]);t.buffer=T}R+=30+y+t.buffer.length,F+=46+y+w}for(n=new(E?Uint8
}))}function u(n,r){n?e(n):(l=r,pn(l).has(p)?t.get(l[p].id,s):e(new Vn.ENOENT("a component of the path does not name an existing file")))}function c(n,r){n?e(n):(f=r,t.get(f.data,u))}n=mn(n);var f,l,h,p=En(n),d=yn(n);o(t,d,c)}function E(t,n,e){function r(t,n){if(t)e(t);else{s=n;var r=Object.keys(s);e(null,r)}}function i(n,i){n?e(n):(a=i,t.get(a.data,r))}n=mn(n),En(n);var a,s;o(t,n,i)}function w(t,n,e,i){function a(n,e){n?i(n):(l=e,t.get(l.data,s))}function s(t,n){t?i(t):(h=n,pn(h).has(d)?i(new Vn.EEXIST):u())}function u(){p=new Wn(void 0,In),p.nlinks+=1,p.size=n.length,p.data=n,t.put(p.id,p,f)}function c(n){if(n)i(n);else{var e=Date.now();r(t,g,l,{mtime:e,ctime:e},i)}}function f(n){n?i(n):(h[d]=new Bn(p.id,In),t.put(l.data,h,c))}e=mn(e);var l,h,p,d=En(e),g=yn(e);xn==d?i(new Vn.EEXIST):o(t,g,a)}function b(t,n,e){function r(n,r){n?e(n):(s=r,t.get(s.data,i))}function i(n,r){n?e(n):(u=r,pn(u).has(c)?t.get(u[c].id,a):e(new Vn.ENOENT("a component of the path does not name an existing file")))}function a(t,n){t?e(t):n.mode!=In?e(new Vn.EINVAL("path not a symbolic link")):e(null,n.data)}n=mn(n);var s,u,c=En(n),f=yn(n);o(t,f,r)}function A(t,n,e,i){function a(n,e){n?i(n):e.mode==Tn?i(new Vn.EISDIR):(f=e,t.get(f.data,s))}function s(n,r){if(n)i(n);else{var o=new Uint8Array(e);r&&o.set(r.subarray(0,e)),t.put(f.data,o,c)}}function u(e){if(e)i(e);else{var o=Date.now();r(t,n,f,{mtime:o,ctime:o},i)}}function c(n){n?i(n):(f.size=e,f.version+=1,t.put(f.id,f,u))}n=mn(n);var f;0>e?i(new Vn.EINVAL("length cannot be negative")):o(t,n,a)}function O(t,n,e,i){function o(n,e){n?i(n):e.mode==Tn?i(new Vn.EISDIR):(c=e,t.get(c.data,a))}function a(n,r){if(n)i(n);else{var o=new Uint8Array(e);r&&o.set(r.subarray(0,e)),t.put(c.data,o,u)}}function s(e){if(e)i(e);else{var o=Date.now();r(t,n.path,c,{mtime:o,ctime:o},i)}}function u(n){n?i(n):(c.size=e,c.version+=1,t.put(c.id,c,s))}var c;0>e?i(new Vn.EINVAL("length cannot be negative")):t.get(n.id,o)}function T(t,n,e,i,a){function s(o,s){o?a(o):r(t,n,s,{atime:e,ctime:i,mtime:i},a)}n=mn(n),"number"!=typeof e||"number"!=typeof i?a(new Vn.EINVAL("atime and mtime must be number")):0>e||0>i?a(new Vn.EINVAL("atime and mtime must be positive integers")):o(t,n,s)}function I(t,n,e,i,o){function a(a,s){a?o(a):r(t,n.path,s,{atime:e,ctime:i,mtime:i},o)}"number"!=typeof e||"number"!=typeof i?o(new Vn.EINVAL("atime and mtime must be a number")):0>e||0>i?o(new Vn.EINVAL("atime and mtime must be positive integers")):t.get(n.id,a)}function S(t,n,e,r,i,o){n=mn(n),"string"!=typeof e?o(new Vn.EINVAL("attribute name must be a string")):e?null!==i&&i!==Fn&&i!==Un?o(new Vn.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):a(t,n,e,r,i,o):o(new Vn.EINVAL("attribute name cannot be an empty string"))}function x(t,n,e,r,i,o){"string"!=typeof e?o(new Vn.EINVAL("attribute name must be a string")):e?null!==i&&i!==Fn&&i!==Un?o(new Vn.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):a(t,n,e,r,i,o):o(new Vn.EINVAL("attribute name cannot be an empty string"))}function N(t,n,e,r){function i(t,n){n?n.xattrs[e]:null,t?r(t):n.xattrs.hasOwnProperty(e)?r(null,n.xattrs[e]):r(new Vn.ENOATTR)}n=mn(n),"string"!=typeof e?r(new Vn.EINVAL("attribute name must be a string")):e?o(t,n,i):r(new Vn.EINVAL("attribute name cannot be an empty string"))}function k(t,n,e,r){function i(t,n){n?n.xattrs[e]:null,t?r(t):n.xattrs.hasOwnProperty(e)?r(null,n.xattrs[e]):r(new Vn.ENOATTR)}"string"!=typeof e?r(new Vn.EINVAL):e?t.get(n.id,i):r(new Vn.EINVAL("attribute name cannot be an empty string"))}function _(t,n,e,i){function a(o,a){function s(e){e?i(e):r(t,n,a,{ctime:Date.now()},i)}var u=a?a.xattrs:null;o?i(o):u.hasOwnProperty(e)?(delete a.xattrs[e],t.put(a.id,a,s)):i(new Vn.ENOATTR)}n=mn(n),"string"!=typeof e?i(new Vn.EINVAL("attribute name must be a string")):e?o(t,n,a):i(new Vn.EINVAL("attribute name cannot be an empty string"))}function D(t,n,e,i){function o(o,a){function s(e){e?i(e):r(t,n.path,a,{ctime:Date.now()},i)}o?i(o):a.xattrs.hasOwnProperty(e)?(delete a.xattrs[e],t.put(a.id,a,s)):i(new Vn.ENOATTR)}"string"!=typeof e?i(new