filer/dist/idbfs.min.js

4 lines
554 KiB
JavaScript
Raw Normal View History

2013-11-15 20:11:09 +00:00
/*! idbfs 2013-11-15 */
(function(l,n){"object"==typeof exports?module.exports=n():"function"==typeof define&&define.amd?define(n):l.IDBFS||(l.IDBFS=n())})(this,function(){var l,n,u;(function(e){function t(l,n){return w.call(l,n)}function r(l,n){var u,e,t,r,i,o,a,s,c,f,p=n&&n.split("/"),d=y.map,h=d&&d["*"]||{};if(l&&"."===l.charAt(0))if(n){for(p=p.slice(0,p.length-1),l=p.concat(l.split("/")),s=0;l.length>s;s+=1)if(f=l[s],"."===f)l.splice(s,1),s-=1;else if(".."===f){if(1===s&&(".."===l[2]||".."===l[0]))break;s>0&&(l.splice(s-1,2),s-=2)}l=l.join("/")}else 0===l.indexOf("./")&&(l=l.substring(2));if((p||h)&&d){for(u=l.split("/"),s=u.length;s>0;s-=1){if(e=u.slice(0,s).join("/"),p)for(c=p.length;c>0;c-=1)if(t=d[p.slice(0,c).join("/")],t&&(t=t[e])){r=t,i=s;break}if(r)break;!o&&h&&h[e]&&(o=h[e],a=s)}!r&&o&&(r=o,i=a),r&&(u.splice(0,i,r),l=u.join("/"))}return l}function i(l,n){return function(){return d.apply(e,_.call(arguments,0).concat([l,n]))}}function o(l){return function(n){return r(n,l)}}function a(l){return function(n){v[l]=n}}function s(l){if(t(m,l)){var n=m[l];delete m[l],b[l]=!0,p.apply(e,n)}if(!t(v,l)&&!t(b,l))throw Error("No "+l);return v[l]}function c(l){var n,u=l?l.indexOf("!"):-1;return u>-1&&(n=l.substring(0,u),l=l.substring(u+1,l.length)),[n,l]}function f(l){return function(){return y&&y.config&&y.config[l]||{}}}var p,d,h,g,v={},m={},y={},b={},w=Object.prototype.hasOwnProperty,_=[].slice;h=function(l,n){var u,e=c(l),t=e[0];return l=e[1],t&&(t=r(t,n),u=s(t)),t?l=u&&u.normalize?u.normalize(l,o(n)):r(l,n):(l=r(l,n),e=c(l),t=e[0],l=e[1],t&&(u=s(t))),{f:t?t+"!"+l:l,n:l,pr:t,p:u}},g={require:function(l){return i(l)},exports:function(l){var n=v[l];return n!==void 0?n:v[l]={}},module:function(l){return{id:l,uri:"",exports:v[l],config:f(l)}}},p=function(l,n,u,r){var o,c,f,p,d,y,w=[];if(r=r||l,"function"==typeof u){for(n=!n.length&&u.length?["require","exports","module"]:n,d=0;n.length>d;d+=1)if(p=h(n[d],r),c=p.f,"require"===c)w[d]=g.require(l);else if("exports"===c)w[d]=g.exports(l),y=!0;else if("module"===c)o=w[d]=g.module(l);else if(t(v,c)||t(m,c)||t(b,c))w[d]=s(c);else{if(!p.p)throw Error(l+" missing "+c);p.p.load(p.n,i(r,!0),a(c),{}),w[d]=v[c]}f=u.apply(v[l],w),l&&(o&&o.exports!==e&&o.exports!==v[l]?v[l]=o.exports:f===e&&y||(v[l]=f))}else l&&(v[l]=u)},l=n=d=function(l,n,u,t,r){return"string"==typeof l?g[l]?g[l](n):s(h(l,n).f):(l.splice||(y=l,n.splice?(l=n,n=u,u=null):l=e),n=n||function(){},"function"==typeof u&&(u=t,t=r),t?p(e,l,n,u):setTimeout(function(){p(e,l,n,u)},4),d)},d.config=function(l){return y=l,y.deps&&d(y.deps,y.callback),d},u=function(l,n,u){n.splice||(u=n,n=[]),t(v,l)||t(m,l)||(m[l]=[l,n,u])},u.amd={jQuery:!0}})(),u("build/almond",function(){}),function(l,n){function e(l){return l&&l.__wrapped__?l:this instanceof e?(this.__wrapped__=l,n):new e(l)}function t(l,n,u){n||(n=0);var e=l.length,t=e-n>=(u||Cn),r=t?{}:l;if(t)for(var i,o=n-1;e>++o;)i=l[o]+"",(Gn.call(r,i)?r[i]:r[i]=[]).push(l[o]);return function(l){if(t){var u=l+"";return Gn.call(r,u)&&F(r[u],l)>-1}return F(r,l,n)>-1}}function r(l,u){var e=l.index,t=u.index;if(l=l.criteria,u=u.criteria,l!==u){if(l>u||l===n)return 1;if(u>l||u===n)return-1}return t>e?-1:1}function i(l,n,u){function e(){var o=arguments,a=r?this:n;if(t||(l=n[i]),u.length&&(o=o.length?u.concat(Qn.call(o)):u),this instanceof e){f.prototype=l.prototype,a=new f;var s=l.apply(a,o);return s&&Lu[typeof s]?s:a}return l.apply(a,o)}var t=h(l),r=!u,i=l;return r&&(u=n),e}function o(l,u){return l?"function"!=typeof l?function(n){return n[l]}:u!==n?function(n,e,t){return l.call(u,n,e,t)}:l:dn}function a(){for(var l=-1,n=arguments.length,u={bottom:"",hasDontEnumBug:Sn,isKeysFast:Ou,noArgsEnum:wu,noCharByIndex:Eu,shadowed:Yn,top:"",useHas:!0,useStrict:Iu,arrayBranch:{},objectBranch:{}};n>++l;){var e=arguments[l];for(var t in e){var i=e[t];/beforeLoop|inLoop/.test(t)?("string"==typeof i&&(i={array:i,object:i}),u.arrayBranch[t]=i.array,u.objectBranch[t]=i.object):u[t]=i}}var a=u.args,s=/^[^,]+/.exec(a)[0],c=u.init;u.firstArg=s,u.init=null==c?s:c,"collection"==s&&u.arrayBranch.inLoop||(u.arrayBranch=null);var f=Function("array
}function u(l,n){return Math.floor(l/n)}function e(l){var n=0;this.get=function(){return n>=l.length?M:Number(l[n])},this.offset=function(u){if(n+=u,0>n)throw Error("Seeking past start of the buffer");if(n>l.length)throw Error("Seeking past EOF")},this.match=function(u){if(u.length>n+l.length)return!1;var e;for(e=0;u.length>e;e+=1)if(Number(l[n+e])!==u[e])return!1;return!0}}function t(l){var n=0;this.emit=function(){var u,e=M;for(u=0;arguments.length>u;++u)e=Number(arguments[u]),l[n++]=e;return e}}function r(l){function u(l){for(var u=[],e=0,t=l.length;l.length>e;){var r=l.charCodeAt(e);if(n(r,55296,57343))if(n(r,56320,57343))u.push(65533);else if(e===t-1)u.push(65533);else{var i=l.charCodeAt(e+1);if(n(i,56320,57343)){var o=1023&r,a=1023&i;e+=1,u.push(65536+(o<<10)+a)}else u.push(65533)}else u.push(r);e+=1}return u}var e=0,t=u(l);this.offset=function(l){if(e+=l,0>e)throw Error("Seeking past start of the buffer");if(e>t.length)throw Error("Seeking past EOF")},this.get=function(){return e>=t.length?P:t[e]}}function i(){var l="";this.string=function(){return l},this.emit=function(n){65535>=n?l+=String.fromCharCode(n):(n-=65536,l+=String.fromCharCode(55296+(1023&n>>10)),l+=String.fromCharCode(56320+(1023&n)))}}function o(l){this.name="EncodingError",this.message=l,this.code=0}function a(l,n){if(l)throw new o("Decoder error");return n||65533}function s(l){throw new o("The code point "+l+" could not be encoded.")}function c(l){return l=(l+"").trim().toLowerCase(),Object.prototype.hasOwnProperty.call(U,l)?U[l]:null}function f(l,n){return(n||[])[l]||null}function p(l,n){var u=n.indexOf(l);return-1===u?null:u}function d(n){if(!("encoding-indexes"in l))throw Error("Indexes missing. Did you forget to include encoding-indexes.js?");return l["encoding-indexes"][n]}function h(l){if(l>39419&&189e3>l||l>1237575)return null;var n,u=0,e=0,t=d("gb18030");for(n=0;t.length>n;++n){var r=t[n];if(!(l>=r[0]))break;u=r[0],e=r[1]}return e+l-u}function g(l){var n,u=0,e=0,t=d("gb18030");for(n=0;t.length>n;++n){var r=t[n];if(!(l>=r[1]))break;u=r[1],e=r[0]}return e+l-u}function v(l){var u=l.fatal,e=0,t=0,r=0,i=0;this.decode=function(l){var o=l.get();if(o===M)return 0!==t?a(u):P;if(l.offset(1),0===t){if(n(o,0,127))return o;if(n(o,194,223))t=1,i=128,e=o-192;else if(n(o,224,239))t=2,i=2048,e=o-224;else{if(!n(o,240,244))return a(u);t=3,i=65536,e=o-240}return e*=Math.pow(64,t),null}if(!n(o,128,191))return e=0,t=0,r=0,i=0,l.offset(-1),a(u);if(r+=1,e+=(o-128)*Math.pow(64,t-r),r!==t)return null;var s=e,c=i;return e=0,t=0,r=0,i=0,n(s,c,1114111)&&!n(s,55296,57343)?s:a(u)}}function m(l){l.fatal,this.encode=function(l,e){var t=e.get();if(t===P)return M;if(e.offset(1),n(t,55296,57343))return s(t);if(n(t,0,127))return l.emit(t);var r,i;n(t,128,2047)?(r=1,i=192):n(t,2048,65535)?(r=2,i=224):n(t,65536,1114111)&&(r=3,i=240);for(var o=l.emit(u(t,Math.pow(64,r))+i);r>0;){var a=u(t,Math.pow(64,r-1));o=l.emit(128+a%64),r-=1}return o}}function y(l,u){var e=u.fatal;this.decode=function(u){var t=u.get();if(t===M)return P;if(u.offset(1),n(t,0,127))return t;var r=l[t-128];return null===r?a(e):r}}function b(l,u){u.fatal,this.encode=function(u,e){var t=e.get();if(t===P)return M;if(e.offset(1),n(t,0,127))return u.emit(t);var r=p(t,l);return null===r&&s(t),u.emit(r+128)}}function w(l,u){var e=u.fatal,t=0,r=0,i=0;this.decode=function(u){var o=u.get();if(o===M&&0===t&&0===r&&0===i)return P;o!==M||0===t&&0===r&&0===i||(t=0,r=0,i=0,a(e)),u.offset(1);var s;if(0!==i)return s=null,n(o,48,57)&&(s=h(10*(126*(10*(t-129)+(r-48))+(i-129))+o-48)),t=0,r=0,i=0,null===s?(u.offset(-3),a(e)):s;if(0!==r)return n(o,129,254)?(i=o,null):(u.offset(-2),t=0,r=0,a(e));if(0!==t){if(n(o,48,57)&&l)return r=o,null;var c=t,p=null;t=0;var g=127>o?64:65;return(n(o,64,126)||n(o,128,254))&&(p=190*(c-129)+(o-g)),s=null===p?null:f(p,d("gbk")),null===p&&u.offset(-1),null===s?a(e):s}return n(o,0,127)?o:128===o?8364:n(o,129,254)?(t=o,null):a(e)}}function _(l,e){e.fatal,this.encode=function(e,t){var r=t.get();if(r===P)return M;if(t.offset(1),n(r,0,127))return e.emit(r);var i=p(r,d("gbk"));if(null!==i){var o=u(i,190)+129,
n.objectStoreNames.contains(W)&&n.deleteObjectStore(W),n.createObjectStore(W),n.objectStoreNames.contains(V)&&n.deleteObjectStore(V),n.createObjectStore(V),u=!0},r.onsuccess=function(l){function n(l){e.db=r,l?(e.readyState=J,t.reject(l)):(e.readyState=G,t.resolve())}var r=l.target.result,i=r.transaction([W],K),o=i.objectStore(W);if(u){var a=o.clear();a.onsuccess=function(){s(o,n)},a.onerror=function(l){n(l)}}else n()},r.onerror=function(l){this.readyState=J,t.reject(l)};var i=1,o={};this.readyState=X,this.db=null,this.nextDescriptor=i,this.openFiles=o,this.name=l}var x=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,E=l("lodash"),j=l("when");l("encoding-indexes"),l("encoding");var k=l("src/path").normalize,A=l("src/path").dirname,O=l("src/path").basename,I=l("src/shared").guid,S=l("src/shared").hash;l("src/shared").nop;var B=l("src/error").EExists,D=l("src/error").EIsDirectory,L=l("src/error").ENoEntry,C=l("src/error").EBusy,R=l("src/error").ENotEmpty,T=l("src/error").ENotDirectory,N=l("src/error").EBadFileDescriptor;l("src/error").ENotImplemented,l("src/error").ENotMounted;var F=l("src/error").EInvalid,M=l("src/error").EIO,P=l("src/error").EFileSystemError,z=l("src/constants").FS_FORMAT,H=l("src/constants").MODE_FILE,U=l("src/constants").MODE_DIRECTORY,q=l("src/constants").ROOT_DIRECTORY_NAME,$=l("src/constants").ROOT_NODE_ID,K=l("src/constants").IDB_RW,Y=l("src/constants").IDB_RO,W=l("src/constants").FILE_STORE_NAME,V=l("src/constants").METADATA_STORE_NAME,G=l("src/constants").FS_READY,X=l("src/constants").FS_PENDING,J=l("src/constants").FS_ERROR,Q=l("src/constants").O_READ,Z=l("src/constants").O_WRITE,ln=l("src/constants").O_CREATE,nn=l("src/constants").O_EXCLUSIVE;l("src/constants").O_TRUNCATE;var un=l("src/constants").O_APPEND,en=l("src/constants").O_FLAGS;return _.prototype._allocate_descriptor=function(l){var n=this.nextDescriptor++;return this.openFiles[n]=l,n},_.prototype._release_descriptor=function(l){delete this.openFiles[l]},_.prototype.open=function(l,n,e){var t=this;this.promise.then(function(){function r(l,e){if(l)i.reject(l);else{var r;r=E(n).contains(un)?e.size:0;var o=new u(e.id,n,r),a=t._allocate_descriptor(o);i.resolve(a)}}var i=j.defer(),o=t.db.transaction([W],K),a=o.objectStore(W);n=w(n),n||i.reject(new F("flags is not valid")),p(t,a,l,n,r),i.promise.then(function(l){e(void 0,l)},function(l){e(l)})},function(){e(new P("unknown error"))})},_.prototype.close=function(l,n){var u=j.defer();E(this.openFiles).has(l)?(this._release_descriptor(l),u.resolve()):u.reject(new N("invalid file descriptor")),u.promise.then(function(){n()},function(l){n(l)})},_.prototype.mkdir=function(l,n){var u=this;this.promise.then(function(){function e(l){l?t.reject(l):t.resolve()}var t=j.defer(),r=u.db.transaction([W],K),i=r.objectStore(W);c(i,l,e),t.promise.then(function(){n()},function(l){n(l)})},function(){n(new P("unknown error"))})},_.prototype.rmdir=function(l,n){var u=this;this.promise.then(function(){function e(l){l?t.reject(l):t.resolve()}var t=j.defer(),r=u.db.transaction([W],K),i=r.objectStore(W);f(i,l,e),t.promise.then(function(){n()},function(l){n(l)})},function(){n(new P("unknown error"))})},_.prototype.stat=function(l,n){var u=this;this.promise.then(function(){function e(l,n){if(l)r.reject(l);else{var e=new t(n,u.name);r.resolve(e)}}var r=j.defer(),i=u.db.transaction([W],K),o=i.objectStore(W);g(o,l,e),r.promise.then(function(l){n(void 0,l)},function(l){n(l)})},function(){n(new P("unknown error"))})},_.prototype.fstat=function(l,n){var u=this;this.promise.then(function(){function e(l,n){if(l)r.reject(l);else{var e=new t(n,u.name);r.resolve(e)}}var r=j.defer(),i=u.db.transaction([W],K),o=i.objectStore(W),a=u.openFiles[l];a?v(o,a,e):r.reject(new N("invalid file descriptor")),r.promise.then(function(l){n(void 0,l)},function(l){n(l)})},function(){n(new P("unknown error"))})},_.prototype.link=function(l,n,u){var e=this;this.promise.then(function(){function t(l){l?r.reject(l):r.resolve()}var r=j.defer(),i=e.db.transaction([W],K),o=i.objectStore(W);m(o,l,n,t),r.promise.then(function(