filer/dist/filer.min.js

4 lines
82 KiB
JavaScript
Raw Normal View History

2015-07-21 18:40:33 +00:00
/*! filer 0.0.43 2015-07-21 */
2015-07-16 21:51:55 +00:00
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Filer=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(b,c,d){!function(){var b={};"undefined"!=typeof process&&process.nextTick?(b.nextTick=process.nextTick,"undefined"!=typeof setImmediate?b.setImmediate=function(a){setImmediate(a)}:b.setImmediate=b.nextTick):"function"==typeof setImmediate?(b.nextTick=function(a){setImmediate(a)},b.setImmediate=b.nextTick):(b.nextTick=function(a){setTimeout(a,0)},b.setImmediate=b.nextTick),b.eachSeries=function(a,b,c){if(c=c||function(){},!a.length)return c();var d=0,e=function(){b(a[d],function(b){b?(c(b),c=function(){}):(d+=1,d>=a.length?c():e())})};e()},b.forEachSeries=b.eachSeries,"undefined"!=typeof a&&a.amd?a([],function(){return b}):"undefined"!=typeof c&&c.exports?c.exports=b:root.async=b}()},{}],2:[function(a,b,c){function d(a,b){for(var c=b.length-1;c>=0;c--)b[c]===a&&b.splice(c,1);return b}var e=function(){};e.createInterface=function(a){var b={};return b.on=function(b,c){"undefined"==typeof this[a]&&(this[a]={}),this[a].hasOwnProperty(b)||(this[a][b]=[]),this[a][b].push(c)},b.off=function(b,c){"undefined"!=typeof this[a]&&this[a].hasOwnProperty(b)&&d(c,this[a][b])},b.trigger=function(b){if("undefined"!=typeof this[a]&&this[a].hasOwnProperty(b))for(var c=Array.prototype.slice.call(arguments,1),d=0;d<this[a][b].length;d++)this[a][b][d].apply(this[a][b][d],c)},b.removeAllListeners=function(b){if("undefined"!=typeof this[a]){var c=this;c[a][b].forEach(function(a){c.off(b,a)})}},b};var f=e.createInterface("_handlers");e.prototype._on=f.on,e.prototype._off=f.off,e.prototype._trigger=f.trigger;var g=e.createInterface("handlers");e.prototype.on=function(){g.on.apply(this,arguments),Array.prototype.unshift.call(arguments,"on"),this._trigger.apply(this,arguments)},e.prototype.off=g.off,e.prototype.trigger=g.trigger,e.prototype.removeAllListeners=g.removeAllListeners,b.exports=e},{}],3:[function(a,b,c){(function(c){function d(a,b){var c=0;return function(){var d=Date.now();d-c>a&&(c=d,b.apply(this,arguments))}}function e(a,b){if("undefined"!=typeof a&&a||(a={}),"object"==typeof b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function f(){var a=this,b=Date.now();this.origin=h(),this.lastMessage=b,this.receivedIDs={},this.previousValues={};var d=function(){a._onStorageEvent.apply(a,arguments)};"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",d):c.addEventListener("storage",d,!1))}var g=a("./eventemitter.js"),h=a("../src/shared.js").guid,i=function(a){return"undefined"==typeof a||"undefined"==typeof a.localStorage?{getItem:function(){},setItem:function(){},removeItem:function(){}}:a.localStorage}(c);f.prototype._transaction=function(a){function b(){if(!g){var k=Date.now(),m=0|i.getItem(l);if(m&&d>k-m)return h||(f._on("storage",b),h=!0),void(j=setTimeout(b,e));g=!0,i.setItem(l,k),a(),c()}}function c(){h&&f._off("storage",b),j&&clearTimeout(j),i.removeItem(l)}var d=1e3,e=20,f=this,g=!1,h=!1,j=null;b()},f.prototype._cleanup_emit=d(100,function(){var a=this;a._transaction(function(){var a,b=Date.now(),c=b-m,d=0;try{a=JSON.parse(i.getItem(j)||"[]")}catch(e){a=[]}for(var f=a.length-1;f>=0;f--)a[f].timestamp<c&&(a.splice(f,1),d++);d>0&&i.setItem(j,JSON.stringify(a))})}),f.prototype._cleanup_once=d(100,function(){var a=this;a._transaction(function(){var b,c,d=(Date.now(),0);try{c=JSON.parse(i.getItem(k)||"{}")}catch(e){c={}}for(b in c)a._once_expired(b,c)&&(delete
2015-07-16 21:56:12 +00:00
x=""}if(b=b||this.options,a="undefined"==typeof a?this.pattern:a,"undefined"==typeof a)throw new Error("undefined pattern");if(b.nobrace||!a.match(/\{.*\}/))return[a];var d=!1;if("{"!==a.charAt(0)){this.debug(a);for(var e=null,f=0,g=a.length;g>f;f++){var h=a.charAt(f);if(this.debug(f,h),"\\"===h)d=!d;else if("{"===h&&!d){e=a.substr(0,f);break}}if(null===e)return this.debug("no sets"),[a];var i=m.call(this,a.substr(f),b);return i.map(function(a){return e+a})}var j=a.match(/^\{(-?[0-9]+)\.\.(-?[0-9]+)\}/);if(j){this.debug("numset",j[1],j[2]);for(var k,n=m.call(this,a.substr(j[0].length),b),o=+j[1],p="0"===j[1][0],q=j[1].length,r=+j[2],s=o>r?-1:1,t=[],f=o;f!=r+s;f+=s){k=p?l(f,q):f+"";for(var u=0,v=n.length;v>u;u++)t.push(k+n[u])}return t}var f=1,w=1,t=[],x="",d=!1;this.debug("Entering for");a:for(f=1,g=a.length;g>f;f++){var h=a.charAt(f);if(this.debug("",f,h),d)d=!1,x+="\\"+h;else switch(h){case"\\":d=!0;continue;case"{":w++,x+="{";continue;case"}":if(w--,0===w){c(),f++;break a}x+=h;continue;case",":1===w?c():x+=h;continue;default:x+=h;continue}}if(0!==w)return this.debug("didn't close",a),m.call(this,"\\"+a,b);this.debug("set",t),this.debug("suffix",a.substr(f));var n=m.call(this,a.substr(f),b),y=1===t.length;this.debug("set pre-expanded",t),t=t.map(function(a){return m.call(this,a,b)},this),this.debug("set expanded",t),t=t.reduce(function(a,b){return a.concat(b)}),y&&(t=t.map(function(a){return"{"+a+"}"}));for(var z=[],f=0,g=t.length;g>f;f++)for(var u=0,v=n.length;v>u;u++)z.push(t[f]+n[u]);return z}function n(a,b){function c(){if(f){switch(f){case"*":h+=x,i=!0;break;case"?":h+=w,i=!0;break;default:h+="\\"+f}p.debug("clearStateChar %j %j",f,h),f=!1}}var d=this.options;if(!d.noglobstar&&"**"===a)return u;if(""===a)return"";for(var e,f,g,h="",i=!!d.nocase,j=!1,k=[],l=!1,m=-1,n=-1,o="."===a.charAt(0)?"":d.dot?"(?!(?:^|\\/)\\.{1,2}(?:$|\\/))":"(?!\\.)",p=this,r=0,s=a.length;s>r&&(g=a.charAt(r));r++)if(this.debug("%s %s %s %j",a,r,h,g),j&&A[g])h+="\\"+g,j=!1;else switch(g){case"/":return!1;case"\\":c(),j=!0;continue;case"?":case"*":case"+":case"@":case"!":if(this.debug("%s %s %s %j <-- stateChar",a,r,h,g),l){this.debug(" in class"),"!"===g&&r===n+1&&(g="^"),h+=g;continue}p.debug("call clearStateChar %j",f),c(),f=g,d.noext&&c();continue;case"(":if(l){h+="(";continue}if(!f){h+="\\(";continue}e=f,k.push({type:e,start:r-1,reStart:h.length}),h+="!"===f?"(?:(?!":"(?:",this.debug("plType %j %j",f,h),f=!1;continue;case")":if(l||!k.length){h+="\\)";continue}switch(c(),i=!0,h+=")",e=k.pop().type){case"!":h+="[^/]*?)";break;case"?":case"+":case"*":h+=e;case"@":}continue;case"|":if(l||!k.length||j){h+="\\|",j=!1;continue}c(),h+="|";continue;case"[":if(c(),l){h+="\\"+g;continue}l=!0,n=r,m=h.length,h+=g;continue;case"]":if(r===n+1||!l){h+="\\"+g,j=!1;continue}i=!0,l=!1,h+=g;continue;default:c(),j?j=!1:!A[g]||"^"===g&&l||(h+="\\"),h+=g}if(l){var t=a.substr(n+1),v=this.parse(t,C);h=h.substr(0,m)+"\\["+v[0],i=i||v[1]}for(var y;y=k.pop();){var z=h.slice(y.reStart+3);z=z.replace(/((?:\\{2})*)(\\?)\|/g,function(a,b,c){return c||(c="\\"),b+b+c+"|"}),this.debug("tail=%j\n %s",z,z);var B="*"===y.type?x:"?"===y.type?w:"\\"+y.type;i=!0,h=h.slice(0,y.reStart)+B+"\\("+z}c(),j&&(h+="\\\\");var D=!1;switch(h.charAt(0)){case".":case"[":case"(":D=!0}if(""!==h&&i&&(h="(?=.)"+h),D&&(h=o+h),b===C)return[h,i];if(!i)return q(a);var E=d.nocase?"i":"",F=new RegExp("^"+h+"$",E);return F._glob=a,F._src=h,F}function o(){if(this.regexp||this.regexp===!1)return this.regexp;var a=this.set;if(!a.length)return this.regexp=!1;var b=this.options,c=b.noglobstar?x:b.dot?y:z,d=b.nocase?"i":"",e=a.map(function(a){return a.map(function(a){return a===u?c:"string"==typeof a?r(a):a._src}).join("\\/")}).join("|");e="^(?:"+e+")$",this.negate&&(e="^(?!"+e+").*$");try{return this.regexp=new RegExp(e,d)}catch(f){return this.regexp=!1}}function p(a,b){if(this.debug("match",a,this.pattern),this.comment)return!1;if(this.empty)return""===a;if("/"===a&&b)return!0;var c=this.options;"win32"===d&&(a=a.split("\\").join("/")),a=a.split(B),this.debug(this.pattern,"split",a);var e=this.set;this
ta.O_APPEND),Ga=ta.O_FLAGS,Ha=ta.XATTR_CREATE,Ia=ta.XATTR_REPLACE,Ja=ta.FS_NOMTIME,Ka=ta.FS_NOCTIME,La=a("../encoding.js"),Ma=a("../errors.js"),Na=a("../directory-entry.js"),Oa=a("../open-file-description.js"),Pa=a("../super-node.js"),Qa=a("../node.js"),Ra=a("../stats.js"),Sa=a("../buffer.js");b.exports={ensureRootDirectory:h,open:J,close:K,mknod:L,mkdir:M,rmdir:N,unlink:R,stat:O,fstat:P,link:Q,read:S,readFile:T,write:U,writeFile:V,appendFile:W,exists:X,getxattr:Y,fgetxattr:Z,setxattr:$,fsetxattr:_,removexattr:aa,fremovexattr:ba,lseek:ca,readdir:da,utimes:ea,futimes:fa,rename:ga,symlink:ha,readlink:ia,lstat:ja,truncate:ka,ftruncate:la}},{"../../lib/nodash.js":4,"../buffer.js":14,"../constants.js":15,"../directory-entry.js":16,"../encoding.js":17,"../errors.js":18,"../node.js":23,"../open-file-description.js":24,"../path.js":25,"../stats.js":33,"../super-node.js":34}],20:[function(a,b,c){function d(a){return"function"==typeof a?a:function(a){if(a)throw a}}function e(a){a&&console.error("Filer error: ",a)}function f(a,b){function c(){I.forEach(function(a){a.call(this)}.bind(F)),I=null}function d(a){return function(b){function c(b){var d=B();a.getObject(d,function(a,e){return a?void b(a):void(e?c(b):b(null,d))})}return g(j).contains(p)?void b(null,B()):void c(b)}}function f(a){if(a.length){var b=s.getInstance();a.forEach(function(a){b.emit(a.event,a.path)})}}a=a||{},b=b||e;var j=a.flags,B=a.guid?a.guid:v,C=a.provider||new q.Default(a.name||k),D=a.name||C.name,E=g(j).contains(l),F=this;F.readyState=n,F.name=D,F.error=null,F.stdin=w,F.stdout=x,F.stderr=y,this.Shell=r.bind(void 0,this);var G={},H=z;Object.defineProperty(this,"openFiles",{get:function(){return G}}),this.allocDescriptor=function(a){var b=H++;return G[b]=a,b},this.releaseDescriptor=function(a){delete G[a]};var I=[];this.queueOrRun=function(a){var b;return m==F.readyState?a.call(F):o==F.readyState?b=new u.EFILESYSTEMERROR("unknown error"):I.push(a),b},this.watch=function(a,b,c){if(h(a))throw new Error("Path must be a string without null bytes.");"function"==typeof b&&(c=b,b={}),b=b||{},c=c||i;var d=new t;return d.start(a,!1,b.recursive),d.on("change",c),d},C.open(function(a){function e(a){function e(a){var b=C[a]();return b.flags=j,b.changes=[],b.guid=d(b),b.close=function(){var a=b.changes;f(a),a.length=0},b}F.provider={openReadWriteContext:function(){return e("getReadWriteContext")},openReadOnlyContext:function(){return e("getReadOnlyContext")}},a?F.readyState=o:F.readyState=m,c(),b(a,F)}if(a)return e(a);var g=C.getReadWriteContext();g.guid=d(g),E?g.clear(function(a){return a?e(a):void A.ensureRootDirectory(g,e)}):A.ensureRootDirectory(g,e)})}var g=a("../../lib/nodash.js"),h=a("../path.js").isNull,i=a("../shared.js").nop,j=a("../constants.js"),k=j.FILE_SYSTEM_NAME,l=j.FS_FORMAT,m=j.FS_READY,n=j.FS_PENDING,o=j.FS_ERROR,p=j.FS_NODUPEIDCHECK,q=a("../providers/index.js"),r=a("../shell/shell.js"),s=a("../../lib/intercom.js"),t=a("../fs-watcher.js"),u=a("../errors.js"),v=a("../shared.js").guid,w=j.STDIN,x=j.STDOUT,y=j.STDERR,z=j.FIRST_DESCRIPTOR,A=a("./implementation.js");f.providers=q,["open","close","mknod","mkdir","rmdir","stat","fstat","link","unlink","read","readFile","write","writeFile","appendFile","exists","lseek","readdir","rename","readlink","symlink","lstat","truncate","ftruncate","utimes","futimes","setxattr","getxattr","fsetxattr","fgetxattr","removexattr","fremovexattr"].forEach(function(a){f.prototype[a]=function(){var b=this,c=Array.prototype.slice.call(arguments,0),e=c.length-1,f="function"!=typeof c[e],g=d(c[e]),h=b.queueOrRun(function(){function d(){h.close(),g.apply(b,arguments)}var h=b.provider.openReadWriteContext();if(o===b.readyState){var i=new u.EFILESYSTEMERROR("filesystem unavailable, operation canceled");return g.call(b,i)}f?c.push(d):c[e]=d;var j=[b,h].concat(c);A[a].apply(null,j)});h&&g(h)}}),b.exports=f},{"../../lib/intercom.js":3,"../../lib/nodash.js":4,"../constants.js":15,"../errors.js":18,"../fs-watcher.js":21,"../path.js":25,"../providers/index.js":26,"../shared.js":30,"../shell/shell.js":32,"./implementation.js":19}],21:[function(