filer/dist/idbfs.min.js

4 lines
550 KiB
JavaScript
Raw Normal View History

/*! idbfs 2013-11-21 */
(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 b.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,w.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],_[l]=!0,p.apply(e,n)}if(!t(v,l)&&!t(_,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=Object.prototype.hasOwnProperty,w=[].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,b=[];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)b[d]=g.require(l);else if("exports"===c)b[d]=g.exports(l),y=!0;else if("module"===c)o=b[d]=g.module(l);else if(t(v,c)||t(m,c)||t(_,c))b[d]=s(c);else{if(!p.p)throw Error(l+" missing "+c);p.p.load(p.n,i(r,!0),a(c),{}),b[d]=v[c]}f=u.apply(v[l],b),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||Rn),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)&&T(r[u],l)>-1}return T(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(Jn.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:In,isKeysFast:Au,noArgsEnum:bu,noCharByIndex:Eu,shadowed:Yn,top:"",useHas:!0,useStrict:Su,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?P: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=P;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?M: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(H,l)?H[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===P)return 0!==t?a(u):M;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===M)return P;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===P)return M;if(u.offset(1),n(t,0,127))return t;var r=l[t-128];return null===r?a(e):r}}function _(l,u){u.fatal,this.encode=function(u,e){var t=e.get();if(t===M)return P;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 b(l,u){var e=u.fatal,t=0,r=0,i=0;this.decode=function(u){var o=u.get();if(o===P&&0===t&&0===r&&0===i)return M;o!==P||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 w(l,e){e.fatal,this.encode=function(e,t){var r=t.get();if(r===M)return P;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,
if(u){var a=i.clear();a.onsuccess=function(){s(o,n)},a.onerror=function(l){n(l)}}else n()},t.onerror=function(l){this.readyState=Z,this.error=l};var r=1,i={};this.readyState=J,this.db=null,this.nextDescriptor=r,this.openFiles=i,this.name=l,this.error=null,this.queue=[]}function k(l){this.transaction=l}function j(){}var O=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,A=l("lodash");l("encoding-indexes"),l("encoding");var S=l("src/path").normalize,I=l("src/path").dirname,B=l("src/path").basename,D=l("src/shared").guid,L=l("src/shared").hash;l("src/shared").nop;var R=l("src/error").EExists,C=l("src/error").EIsDirectory,F=l("src/error").ENoEntry,N=l("src/error").EBusy,T=l("src/error").ENotEmpty,P=l("src/error").ENotDirectory,M=l("src/error").EBadFileDescriptor;l("src/error").ENotImplemented,l("src/error").ENotMounted;var q=l("src/error").EInvalid,z=l("src/error").EIO,H=l("src/error").EFileSystemError,U=l("src/constants").FS_FORMAT,$=l("src/constants").MODE_FILE,K=l("src/constants").MODE_DIRECTORY,Y=l("src/constants").ROOT_DIRECTORY_NAME,W=l("src/constants").ROOT_NODE_ID,V=l("src/constants").IDB_RW;l("src/constants").IDB_RO;var G=l("src/constants").FILE_STORE_NAME,X=l("src/constants").METADATA_STORE_NAME,Q=l("src/constants").FS_READY,J=l("src/constants").FS_PENDING,Z=l("src/constants").FS_ERROR,ln=l("src/constants").O_READ,nn=l("src/constants").O_WRITE,un=l("src/constants").O_CREATE,en=l("src/constants").O_EXCLUSIVE;l("src/constants").O_TRUNCATE;var tn=l("src/constants").O_APPEND,rn=l("src/constants").O_FLAGS;return w.prototype._allocate_descriptor=function(l){var n=this.nextDescriptor++;return this.openFiles[n]=l,n},w.prototype._release_descriptor=function(l){delete this.openFiles[l]},w.prototype._queueOrRun=function(l){var n=void 0;return Q==this.readyState?l.call(this):Z==this.readyState?n=new H("unknown error"):this.queue.push(l),n},w.prototype._runQueued=function(){this.queue.forEach(function(l){l.call(this)}.bind(this)),this.queue=null},w.prototype._open=function(l,n,e,t){function r(l,n){if(l)t(l);else{var r;r=A(e).contains(tn)?n.size:0;var o=new u(n.id,e,r),a=i._allocate_descriptor(o);t(void 0,a)}}var i=this;e=b(e),e||t(new q("flags is not valid")),p(i,l,n,e,r)},w.prototype._close=function(l,n){A(this.openFiles).has(l)?(this._release_descriptor(l),n(void 0)):n(new M("invalid file descriptor"))},w.prototype._mkdir=function(l,n,u){function e(l){l?u(l):u(void 0)}c(l,n,e)},w.prototype._rmdir=function(l,n,u){function e(l){l?u(l):u(void 0)}f(l,n,e)},w.prototype._stat=function(l,n,u){function e(l,n){if(l)u(l);else{var e=new t(n,r.name);u(void 0,e)}}var r=this;g(l,n,e)},w.prototype._fstat=function(l,n,u){function e(l,n){if(l)u(l);else{var e=new t(n,r.name);u(void 0,e)}}var r=this,i=r.openFiles[n];i?v(l,i,e):u(new M("invalid file descriptor"))},w.prototype._link=function(l,n,u,e){function t(l){l?e(l):e(void 0)}m(l,n,u,t)},w.prototype._unlink=function(l,n,u){function e(l){l?u(l):u(void 0)}y(l,n,e)},w.prototype._read=function(l,n,u,e,t,r,i){function o(l,n){l?i(l):i(void 0,n)}var a=this;e=void 0===e?0:e,t=void 0===t?u.length-e:t;var s=a.openFiles[n];s?A(s.flags).contains(ln)?h(l,s,u,e,t,r,o):i(new M("descriptor does not permit reading")):i(new M("invalid file descriptor"))},w.prototype._readFile=function(l,n,e,r){var i=this;e?"function"==typeof e?(r=e,e={encoding:null,flag:"r"}):"string"==typeof e&&(e={encoding:e,flag:"r"}):e={encoding:null,flag:"r"};var o=b(e.flag||"r");o||r(new q("flags is not valid")),p(i,l,n,o,function(n,a){if(n)return r(n);var s=new u(a.id,o,0),c=i._allocate_descriptor(s);v(l,s,function(n,u){if(n)return r(n);var o=new t(u,i.name),a=o.size,f=new Uint8Array(a);h(l,s,f,0,a,0,function(l){if(l)return r(l);i._release_descriptor(c);var n;n="utf8"===e.encoding?new TextDecoder("utf-8").decode(f):f,r(void 0,n)})})})},w.prototype._write=function(l,n,u,e,t,r,i){function o(l,n){l?i(l):i(void 0,n)}var a=this;e=void 0===e?0:e,t=void 0===t?u.length-e:t;var s=a.openFiles[n];s?A(s.flags).contains(nn)?t>u.length-e?i(new z("intput buffer is too small")):d(l,s,u,e,t,r,o):i(new M("descriptor doe