4 lines
554 KiB
JavaScript
4 lines
554 KiB
JavaScript
|
/*! idbfs 2013-11-12 */
|
||
|
(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,s,a,c,f,p=n&&n.split("/"),h=y.map,d=h&&h["*"]||{};if(l&&"."===l.charAt(0))if(n){for(p=p.slice(0,p.length-1),l=p.concat(l.split("/")),a=0;l.length>a;a+=1)if(f=l[a],"."===f)l.splice(a,1),a-=1;else if(".."===f){if(1===a&&(".."===l[2]||".."===l[0]))break;a>0&&(l.splice(a-1,2),a-=2)}l=l.join("/")}else 0===l.indexOf("./")&&(l=l.substring(2));if((p||d)&&h){for(u=l.split("/"),a=u.length;a>0;a-=1){if(e=u.slice(0,a).join("/"),p)for(c=p.length;c>0;c-=1)if(t=h[p.slice(0,c).join("/")],t&&(t=t[e])){r=t,i=a;break}if(r)break;!o&&d&&d[e]&&(o=d[e],s=a)}!r&&o&&(r=o,i=s),r&&(u.splice(0,i,r),l=u.join("/"))}return l}function i(l,n){return function(){return h.apply(e,_.call(arguments,0).concat([l,n]))}}function o(l){return function(n){return r(n,l)}}function s(l){return function(n){v[l]=n}}function a(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,h,d,g,v={},m={},y={},b={},w=Object.prototype.hasOwnProperty,_=[].slice;d=function(l,n){var u,e=c(l),t=e[0];return l=e[1],t&&(t=r(t,n),u=a(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=a(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,h,y,w=[];if(r=r||l,"function"==typeof u){for(n=!n.length&&u.length?["require","exports","module"]:n,h=0;n.length>h;h+=1)if(p=d(n[h],r),c=p.f,"require"===c)w[h]=g.require(l);else if("exports"===c)w[h]=g.exports(l),y=!0;else if("module"===c)o=w[h]=g.module(l);else if(t(v,c)||t(m,c)||t(b,c))w[h]=a(c);else{if(!p.p)throw Error(l+" missing "+c);p.p.load(p.n,i(r,!0),s(c),{}),w[h]=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=h=function(l,n,u,t,r){return"string"==typeof l?g[l]?g[l](n):a(d(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),h)},h.config=function(l){return y=l,y.deps&&h(y.deps,y.callback),h},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,s=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,s=new f;var a=l.apply(s,o);return a&&Lu[typeof a]?a:s}return l.apply(s,o)}var t=d(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:hn}function s(){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 s=u.args,a=/^[^,]+/.exec(s)[0],c=u.init;u.firstArg=a,u.init=null==c?a:c,"collection"==a&&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,s=1023&i;e+=1,u.push(65536+(o<<10)+s)}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 s(l,n){if(l)throw new o("Decoder error");return n||65533}function a(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 h(n){if(!("encoding-indexes"in l))throw Error("Indexes missing. Did you forget to include encoding-indexes.js?");return l["encoding-indexes"][n]}function d(l){if(l>39419&&189e3>l||l>1237575)return null;var n,u=0,e=0,t=h("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=h("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?s(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 s(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),s(u);if(r+=1,e+=(o-128)*Math.pow(64,t-r),r!==t)return null;var a=e,c=i;return e=0,t=0,r=0,i=0,n(a,c,1114111)&&!n(a,55296,57343)?a:s(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 a(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 s=u(t,Math.pow(64,r-1));o=l.emit(128+s%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?s(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&&a(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,s(e)),u.offset(1);var a;if(0!==i)return a=null,n(o,48,57)&&(a=d(10*(126*(10*(t-129)+(r-48))+(i-129))+o-48)),t=0,r=0,i=0,null===a?(u.offset(-3),s(e)):a;if(0!==r)return n(o,129,254)?(i=o,null):(u.offset(-2),t=0,r=0,s(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)),a=null===p?null:f(p,h("gbk")),null===p&&u.offset(-1),null===a?s(e):a}return n(o,0,127)?o:128===o?8364:n(o,129,254)?(t=o,null):s(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,h("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 s=o.clear();s.onsuccess=function(){a(o,n)},s.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),s=t._allocate_descriptor(o);i.resolve(s)}}var i=j.defer(),o=t.db.transaction([W],K),s=o.objectStore(W);n=w(n),n||i.reject(new F("flags is not valid")),p(this,s,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),s=u.openFiles[l];s?v(o,s,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(functi
|