From 7e59e3a6848368c912fa0c1041b41dddac3ff100 Mon Sep 17 00:00:00 2001 From: Alan Kligman Date: Thu, 7 Nov 2013 15:55:14 -0500 Subject: [PATCH] support for readdir --- README.md | 4 +++ dist/idbfs.js | 59 ++++++++++++++++++++++++++++++++ dist/idbfs.min.js | 3 -- examples/refactoring-test.html | 4 +++ src/file-system.js | 59 ++++++++++++++++++++++++++++++++ tests/spec/idbfs.spec.js | 61 ++++++++++++++++++++++++++++++++++ 6 files changed, 187 insertions(+), 3 deletions(-) delete mode 100644 dist/idbfs.min.js diff --git a/README.md b/README.md index 7a74579..1f00d48 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,7 @@ The callback gets `(error, nbytes)`, where `nbytes` is the number of bytes read. #### fs.lseek(fd, offset, whence, callback) Asynchronous lseek(2), where `whence` can be `SET`, `CUR`, or `END`. Callback gets `(error, pos)`, where `pos` is the resulting offset, in bytes, from the beginning of the file. + +#### fs.readdir(path, callback) + +Asynchronous readdir(3). Reads the contents of a directory. Callback gets `(error, files)`, where `files` is an array containing the names of each file in the directory, excluding `.` and `..`. \ No newline at end of file diff --git a/dist/idbfs.js b/dist/idbfs.js index 9a1df1f..a16ab2c 100644 --- a/dist/idbfs.js +++ b/dist/idbfs.js @@ -6548,6 +6548,35 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p } }; + function read_directory(objectStore, path, callback) { + path = normalize(path); + var name = basename(path); + + var directoryNode; + var directoryData; + + find_node(objectStore, path, read_directory_data); + + function read_directory_data(error, result) { + if(error) { + callback(error); + } else { + directoryNode = result; + read_object(objectStore, directoryNode.data, handle_directory_data); + } + }; + + function handle_directory_data(error, result) { + if(error) { + callback(error); + } else { + directoryData = result; + var files = Object.keys(directoryData); + callback(undefined, files); + } + }; + }; + /* * FileSystem */ @@ -7059,7 +7088,37 @@ define('src/file-system',['require','lodash','when','src/path','src/path','src/p ); }; FileSystem.prototype.readdir = function readdir(path, callback) { + var that = this; + this.promise.then( + function() { + var deferred = when.defer(); + var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW); + var files = transaction.objectStore(FILE_STORE_NAME); + function check_result(error, files) { + if(error) { + // if(transaction.error) transaction.abort(); + deferred.reject(error); + } else { + deferred.resolve(files); + } + }; + + read_directory(files, path, check_result); + + deferred.promise.then( + function(result) { + callback(undefined, result); + }, + function(error) { + callback(error); + } + ); + }, + function() { + callback(new EFileSystemError('unknown error')); + } + ); }; FileSystem.prototype.utimes = function utimes(path, atime, mtime, callback) { diff --git a/dist/idbfs.min.js b/dist/idbfs.min.js deleted file mode 100644 index 36e68d4..0000000 --- a/dist/idbfs.min.js +++ /dev/null @@ -1,3 +0,0 @@ -/*! idbfs 2013-07-29 */ -(function(n,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define(t):n.IDBFS||(n.IDBFS=t())})(this,function(){var n,t,e;(function(r){function o(n,t){return _.call(n,t)}function i(n,t){var e,r,o,i,a,c,s,u,l,f,p=t&&t.split("/"),h=m.map,d=h&&h["*"]||{};if(n&&"."===n.charAt(0))if(t){for(p=p.slice(0,p.length-1),n=p.concat(n.split("/")),u=0;n.length>u;u+=1)if(f=n[u],"."===f)n.splice(u,1),u-=1;else if(".."===f){if(1===u&&(".."===n[2]||".."===n[0]))break;u>0&&(n.splice(u-1,2),u-=2)}n=n.join("/")}else 0===n.indexOf("./")&&(n=n.substring(2));if((p||d)&&h){for(e=n.split("/"),u=e.length;u>0;u-=1){if(r=e.slice(0,u).join("/"),p)for(l=p.length;l>0;l-=1)if(o=h[p.slice(0,l).join("/")],o&&(o=o[r])){i=o,a=u;break}if(i)break;!c&&d&&d[r]&&(c=d[r],s=u)}!i&&c&&(i=c,a=s),i&&(e.splice(0,a,i),n=e.join("/"))}return n}function a(n,t){return function(){return h.apply(r,x.call(arguments,0).concat([n,t]))}}function c(n){return function(t){return i(t,n)}}function s(n){return function(t){g[n]=t}}function u(n){if(o(y,n)){var t=y[n];delete y[n],b[n]=!0,p.apply(r,t)}if(!o(g,n)&&!o(b,n))throw Error("No "+n);return g[n]}function l(n){var t,e=n?n.indexOf("!"):-1;return e>-1&&(t=n.substring(0,e),n=n.substring(e+1,n.length)),[t,n]}function f(n){return function(){return m&&m.config&&m.config[n]||{}}}var p,h,d,v,g={},y={},m={},b={},_=Object.prototype.hasOwnProperty,x=[].slice;d=function(n,t){var e,r=l(n),o=r[0];return n=r[1],o&&(o=i(o,t),e=u(o)),o?n=e&&e.normalize?e.normalize(n,c(t)):i(n,t):(n=i(n,t),r=l(n),o=r[0],n=r[1],o&&(e=u(o))),{f:o?o+"!"+n:n,n:n,pr:o,p:e}},v={require:function(n){return a(n)},exports:function(n){var t=g[n];return t!==void 0?t:g[n]={}},module:function(n){return{id:n,uri:"",exports:g[n],config:f(n)}}},p=function(n,t,e,i){var c,l,f,p,h,m,_=[];if(i=i||n,"function"==typeof e){for(t=!t.length&&e.length?["require","exports","module"]:t,h=0;t.length>h;h+=1)if(p=d(t[h],i),l=p.f,"require"===l)_[h]=v.require(n);else if("exports"===l)_[h]=v.exports(n),m=!0;else if("module"===l)c=_[h]=v.module(n);else if(o(g,l)||o(y,l)||o(b,l))_[h]=u(l);else{if(!p.p)throw Error(n+" missing "+l);p.p.load(p.n,a(i,!0),s(l),{}),_[h]=g[l]}f=e.apply(g[n],_),n&&(c&&c.exports!==r&&c.exports!==g[n]?g[n]=c.exports:f===r&&m||(g[n]=f))}else n&&(g[n]=e)},n=t=h=function(n,t,e,o,i){return"string"==typeof n?v[n]?v[n](t):u(d(n,t).f):(n.splice||(m=n,t.splice?(n=t,t=e,e=null):n=r),t=t||function(){},"function"==typeof e&&(e=o,o=i),o?p(r,n,t,e):setTimeout(function(){p(r,n,t,e)},4),h)},h.config=function(n){return m=n,m.deps&&h(m.deps,m.callback),h},e=function(n,t,e){t.splice||(e=t,t=[]),o(g,n)||o(y,n)||(y[n]=[n,t,e])},e.amd={jQuery:!0}})(),e("build/almond",function(){}),function(n,t){function r(n){return n&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,t):new r(n)}function o(n,t,e){t||(t=0);var r=n.length,o=r-t>=(e||Dt),i=o?{}:n;if(o)for(var a,c=t-1;r>++c;)a=n[c]+"",(Gt.call(i,a)?i[a]:i[a]=[]).push(n[c]);return function(n){if(o){var e=n+"";return Gt.call(i,e)&&C(i[e],n)>-1}return C(i,n,t)>-1}}function i(n,e){var r=n.index,o=e.index;if(n=n.criteria,e=e.criteria,n!==e){if(n>e||n===t)return 1;if(e>n||e===t)return-1}return o>r?-1:1}function a(n,t,e){function r(){var c=arguments,s=i?this:t;if(o||(n=t[a]),e.length&&(c=c.length?e.concat(Jt.call(c)):e),this instanceof r){f.prototype=n.prototype,s=new f;var u=n.apply(s,c);return u&&Le[typeof u]?u:s}return n.apply(s,c)}var o=d(n),i=!e,a=n;return i&&(e=t),r}function c(n,e){return n?"function"!=typeof n?function(t){return t[n]}:e!==t?function(t,r,o){return n.call(e,t,r,o)}:n:pt}function s(){for(var n=-1,t=arguments.length,e={bottom:"",hasDontEnumBug:It,isKeysFast:Ae,noArgsEnum:be,noCharByIndex:we,shadowed:Yt,top:"",useHas:!0,useStrict:Oe,arrayBranch:{},objectBranch:{}};t>++n;){var r=arguments[n];for(var o in r){var a=r[o];/beforeLoop|inLoop/.test(o)?("string"==typeof a&&(a={array:a,object:a}),e.arrayBranch[o]=a.array,e.objectBranch[o]=a.object):e[o]=a}}var s=e.args,u=/^[^,]+/.exec(s)[0],l=e.init;e.firstArg=u,e.init=null==l?u:l,"collection"==u&&e.arrayBranch.inLoop||(e.arrayBranch=null);var f=Function("arrayLikeClasses, ArrayProto, bind, compareAscending, concat, createCallback, forIn, hasOwnProperty, indexOf, isArguments, isArray, isFunction, isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, slice, stringClass, toString, undefined","var callee = function("+s+") {\n"+Re(e)+"\n};\n"+"return callee");return f(Se,At,nt,i,Kt,c,Je,Gt,C,h,$e,d,Ye,de,Le,oe,Xt,Jt,ge,Qt)}function u(n){return"\\"+De[n]}function l(n){return Ke[n]}function f(){}function p(n){return Ge[n]}function h(n){return Qt.call(n)==se}function d(n){return"function"==typeof n}function v(n){var t=!1;if(!n||"object"!=typeof n||h(n))return t;var e=n.constructor;return Ee&&"function"!=typeof n.toString&&"string"==typeof(n+"")||d(e)&&!(e instanceof e)?t:Bt?(Je(n,function(n,e,r){return t=!Gt.call(r,e),!1}),t===!1):(Je(n,function(n,e){t=e}),t===!1||Gt.call(n,t))}function g(n,t,e,r,o){if(null==n)return n;e&&(t=!1);var i=Le[typeof n];if(i){var a=Qt.call(n);if(!Be[a]||_e&&h(n))return n;var c=a==ue;i=c||(a==de?Ye(n):i)}if(!i||!t)return i?c?Jt.call(n):Xe({},n):n;var s=n.constructor;switch(a){case le:return new s(1==n);case fe:return new s(+n);case he:case ge:return new s(n);case ve:return s(n.source,Mt.exec(n))}r||(r=[]),o||(o=[]);for(var u=r.length;u--;)if(r[u]==n)return o[u];var l=c?s(u=n.length):{};if(r.push(n),o.push(l),c)for(var f=-1;u>++f;)l[f]=g(n[f],t,null,r,o);else Qe(n,function(n,e){l[e]=g(n,t,null,r,o)});return l}function y(n,t){return n?Gt.call(n,t):!1}function m(n){return n===!0||n===!1||Qt.call(n)==le}function b(n){return Qt.call(n)==fe}function _(n){return n?1===n.nodeType:!1}function x(n,t,e,r){if(null==n||null==t)return n===t;if(n===t)return 0!==n||1/n==1/t;(Le[typeof n]||Le[typeof t])&&(n=n.__wrapped__||n,t=t.__wrapped__||t);var o=Qt.call(n);if(o!=Qt.call(t))return!1;switch(o){case le:case fe:return+n==+t;case he:return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case ve:case ge:return n==t+""}var i=Se[o];if(_e&&!i&&(i=h(n))&&!h(t))return!1;if(!i&&(o!=de||Ee&&("function"!=typeof n.toString&&"string"==typeof(n+"")||"function"!=typeof t.toString&&"string"==typeof(t+""))))return!1;e||(e=[]),r||(r=[]);for(var a=e.length;a--;)if(e[a]==n)return r[a]==t;var c=-1,s=!0,u=0;if(e.push(n),r.push(t),i){if(u=n.length,s=u==t.length)for(;u--&&(s=x(n[u],t[u],e,r)););return s}var l=n.constructor,f=t.constructor;if(l!=f&&!(d(l)&&l instanceof l&&d(f)&&f instanceof f))return!1;for(var p in n)if(Gt.call(n,p)&&(u++,!Gt.call(t,p)||!x(n[p],t[p],e,r)))return!1;for(p in t)if(Gt.call(t,p)&&!u--)return!1;if(It)for(;7>++c;)if(p=Yt[c],Gt.call(n,p)&&(!Gt.call(t,p)||!x(n[p],t[p],e,r)))return!1;return!0}function w(n){return re(n)&&Qt.call(n)==he}function E(n){return n?Le[typeof n]:!1}function j(n){return Qt.call(n)==he&&n!=+n}function k(n){return null===n}function A(n){return Qt.call(n)==he}function O(n){return Qt.call(n)==ve}function I(n){return Qt.call(n)==ge}function S(n){return n===t}function B(n,t,e,r){var o=n,i=n?n.length:0,a=3>arguments.length;if(i!==+i){var c=tr(n);i=c.length}else we&&Qt.call(n)==ge&&(o=n.split(""));return pr(n,function(n,s,u){s=c?c[--i]:--i,e=a?(a=!1,o[s]):t.call(r,e,o[s],s,u)}),e}function L(n){var t=n?n.length:0;return t===+t?t:tr(n).length}function D(n){if(!n)return[];var t=n.length;return t===+t?(xe?Qt.call(n)==ge:"string"==typeof n)?n.split(""):Jt.call(n):ar(n)}function R(n){for(var t=-1,e=n?n.length:0,r=[];e>++t;)n[t]&&r.push(n[t]);return r}function N(n){var t=[];if(!n)return t;for(var e=-1,r=n.length,i=Kt.apply(At,arguments),a=o(i,r);r>++e;){var c=n[e];a(c)||t.push(c)}return t}function F(n,e,r){return n?null==e||r?n[0]:Jt.call(n,0,e):t}function T(n,t){for(var e,r=-1,o=n?n.length:0,i=[];o>++r;)e=n[r],$e(e)?Vt.apply(i,t?e:T(e)):i.push(e);return i}function C(n,t,e){var r=-1,o=n?n.length:0;if("number"==typeof e)r=(0>e?ie(0,o+e):e||0)-1;else if(e)return r=G(n,t),n[r]===t?r:-1;for(;o>++r;)if(n[r]===t)return r;return-1}function P(n,t,e){return n?Jt.call(n,0,-(null==t||e?1:t)):[]}function M(n){var t=arguments.length,e=[],r=-1,i=n?n.length:0,a=[];n:for(;i>++r;){var c=n[r];if(0>C(a,c)){for(var s=1;t>s;s++)if(!(e[s]||(e[s]=o(arguments[s])))(c))continue n;a.push(c)}}return a}function z(n,t,e){if(n){var r=n.length;return null==t||e?n[r-1]:Jt.call(n,-t||r)}}function H(n,t,e){var r=n?n.length:0;for("number"==typeof e&&(r=(0>e?ie(0,r+e):ae(e,r-1))+1);r--;)if(n[r]===t)return r;return-1}function U(n,t,e){var r,o=-1/0,i=-1,a=n?n.length:0,s=o;for(t=c(t,e);a>++i;)r=t(n[i],i,n),r>o&&(o=r,s=n[i]);return s}function q(n,t,e){var r,o=1/0,i=-1,a=n?n.length:0,s=o;for(t=c(t,e);a>++i;)r=t(n[i],i,n),o>r&&(o=r,s=n[i]);return s}function $(n,t){for(var e=-1,r=n?n.length:0,o={};r>++e;)t?o[n[e]]=t[e]:o[n[e][0]]=n[e][1];return o}function Y(n,t,e){n=+n||0,e=+e||1,null==t&&(t=n,n=0);for(var r=-1,o=ie(0,Math.ceil((t-n)/e)),i=Array(o);o>++r;)i[r]=n,n+=e;return i}function W(n,t,e){return n?Jt.call(n,null==t||e?1:t):[]}function K(n){for(var t=-1,e=n?n.length:0,r=Array(e);e>++t;){var o=ne(ce()*(t+1));r[t]=r[o],r[o]=n[t]}return r}function G(n,t,e,r){var o=0,i=n?n.length:o;for(e=c(e,r),t=e(t);i>o;){var a=o+i>>>1;t>e(n[a])?o=a+1:i=a}return o}function V(){for(var n=-1,t=Kt.apply(At,arguments),e=t.length,r=[];e>++n;)0>C(r,t[n])&&r.push(t[n]);return r}function X(n,t,e,r){var o=-1,i=n?n.length:0,a=[],s=[];for("function"==typeof t&&(r=e,e=t,t=!1),e=c(e,r);i>++o;){var u=e(n[o],o,n);(t?!o||s[s.length-1]!==u:0>C(s,u))&&(s.push(u),a.push(n[o]))}return a}function J(n){for(var t=-1,e=n?n.length:0,r=o(arguments,1,20),i=[];e>++t;){var a=n[t];r(a)||i.push(a)}return i}function Q(n){for(var t=-1,e=n?U(gr(arguments,"length")):0,r=Array(e);e>++t;)r[t]=gr(arguments,t);return r}function Z(n,e){return 1>n?e():function(){return 1>--n?e.apply(this,arguments):t}}function nt(n,t){return ke||Zt&&arguments.length>2?Zt.call.apply(Zt,arguments):a(n,t,Jt.call(arguments,2))}function tt(){var n=arguments;return function(){for(var t=arguments,e=n.length;e--;)t=[n[e].apply(this,t)];return t[0]}}function et(n,t,e){function r(){c=null,e||(i=n.apply(a,o))}var o,i,a,c;return function(){var s=e&&!c;return o=arguments,a=this,ye(c),c=me(r,t),s&&(i=n.apply(a,o)),i}}function rt(n,e){var r=Jt.call(arguments,2);return me(function(){return n.apply(t,r)},e)}function ot(n){var e=Jt.call(arguments,1);return me(function(){return n.apply(t,e)},1)}function it(n,t){return a(t,n,Jt.call(arguments,2))}function at(n,t){var e={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Gt.call(e,r)?e[r]:e[r]=n.apply(this,arguments)}}function ct(n){var t,e=!1;return function(){return e?t:(e=!0,t=n.apply(this,arguments),n=null,t)}}function st(n){return a(n,Jt.call(arguments,1))}function ut(n,t){function e(){c=new Date,a=null,o=n.apply(i,r)}var r,o,i,a,c=0;return function(){var s=new Date,u=t-(s-c);return r=arguments,i=this,0>=u?(c=s,o=n.apply(i,r)):a||(a=me(e,u)),o}}function lt(n,t){return function(){var e=[n];return arguments.length&&Vt.apply(e,arguments),t.apply(this,e)}}function ft(n){return null==n?"":(n+"").replace(qt,l)}function pt(n){return n}function ht(n){pr(Ze(n),function(t){var e=r[t]=n[t];r.prototype[t]=function(){var n=[this.__wrapped__];arguments.length&&Vt.apply(n,arguments);var t=e.apply(r,n);return this.__chain__&&(t=new r(t),t.__chain__=!0),t}})}function dt(){return n._=Rt,this}function vt(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+ne(ce()*((+t||0)-n+1))}function gt(n,t){var e=n?n[t]:null;return d(e)?n[t]():e}function yt(n,t,e){n+="",e||(e={});var o,i,a=0,c=r.templateSettings,s="__p += '",l=e.variable||c.variable,f=l,p=RegExp((e.escape||c.escape||Ut).source+"|"+(e.interpolate||c.interpolate||Ut).source+"|"+(e.evaluate||c.evaluate||Ut).source+"|$","g");if(n.replace(p,function(t,e,r,i,c){s+=n.slice(a,c).replace($t,u),s+=e?"' +\n__e("+e+") +\n'":i?"';\n"+i+";\n__p += '":r?"' +\n((__t = ("+r+")) == null ? '' : __t) +\n'":"",o||(o=i||Nt.test(e||r)),a=c+t.length}),s+="';\n",!f)if(l="obj",o)s="with ("+l+") {\n"+s+"\n}\n";else{var h=RegExp("(\\(\\s*)"+l+"\\."+l+"\\b","g");s=s.replace(zt,"$&"+l+".").replace(h,"$1__d")}s=(o?s.replace(Tt,""):s).replace(Ct,"$1").replace(Pt,"$1;"),s="function("+l+") {\n"+(f?"":l+" || ("+l+" = {});\n")+"var __t, __p = '', __e = _.escape"+(o?", __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, '') }\n":(f?"":", __d = "+l+"."+l+" || "+l)+";\n")+s+"return __p\n}";var d=Ie?"\n//@ sourceURL=/lodash/template/source["+Wt++ +"]":"";try{i=Function("_","return "+s+d)(r)}catch(v){throw v.source=s,v}return t?i(t):(i.source=s,i)}function mt(n,t,e){n=+n||0;for(var r=-1,o=Array(n);n>++r;)o[r]=t.call(e,r);return o}function bt(n){return null==n?"":(n+"").replace(Ft,p)}function _t(n){var t=Lt++;return n?n+t:t}function xt(n){return n=new r(n),n.__chain__=!0,n}function wt(n,t){return t(n),n}function Et(){return this.__chain__=!0,this}function jt(){return this.__wrapped__}var kt="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(n=global),exports),At=Array.prototype,Ot=(Boolean.prototype,Object.prototype);Number.prototype,String.prototype;var It,St,Bt,Lt=0,Dt=30,Rt=n._,Nt=/[-?+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,Ft=/&(?:amp|lt|gt|quot|#x27);/g,Tt=/\b__p \+= '';/g,Ct=/\b(__p \+=) '' \+/g,Pt=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Mt=/\w*$/,zt=/(?:__e|__t = )\(\s*(?![\d\s"']|this\.)/g,Ht=RegExp("^"+(Ot.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),Ut=/($^)/,qt=/[&<>"']/g,$t=/['\n\r\t\u2028\u2029\\]/g,Yt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Wt=0,Kt=At.concat,Gt=Ot.hasOwnProperty,Vt=At.push,Xt=Ot.propertyIsEnumerable,Jt=At.slice,Qt=Ot.toString,Zt=Ht.test(Zt=Jt.bind)&&Zt,ne=Math.floor,te=Ht.test(te=Object.getPrototypeOf)&&te,ee=Ht.test(ee=Array.isArray)&&ee,re=n.isFinite,oe=Ht.test(oe=Object.keys)&&oe,ie=Math.max,ae=Math.min,ce=Math.random,se="[object Arguments]",ue="[object Array]",le="[object Boolean]",fe="[object Date]",pe="[object Function]",he="[object Number]",de="[object Object]",ve="[object RegExp]",ge="[object String]",ye=n.clearTimeout,me=n.setTimeout,be=!0;(function(){function n(){this.x=1}var t={0:1,length:1},e=[];n.prototype={valueOf:1,y:1};for(var r in new n)e.push(r);for(r in arguments)be=!r;It=4>(e+"").length,Bt="x"!=e[0],e.splice.call(t,0,1),St=t[0]})(1);var _e=!h(arguments),xe="x"!=Jt.call("x")[0],we="xx"!="x"[0]+Object("x")[0];try{var Ee=Qt.call(n.document||0)==de}catch(je){}var ke=Zt&&/\n|Opera/.test(Zt+Qt.call(n.opera)),Ae=oe&&/^.+$|true/.test(oe+!!n.attachEvent),Oe=!ke;try{var Ie=(Function("//@")(),!n.attachEvent)}catch(je){}var Se={};Se[le]=Se[fe]=Se[pe]=Se[he]=Se[de]=Se[ve]=!1,Se[se]=Se[ue]=Se[ge]=!0;var Be={};Be[se]=Be[pe]=!1,Be[ue]=Be[le]=Be[fe]=Be[he]=Be[de]=Be[ve]=Be[ge]=!0;var Le={"boolean":!1,"function":!0,object:!0,number:!1,string:!1,undefined:!1,unknown:!0},De={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};r.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""};var Re=yt("<% if (useStrict) { %>'use strict';\n<% } %>var index, value, iteratee = <%= firstArg %>, result<% if (init) { %> = <%= init %><% } %>;\nif (!<%= firstArg %>) return result;\n<%= top %>;\n<% if (arrayBranch) { %>var length = iteratee.length; index = -1; <% if (objectBranch) { %>\nif (length === +length) {<% } %> <% if (noCharByIndex) { %>\n if (toString.call(iteratee) == stringClass) {\n iteratee = iteratee.split('')\n } <% } %>\n <%= arrayBranch.beforeLoop %>;\n while (++index < length) {\n value = iteratee[index];\n <%= arrayBranch.inLoop %>\n } <% if (objectBranch) { %>\n}<% } %><% } %><% if (objectBranch) { %> <% if (arrayBranch) { %>\nelse { <% } else if (noArgsEnum) { %>\n var length = iteratee.length; index = -1;\n if (length && isArguments(iteratee)) {\n while (++index < length) {\n value = iteratee[index += ''];\n <%= objectBranch.inLoop %>\n }\n } else { <% } %> <% if (!hasDontEnumBug) { %>\n var skipProto = typeof iteratee == 'function' && \n propertyIsEnumerable.call(iteratee, 'prototype');\n <% } %> <% if (isKeysFast && useHas) { %>\n var ownIndex = -1,\n ownProps = objectTypes[typeof iteratee] ? nativeKeys(iteratee) : [],\n length = ownProps.length;\n\n <%= objectBranch.beforeLoop %>;\n while (++ownIndex < length) {\n index = ownProps[ownIndex];\n <% if (!hasDontEnumBug) { %>if (!(skipProto && index == 'prototype')) {\n <% } %> value = iteratee[index];\n <%= objectBranch.inLoop %>\n <% if (!hasDontEnumBug) { %>}\n<% } %> } <% } else { %>\n <%= objectBranch.beforeLoop %>;\n for (index in iteratee) {<% if (!hasDontEnumBug || useHas) { %>\n if (<% if (!hasDontEnumBug) { %>!(skipProto && index == 'prototype')<% } if (!hasDontEnumBug && useHas) { %> && <% } if (useHas) { %>hasOwnProperty.call(iteratee, index)<% } %>) { <% } %>\n value = iteratee[index];\n <%= objectBranch.inLoop %>; <% if (!hasDontEnumBug || useHas) { %>\n }<% } %>\n } <% } %> <% if (hasDontEnumBug) { %>\n\n var ctor = iteratee.constructor;\n <% for (var k = 0; k < 7; k++) { %>\n index = '<%= shadowed[k] %>';\n if (<% if (shadowed[k] == 'constructor') { %>!(ctor && ctor.prototype === iteratee) && <% } %>hasOwnProperty.call(iteratee, index)) {\n value = iteratee[index];\n <%= objectBranch.inLoop %>\n } <% } %> <% } %> <% if (arrayBranch || noArgsEnum) { %>\n}<% } %><% } %>\n<%= bottom %>;\nreturn result"),Ne={args:"collection, callback, thisArg",init:"collection",top:"callback = createCallback(callback, thisArg)",inLoop:"if (callback(value, index, collection) === false) return result"},Fe={init:"{}",top:"callback = createCallback(callback, thisArg)",inLoop:"var prop = callback(value, index, collection);\n(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)"},Te={init:"true",inLoop:"if (!callback(value, index, collection)) return !result"},Ce={useHas:!1,useStrict:!1,args:"object",init:"object",top:"for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) {\n if (iteratee = arguments[argsIndex]) {",inLoop:"result[index] = value",bottom:" }\n}"},Pe={init:"[]",inLoop:"callback(value, index, collection) && result.push(value)"},Me={top:"callback = createCallback(callback, thisArg)"},ze={inLoop:{object:Ne.inLoop}},He={init:!1,beforeLoop:{array:"result = Array(length)",object:"result = "+(Ae?"Array(length)":"[]")},inLoop:{array:"result[index] = callback(value, index, collection)",object:"result"+(Ae?"[ownIndex] = ":".push")+"(callback(value, index, collection))"}},Ue={useHas:!1,args:"object, callback, thisArg",init:"{}",top:"var isFunc = typeof callback == 'function';\nif (isFunc) callback = createCallback(callback, thisArg);\nelse var props = concat.apply(ArrayProto, arguments)",inLoop:"if (isFunc\n ? !callback(value, index, object)\n : indexOf(props, index) < 0\n) result[index] = value"},qe=s({args:"object",init:"{}",inLoop:"result[value] = index"});_e&&(h=function(n){return n?Gt.call(n,"callee"):!1});var $e=ee||function(n){return Qt.call(n)==ue};d(/x/)&&(d=function(n){return Qt.call(n)==pe});var Ye=te?function(n){if(!n||"object"!=typeof n)return!1;var t=n.valueOf,e="function"==typeof t&&(e=te(t))&&te(e);return e?n==e||te(n)==e&&!h(n):v(n)}:v,We=s({args:"object",init:"[]",inLoop:"result.push(index)"}),Ke={"&":"&","<":"<",">":">",'"':""","'":"'"},Ge=qe(Ke),Ve=s(Ce,{inLoop:"if (result[index] == null) "+Ce.inLoop}),Xe=s(Ce),Je=s(Ne,Me,ze,{useHas:!1}),Qe=s(Ne,Me,ze),Ze=s({useHas:!1,args:"object",init:"[]",inLoop:"if (isFunction(value)) result.push(index)",bottom:"result.sort()"}),nr=s({args:"value",init:"true",top:"var className = toString.call(value),\n length = value.length;\nif (arrayLikeClasses[className]"+(_e?" || isArguments(value)":"")+" ||\n"+" (className == objectClass && length === +length &&\n"+" isFunction(value.splice))"+") return !length",inLoop:{object:"return false"}}),tr=oe?function(n){var t=typeof n;return"function"==t&&Xt.call(n,"prototype")?We(n):n&&Le[t]?oe(n):[]}:We,er=s(Ce,{args:"object, source, indicator",top:"var isArr, args = arguments, argsIndex = 0;\nif (indicator == compareAscending) {\n var argsLength = 2, stackA = args[3], stackB = args[4]\n} else {\n var argsLength = args.length, stackA = [], stackB = []\n}\nwhile (++argsIndex < argsLength) {\n if (iteratee = args[argsIndex]) {",inLoop:"if ((source = value) && ((isArr = isArray(source)) || isPlainObject(source))) {\n var found = false, stackLength = stackA.length;\n while (stackLength--) {\n if (found = stackA[stackLength] == source) break\n }\n if (found) {\n result[index] = stackB[stackLength]\n } else {\n stackA.push(source);\n stackB.push(value = (value = result[index]) && isArr\n ? (isArray(value) ? value : [])\n : (isPlainObject(value) ? value : {})\n );\n result[index] = callee(value, source, compareAscending, stackA, stackB)\n }\n} else if (source != null) {\n result[index] = source\n}"}),rr=s(Ue),or=s({args:"object",init:"[]",inLoop:"result"+(Ae?"[ownIndex] = ":".push")+"([index, value])"}),ir=s(Ue,{top:"if (typeof callback != 'function') {\n var prop,\n props = concat.apply(ArrayProto, arguments),\n length = props.length;\n for (index = 1; index < length; index++) {\n prop = props[index];\n if (prop in object) result[prop] = object[prop]\n }\n} else {\n callback = createCallback(callback, thisArg)",inLoop:"if (callback(value, index, object)) result[index] = value",bottom:"}"}),ar=s({args:"object",init:"[]",inLoop:"result.push(value)"}),cr=s({args:"collection, target",init:"false",noCharByIndex:!1,beforeLoop:{array:"if (toString.call(collection) == stringClass) return collection.indexOf(target) > -1"},inLoop:"if (value === target) return true"}),sr=s(Ne,Fe),ur=s(Ne,Te),lr=s(Ne,Pe),fr=s(Ne,Me,{init:!1,inLoop:"if (callback(value, index, collection)) return value"}),pr=s(Ne,Me),hr=s(Ne,Fe,{inLoop:"var prop = callback(value, index, collection);\n(hasOwnProperty.call(result, prop) ? result[prop] : result[prop] = []).push(value)"}),dr=s(He,{args:"collection, methodName",top:"var args = slice.call(arguments, 2),\n isFunc = typeof methodName == 'function'",inLoop:{array:"result[index] = (isFunc ? methodName : value[methodName]).apply(value, args)",object:"result"+(Ae?"[ownIndex] = ":".push")+"((isFunc ? methodName : value[methodName]).apply(value, args))"}}),vr=s(Ne,He),gr=s(He,{args:"collection, property",inLoop:{array:"result[index] = value[property]",object:"result"+(Ae?"[ownIndex] = ":".push")+"(value[property])"}}),yr=s({args:"collection, callback, accumulator, thisArg",init:"accumulator",top:"var noaccum = arguments.length < 3;\ncallback = createCallback(callback, thisArg)",beforeLoop:{array:"if (noaccum) result = iteratee[++index]"},inLoop:{array:"result = callback(result, value, index, collection)",object:"result = noaccum\n ? (noaccum = false, value)\n : callback(result, value, index, collection)"}}),mr=s(Ne,Pe,{inLoop:"!"+Pe.inLoop}),br=s(Ne,Te,{init:"false",inLoop:Te.inLoop.replace("!","")}),_r=s(Ne,Fe,He,{inLoop:{array:"result[index] = {\n criteria: callback(value, index, collection),\n index: index,\n value: value\n}",object:"result"+(Ae?"[ownIndex] = ":".push")+"({\n"+" criteria: callback(value, index, collection),\n"+" index: index,\n"+" value: value\n"+"})"},bottom:"result.sort(compareAscending);\nlength = result.length;\nwhile (length--) {\n result[length] = result[length].value\n}"}),xr=s(Pe,{args:"collection, properties",top:"var props = [];\nforIn(properties, function(value, prop) { props.push(prop) });\nvar propsLength = props.length",inLoop:"for (var prop, pass = true, propIndex = 0; propIndex < propsLength; propIndex++) {\n prop = props[propIndex];\n if (!(pass = value[prop] === properties[prop])) break\n}\npass && result.push(value)"}),wr=s({useHas:!1,useStrict:!1,args:"object",top:"var funcs = arguments,\n length = funcs.length;\nif (length > 1) {\n for (var index = 1; index < length; index++) {\n result[funcs[index]] = bind(result[funcs[index]], result)\n }\n return result\n}",inLoop:"if (isFunction(value)) {\n result[index] = bind(value, result)\n}"});r.VERSION="0.8.1",r.after=Z,r.bind=nt,r.bindAll=wr,r.chain=xt,r.clone=g,r.compact=R,r.compose=tt,r.contains=cr,r.countBy=sr,r.debounce=et,r.defaults=Ve,r.defer=ot,r.delay=rt,r.difference=N,r.escape=ft,r.every=ur,r.extend=Xe,r.filter=lr,r.find=fr,r.first=F,r.flatten=T,r.forEach=pr,r.forIn=Je,r.forOwn=Qe,r.functions=Ze,r.groupBy=hr,r.has=y,r.identity=pt,r.indexOf=C,r.initial=P,r.intersection=M,r.invert=qe,r.invoke=dr,r.isArguments=h,r.isArray=$e,r.isBoolean=m,r.isDate=b,r.isElement=_,r.isEmpty=nr,r.isEqual=x,r.isFinite=w,r.isFunction=d,r.isNaN=j,r.isNull=k,r.isNumber=A,r.isObject=E,r.isPlainObject=Ye,r.isRegExp=O,r.isString=I,r.isUndefined=S,r.keys=tr,r.last=z,r.lastIndexOf=H,r.lateBind=it,r.map=vr,r.max=U,r.memoize=at,r.merge=er,r.min=q,r.mixin=ht,r.noConflict=dt,r.object=$,r.omit=rr,r.once=ct,r.pairs=or,r.partial=st,r.pick=ir,r.pluck=gr,r.random=vt,r.range=Y,r.reduce=yr,r.reduceRight=B,r.reject=mr,r.rest=W,r.result=gt,r.shuffle=K,r.size=L,r.some=br,r.sortBy=_r,r.sortedIndex=G,r.tap=wt,r.template=yt,r.throttle=ut,r.times=mt,r.toArray=D,r.unescape=bt,r.union=V,r.uniq=X,r.uniqueId=_t,r.values=ar,r.where=xr,r.without=J,r.wrap=lt,r.zip=Q,r.all=ur,r.any=br,r.collect=vr,r.detect=fr,r.drop=W,r.each=pr,r.foldl=yr,r.foldr=B,r.head=F,r.include=cr,r.inject=yr,r.methods=Ze,r.select=lr,r.tail=W,r.take=F,r.unique=X,r._iteratorTemplate=Re,r._shimKeys=We,ht(r),r.prototype.chain=Et,r.prototype.value=jt,pr(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=At[n];r.prototype[n]=function(){var n=this.__wrapped__;return t.apply(n,arguments),St&&0===n.length&&delete n[0],this.__chain__&&(n=new r(n),n.__chain__=!0),n}}),pr(["concat","join","slice"],function(n){var t=At[n];r.prototype[n]=function(){var n=this.__wrapped__,e=t.apply(n,arguments);return this.__chain__&&(e=new r(e),e.__chain__=!0),e}}),"function"==typeof e&&"object"==typeof e.amd&&e.amd?(n._=r,e("lodash",[],function(){return r})):kt?"object"==typeof module&&module&&module.exports==kt?(module.exports=r)._=r:kt._=r:n._=r}(this),function(n,t){n("when",[],function(){function n(n,t,e,o){return r(n).then(t,e,o)}function e(n,t){this.then=n,this.inspect=t}function r(n){return a(function(t){t(n)})}function o(t){return n(t,u)}function i(){function n(n,i,a){t.resolve=t.resolver.resolve=function(t){return o?r(t):(o=!0,n(t),e)},t.reject=t.resolver.reject=function(n){return o?r(u(n)):(o=!0,i(n),e)},t.notify=t.resolver.notify=function(n){return a(n),n}}var t,e,o;return t={promise:C,resolve:C,reject:C,notify:C,resolver:{resolve:C,reject:C,notify:C}},t.promise=e=a(n),t}function a(n){function t(n,t,e){return a(function(r,o,i){h?h.push(function(a){a.then(n,t,e).then(r,o,i)}):j(function(){p.then(n,t,e).then(r,o,i)})})}function r(){return p?p.inspect():E()}function o(n){h&&(p=c(n),f(h,p),h=C)}function i(n){o(u(n))}function s(n){h&&f(h,l(n))}var p,h=[];try{n(o,i,s)}catch(d){i(d)}return new e(t,r)}function c(n){return n instanceof e?n:n===Object(n)&&"then"in n?a(function(t,e,r){j(function(){try{var o=n.then;"function"==typeof o?B(o,n,t,e,r):t(s(n))}catch(i){e(i)}})}):s(n)}function s(n){var t=new e(function(e){try{return"function"==typeof e?c(e(n)):t}catch(r){return u(r)}},function(){return x(n)});return t}function u(n){var t=new e(function(e,r){try{return"function"==typeof r?c(r(n)):t}catch(o){return u(o)}},function(){return w(n)});return t}function l(n){var t=new e(function(e,r,o){try{return"function"==typeof o?l(o(n)):t}catch(i){return l(i)}});return t}function f(n,t){j(function(){for(var e,r=0;e=n[r++];)e(t)})}function p(n){return n&&"function"==typeof n.then}function h(t,e,r,o,i){return n(t,function(t){function c(r,o,i){function a(n){h(n)}function c(n){p(n)}var s,u,l,f,p,h,d,v;if(d=t.length>>>0,s=Math.max(0,Math.min(e,d)),l=[],u=d-s+1,f=[],s)for(h=function(n){f.push(n),--u||(p=h=O,o(f))},p=function(n){l.push(n),--s||(p=h=O,r(l))},v=0;d>v;++v)v in t&&n(t[v],c,a,i);else r(l)}return a(c).then(r,o,i)})}function d(n,t,e,r){function o(n){return t?t(n[0]):n[0]}return h(n,1,o,e,r)}function v(n,t,e,r){return b(n,O).then(t,e,r)}function g(){return b(arguments,O)}function y(n){return b(n,x,w)}function m(n,t){return b(n,t)}function b(t,e,r){return n(t,function(t){function o(o,i,a){var c,s,u,l,f;if(u=s=t.length>>>0,c=[],!u)return o(c),void 0;for(l=function(t,s){n(t,e,r).then(function(n){c[s]=n,--u||o(c)},i,a)},f=0;s>f;f++)f in t?l(t[f],f):--u}return a(o)})}function _(t,e){var r=B(S,arguments,1);return n(t,function(t){var o;return o=t.length,r[0]=function(t,r,i){return n(t,function(t){return n(r,function(n){return e(t,n,i,o)})})},I.apply(t,r)})}function x(n){return{state:"fulfilled",value:n}}function w(n){return{state:"rejected",reason:n}}function E(){return{state:"pending"}}function j(n){1===D.push(n)&&k()}function k(){L(A)}function A(){for(var n,t=0;n=D[t++];)n();D=[]}function O(n){return n}n.defer=i,n.resolve=r,n.reject=o,n.join=g,n.all=v,n.map=m,n.reduce=_,n.settle=y,n.any=d,n.some=h,n.isPromise=p,n.promise=a,e.prototype={otherwise:function(n){return this.then(C,n)},ensure:function(n){function t(){return r(n())}return this.then(t,t).yield(this)},yield:function(n){return this.then(function(){return n})},spread:function(n){return this.then(function(t){return v(t,function(t){return n.apply(C,t)})})},always:function(n,t){return this.then(n,n,t)}};var I,S,B,L,D,R,N,F,T,C;return D=[],R=t.setTimeout,L="function"==typeof setImmediate?setImmediate.bind(t):"object"==typeof process&&process.nextTick?process.nextTick:"object"==typeof vertx?vertx.runOnLoop:function(n){R(n,0)},N=Function.prototype,F=N.call,B=N.bind?F.bind(F):function(n,t){return n.apply(t,S.call(arguments,2))},T=[],S=T.slice,I=T.reduce||function(n){var t,e,r,o,i;if(i=0,t=Object(this),o=t.length>>>0,e=arguments,1>=e.length)for(;;){if(i in t){r=t[i++];break}if(++i>=o)throw new TypeError}else r=e[1];for(;o>i;++i)i in t&&(r=n(r,t[i],i,t));return r},n})}("function"==typeof e&&e.amd?e:function(n){module.exports=n()},this),e("src/path",["require"],function(){function n(n,t){for(var e=0,r=n.length-1;r>=0;r--){var o=n[r];"."===o?n.splice(r,1):".."===o?(n.splice(r,1),e++):e&&(n.splice(r,1),e--)}if(t)for(;e--;e)n.unshift("..");return n}function t(t){var e="/"===t.charAt(0);return t=n(t.split("/").filter(function(n){return!!n}),!e).join("/"),t||e||(t="."),(e?"/":"")+t}function e(n){var t=a(n),e=t[0],r=t[1];return e||r?(r&&(r=r.substr(0,r.length-1)),e+r):"."}function r(n,t){var e=a(n)[2];return t&&e.substr(-1*t.length)===t&&(e=e.substr(0,e.length-t.length)),""===e?"/":e}function o(n){return"/"===n.charAt(0)}var i=/^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/,a=function(n){var t=i.exec(n);return[t[1]||"",t[2]||"",t[3]||"",t[4]||""]};return{normalize:t,dirname:e,basename:r,isAbsolute:o}});var r=r||function(n,t){var e={},r=e.lib={},o=r.Base=function(){function n(){}return{extend:function(t){n.prototype=this;var e=new n;return t&&e.mixIn(t),e.$super=this,e},create:function(){var n=this.extend();return n.init.apply(n,arguments),n},init:function(){},mixIn:function(n){for(var t in n)n.hasOwnProperty(t)&&(this[t]=n[t]);n.hasOwnProperty("toString")&&(this.toString=n.toString)},clone:function(){return this.$super.extend(this)}}}(),i=r.WordArray=o.extend({init:function(n,e){n=this.words=n||[],this.sigBytes=e!=t?e:4*n.length},toString:function(n){return(n||c).stringify(this)},concat:function(n){var t=this.words,e=n.words,r=this.sigBytes,n=n.sigBytes;if(this.clamp(),r%4)for(var o=0;n>o;o++)t[r+o>>>2]|=(255&e[o>>>2]>>>24-8*(o%4))<<24-8*((r+o)%4);else if(e.length>65535)for(o=0;n>o;o+=4)t[r+o>>>2]=e[o>>>2];else t.push.apply(t,e);return this.sigBytes+=n,this},clamp:function(){var t=this.words,e=this.sigBytes;t[e>>>2]&=4294967295<<32-8*(e%4),t.length=n.ceil(e/4) -},clone:function(){var n=o.clone.call(this);return n.words=this.words.slice(0),n},random:function(t){for(var e=[],r=0;t>r;r+=4)e.push(0|4294967296*n.random());return i.create(e,t)}}),a=e.enc={},c=a.Hex={stringify:function(n){for(var t=n.words,n=n.sigBytes,e=[],r=0;n>r;r++){var o=255&t[r>>>2]>>>24-8*(r%4);e.push((o>>>4).toString(16)),e.push((15&o).toString(16))}return e.join("")},parse:function(n){for(var t=n.length,e=[],r=0;t>r;r+=2)e[r>>>3]|=parseInt(n.substr(r,2),16)<<24-4*(r%8);return i.create(e,t/2)}},s=a.Latin1={stringify:function(n){for(var t=n.words,n=n.sigBytes,e=[],r=0;n>r;r++)e.push(String.fromCharCode(255&t[r>>>2]>>>24-8*(r%4)));return e.join("")},parse:function(n){for(var t=n.length,e=[],r=0;t>r;r++)e[r>>>2]|=(255&n.charCodeAt(r))<<24-8*(r%4);return i.create(e,t)}},u=a.Utf8={stringify:function(n){try{return decodeURIComponent(escape(s.stringify(n)))}catch(t){throw Error("Malformed UTF-8 data")}},parse:function(n){return s.parse(unescape(encodeURIComponent(n)))}},l=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=i.create(),this._nDataBytes=0},_append:function(n){"string"==typeof n&&(n=u.parse(n)),this._data.concat(n),this._nDataBytes+=n.sigBytes},_process:function(t){var e=this._data,r=e.words,o=e.sigBytes,a=this.blockSize,c=o/(4*a),c=t?n.ceil(c):n.max((0|c)-this._minBufferSize,0),t=c*a,o=n.min(4*t,o);if(t){for(var s=0;t>s;s+=a)this._doProcessBlock(r,s);s=r.splice(0,t),e.sigBytes-=o}return i.create(s,o)},clone:function(){var n=o.clone.call(this);return n._data=this._data.clone(),n},_minBufferSize:0});r.Hasher=l.extend({init:function(){this.reset()},reset:function(){l.reset.call(this),this._doReset()},update:function(n){return this._append(n),this._process(),this},finalize:function(n){return n&&this._append(n),this._doFinalize(),this._hash},clone:function(){var n=l.clone.call(this);return n._hash=this._hash.clone(),n},blockSize:16,_createHelper:function(n){return function(t,e){return n.create(e).finalize(t)}},_createHmacHelper:function(n){return function(t,e){return f.HMAC.create(n,e).finalize(t)}}});var f=e.algo={};return e}(Math);(function(n){var t=r,e=t.lib,o=e.WordArray,e=e.Hasher,i=t.algo,a=[],c=[];(function(){function t(t){for(var e=n.sqrt(t),r=2;e>=r;r++)if(!(t%r))return!1;return!0}function e(n){return 0|4294967296*(n-(0|n))}for(var r=2,o=0;64>o;)t(r)&&(8>o&&(a[o]=e(n.pow(r,.5))),c[o]=e(n.pow(r,1/3)),o++),r++})();var s=[],i=i.SHA256=e.extend({_doReset:function(){this._hash=o.create(a.slice(0))},_doProcessBlock:function(n,t){for(var e=this._hash.words,r=e[0],o=e[1],i=e[2],a=e[3],u=e[4],l=e[5],f=e[6],p=e[7],h=0;64>h;h++){if(16>h)s[h]=0|n[t+h];else{var d=s[h-15],v=s[h-2];s[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+s[h-7]+((v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10)+s[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&l^~u&f)+c[h]+s[h],v=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=f,f=l,l=u,u=0|a+d,a=i,i=o,o=r,r=0|d+v}e[0]=0|e[0]+r,e[1]=0|e[1]+o,e[2]=0|e[2]+i,e[3]=0|e[3]+a,e[4]=0|e[4]+u,e[5]=0|e[5]+l,e[6]=0|e[6]+f,e[7]=0|e[7]+p},_doFinalize:function(){var n=this._data,t=n.words,e=8*this._nDataBytes,r=8*n.sigBytes;t[r>>>5]|=128<<24-r%32,t[(r+64>>>9<<4)+15]=e,n.sigBytes=4*t.length,this._process()}});t.SHA256=e._createHelper(i),t.HmacSHA256=e._createHmacHelper(i)})(Math),e("crypto-js/rollups/sha256",function(){}),e("src/shared",["require","crypto-js/rollups/sha256"],function(n){function t(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var t=0|16*Math.random(),e="x"==n?t:8|3&t;return e.toString(16)}).toUpperCase()}function e(n){return i.SHA256(n).toString(i.enc.hex)}function o(){}n("crypto-js/rollups/sha256");var i=r;return{guid:t,hash:e,nop:o}}),e("src/error",["require"],function(){function n(n){this.message=n||""}function t(n){this.message=n||""}function e(n){this.message=n||""}function r(n){this.message=n||""}function o(n){this.message=n||""}function i(n){this.message=n||""}function a(n){this.message=n||""}function c(n){this.message=n||""}function s(n){this.message=n||""}function u(n){this.message=n||""}function l(n){this.message=n||""}function f(n){this.message=n||""}return n.prototype=Error(),n.prototype.name="EExists",n.prototype.constructor=n,t.prototype=Error(),t.prototype.name="EIsDirectory",t.prototype.constructor=t,e.prototype=Error(),e.prototype.name="ENoEntry",e.prototype.constructor=e,r.prototype=Error(),r.prototype.name="EBusy",r.prototype.constructor=r,o.prototype=Error(),o.prototype.name="ENotEmpty",o.prototype.constructor=o,i.prototype=Error(),i.prototype.name="ENotDirectory",i.prototype.constructor=i,a.prototype=Error(),a.prototype.name="EBadFileDescriptor",a.prototype.constructor=a,c.prototype=Error(),c.prototype.name="ENotImplemented",c.prototype.constructor=c,s.prototype=Error(),s.prototype.name="ENotMounted",s.prototype.constructor=s,u.prototype=Error(),u.prototype.name="EInvalid",u.prototype.constructor=u,l.prototype=Error(),l.prototype.name="EIO",l.prototype.constructor=l,f.prototype=Error(),f.prototype.name="EFileSystemError",f.prototype.constructor=f,{EExists:n,EIsDirectory:t,ENoEntry:e,EBusy:r,ENotEmpty:o,ENotDirectory:i,EBadFileDescriptor:a,ENotImplemented:c,ENotMounted:s,EInvalid:u,EIO:l}}),e("src/constants",["require"],function(){var n="READ",t="WRITE",e="CREATE",r="EXCLUSIVE",o="TRUNCATE",i="APPEND";return{METADATA_STORE_NAME:"metadata",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",MODE_FILE:"FILE",MODE_DIRECTORY:"DIRECTORY",MODE_SYMBOLIC_LINK:"SYMLINK",BINARY_MIME_TYPE:"application/octet-stream",JSON_MIME_TYPE:"application/json",ROOT_DIRECTORY_NAME:"/",ROOT_NODE_ID:"8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1",FS_FORMAT:"FORMAT",O_READ:n,O_WRITE:t,O_CREATE:e,O_EXCLUSIVE:r,O_TRUNCATE:o,O_APPEND:i,O_FLAGS:{r:[n],"r+":[n,t],w:[t,e,o],"w+":[t,n,e,o],wx:[t,e,r,o],"wx+":[t,n,e,r,o],a:[t,e,i],"a+":[t,n,e,i],ax:[t,e,r,i],"ax+":[t,n,e,r,i]},FS_READY:"READY",FS_PENDING:"PENDING",FS_ERROR:"ERROR"}}),e("src/file-system",["require","lodash","when","src/path","src/path","src/path","src/shared","src/shared","src/shared","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/error","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants","src/constants"],function(n){function t(n,t){this.id=n,this.type=t||M}function e(n,t,e){this.id=n,this.flags=t,this.position=e}function r(n,t,e,r,o,i,a,c,s,u){var l=Date.now();this.id=n||O(A()),this.mode=t||M,this.size=e||0,this.atime=r||l,this.ctime=o||l,this.mtime=i||l,this.flags=a||[],this.xattrs=c||{},this.nlinks=s||0,this.version=u||0,this.blksize=void 0,this.nblocks=1,this.data=O(A())}function o(n,t){this.node=n.id,this.dev=t,this.size=n.size,this.nlinks=n.nlinks,this.atime=n.atime,this.mtime=n.mtime,this.ctime=n.ctime,this.type=n.mode}function i(n,t,e){function r(n,t){n?e(n):t?e(void 0,t):e(new B("path does not exist"))}function o(t,r){t?e(t):x(r).has("data")&&!r.type!=z?a(n,r.data,c):e(new R("a component of the path prefix is not a directory"))}function c(t,r){if(t)e(t);else if(x(r).has(s)){var o=r[s].id;a(n,o,e)}else e(new B("path does not exist"))}if(t=E(t),!t)return e(new B("path is an empty string"));var s=k(t),u=j(t);H==s?a(n,U,r):i(n,u,o)}function a(n,t,e){try{var r=n.get(t);r.onsuccess=function(n){var t=n.target.result;e(void 0,t)},r.onerror=function(n){e(n)}}catch(o){e(new T(o.message))}}function c(n,t,e,r){try{var o=n.put(t,e);o.onsuccess=function(n){var t=n.target.result;r(void 0,t)},o.onerror=function(n){r(n)}}catch(i){r(new T(i.message))}}function s(n,t,e){var r=n.delete(t);r.onsuccess=function(n){var t=n.target.result;e(void 0,t)},r.onerror=function(n){e(n)}}function u(n,t){function e(e,i){!e&&i?t(new I):e&&!e instanceof B?t(e):(a=new r(U,z),a.nlinks+=1,c(n,a,a.id,o))}function o(e){e?t(e):(s={},c(n,s,a.data,t))}var a,s;i(n,H,e)}function l(n,e,o){function s(t,e){!t&&e?o(new I):t&&!t instanceof B?o(t):i(n,m,u)}function u(t,e){t?o(t):(v=e,a(n,v.data,l))}function l(t,e){t?o(t):(g=e,h=new r(void 0,z),h.nlinks+=1,c(n,h,h.id,f))}function f(t){t?o(t):(d={},c(n,d,h.data,p))}function p(e){e?o(e):(g[y]=new t(h.id,z),c(n,g,v.data,o))}e=E(e);var h,d,v,g,y=k(e),m=j(e);i(n,e,s)}function f(n,t,e){function r(t,r){t?e(t):H==y?e(new L):r?(h=r,a(n,h.data,o)):e(new B)}function o(t,r){t?e(t):(d=r,x(d).size()>0?e(new D):i(n,m,u))}function u(t,r){t?e(t):(v=r,a(n,v.data,l))}function l(t,r){t?e(t):(g=r,delete g[y],c(n,g,v.data,f))}function f(t){t?e(t):s(n,h.id,p)}function p(t){t?e(t):s(n,h.data,e)}t=E(t);var h,d,v,g,y=k(t),m=j(t);i(n,t,r)}function p(n,e,o,s,u){function l(n,t){n?u(n):(y=t,a(e,y.data,f))}function f(n,t){n?u(n):(m=t,x(m).has(A)?x(s).contains(Q)?u(new B("O_CREATE and O_EXCLUSIVE are set, and the named file exists")):(b=m[A],b.type==z&&x(s).contains(X)?u(new S("the named file is a directory and O_WRITE is set")):a(e,b.id,p)):x(s).contains(J)?h():u(new B("O_CREATE is not set and the named file does not exist")))}function p(n,t){n?u(n):(_=t,u(void 0,_))}function h(){_=new r(void 0,M),_.nlinks+=1,c(e,_,_.id,d)}function d(n){n?u(n):(w=new Uint8Array(0),c(e,w,_.data,v))}function v(n){n?u(n):(m[A]=new t(_.id,M),c(e,m,y.data,g))}function g(n){n?u(n):u(void 0,_)}o=E(o);var y,m,b,_,w,A=k(o),O=j(o);H==A?x(s).contains(X)?u(new S("the named file is a directory and O_WRITE is set")):i(e,o,p):i(e,O,l)}function h(n,t,e,r,o,i,s){function u(t,e){t?s(t):(h=e,a(n,h.data,l))}function l(r,a){if(r)s(r);else{d=a;var u=void 0!==i&&null!==i?i:t.position,l=Math.max(d.length,u+o),p=new Uint8Array(l);d&&p.set(d),p.set(e,u),void 0===i&&(t.position+=o),h.size=l,h.mtime=Date.now(),h.version+=1,c(n,p,h.data,f)}}function f(t){t?s(t):c(n,h,h.id,p)}function p(n){n?s(n):s(void 0,o)}var h,d;a(n,t.id,u)}function d(n,t,e,r,o,i,c){function s(t,e){t?c(t):(l=e,a(n,l.data,u))}function u(n,a){if(n)c(n);else{f=a;var s=void 0!==i&&null!==i?i:t.position;o=s+o>e.length?o-s:o;var u=f.subarray(s,s+o);e.set(u,r),void 0===i&&(t.position+=o),c(void 0,o)}}var l,f;a(n,t.id,s)}function v(n,t,e){function r(n,t){n?e(n):e(void 0,t)}t=E(t),k(t),i(n,t,r)}function g(n,t,e){function r(n,t){n?e(n):e(void 0,t)}a(n,t.id,r)}function y(n,t,e,r){function o(t,e){t?r(t):(v=e,a(n,v.data,s))}function s(t,e){t?r(t):(g=e,x(g).has(h)?i(n,w,u):r(new B("a component of either path prefix does not exist")))}function u(t,e){t?r(t):(y=e,a(n,y.data,l))}function l(t,e){t?r(t):(m=e,x(m).has(_)?r(new I("newpath resolves to an existing file")):(m[_]=g[h],c(n,m,y.data,f)))}function f(t){t?r(t):a(n,m[_].id,p)}function p(t,e){t?r(t):(b=e,b.nlinks+=1,c(n,b,b.id,r))}t=E(t);var h=k(t),d=j(t);e=E(e);var v,g,y,m,b,_=k(e),w=j(e);i(n,d,o)}function m(n,t,e){function r(t,r){t?e(t):(p=r,a(n,p.data,o))}function o(t,r){t?e(t):(h=r,x(h).has(name)?a(n,h[name].id,u):e(new B("a component of the path does not name an existing file")))}function u(t,r){t?e(t):(d=r,d.nlinks-=1,1>d.nlinks?s(n,d.id,l):c(n,d,d.id,f))}function l(t){t?e(t):s(n,d.data,f)}function f(t){t?e(t):(delete h[name],c(n,h,p.data,e))}t=E(t),name=k(t),parentPath=j(t);var p,h,d;i(n,parentPath,r)}function b(n,t){var e=x(t).contains(P),r=this,o=w.defer();this.promise=o.promise;var i=_.open(n);i.onupgradeneeded=function(n){var t=n.target.result;t.objectStoreNames.contains($)&&t.deleteObjectStore($),t.createObjectStore($),t.objectStoreNames.contains(Y)&&t.deleteObjectStore(Y),t.createObjectStore(Y),e=!0},i.onsuccess=function(n){function t(n){r.db=i,n?(r.readyState=G,o.reject(n)):(r.readyState=W,o.resolve())}var i=n.target.result,a=i.transaction([$],q),c=a.objectStore($);if(e){var s=c.clear();s.onsuccess=function(){u(c,t)},s.onerror=function(n){t(n)}}else t()},i.onerror=function(n){this.readyState=G,o.reject(n)};var a=1,c={};this.readyState=K,this.db=null,this.nextDescriptor=a,this.openFiles=c,this.name=n}var _=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,x=n("lodash"),w=n("when"),E=n("src/path").normalize,j=n("src/path").dirname,k=n("src/path").basename,A=n("src/shared").guid,O=n("src/shared").hash;n("src/shared").nop;var I=n("src/error").EExists,S=n("src/error").EIsDirectory,B=n("src/error").ENoEntry,L=n("src/error").EBusy,D=n("src/error").ENotEmpty,R=n("src/error").ENotDirectory,N=n("src/error").EBadFileDescriptor;n("src/error").ENotImplemented,n("src/error").ENotMounted;var F=n("src/error").EInvalid,T=n("src/error").EIO,C=n("src/error").EFileSystemError,P=n("src/constants").FS_FORMAT,M=n("src/constants").MODE_FILE,z=n("src/constants").MODE_DIRECTORY,H=n("src/constants").ROOT_DIRECTORY_NAME,U=n("src/constants").ROOT_NODE_ID,q=n("src/constants").IDB_RW;n("src/constants").IDB_RO;var $=n("src/constants").FILE_STORE_NAME,Y=n("src/constants").METADATA_STORE_NAME,W=n("src/constants").FS_READY,K=n("src/constants").FS_PENDING,G=n("src/constants").FS_ERROR,V=n("src/constants").O_READ,X=n("src/constants").O_WRITE,J=n("src/constants").O_CREATE,Q=n("src/constants").O_EXCLUSIVE;n("src/constants").O_TRUNCATE;var Z=n("src/constants").O_APPEND,nt=n("src/constants").O_FLAGS;return b.prototype._allocate_descriptor=function(n){var t=this.nextDescriptor++;return this.openFiles[t]=n,t},b.prototype._release_descriptor=function(n){delete this.openFiles[n]},b.prototype.open=function(n,t,r){var o=this;this.promise.then(function(){function i(n,r){if(n)a.reject(n);else{var i;i=x(t).contains(Z)?r.size:0;var c=new e(r.id,t,i),s=o._allocate_descriptor(c);a.resolve(s)}}var a=w.defer(),c=o.db.transaction([$],q),s=c.objectStore($);x(nt).has(t)?t=nt[t]:a.reject(new F("flags is not valid")),p(this,s,n,t,i),a.promise.then(function(n){r(void 0,n)},function(n){r(n)})},function(){r(new C("unknown error"))})},b.prototype.close=function(n,t){var e=w.defer();x(this.openFiles).has(n)?(this._release_descriptor(n),e.resolve()):e.reject(new N("invalid file descriptor")),e.promise.then(function(){t()},function(n){t(n)})},b.prototype.mkdir=function(n,t){var e=this;this.promise.then(function(){function r(n){n?o.reject(n):o.resolve()}var o=w.defer(),i=e.db.transaction([$],q),a=i.objectStore($);l(a,n,r),o.promise.then(function(){t()},function(n){t(n)})},function(){t(new C("unknown error"))})},b.prototype.rmdir=function(n,t){var e=this;this.promise.then(function(){function r(n){n?o.reject(n):o.resolve()}var o=w.defer(),i=e.db.transaction([$],q),a=i.objectStore($);f(a,n,r),o.promise.then(function(){t()},function(n){t(n)})},function(){t(new C("unknown error"))})},b.prototype.stat=function(n,t){var e=this;this.promise.then(function(){function r(n,t){if(n)i.reject(n);else{var r=new o(t,e.name);i.resolve(r)}}var i=w.defer(),a=e.db.transaction([$],q),c=a.objectStore($);v(c,n,r),i.promise.then(function(n){t(void 0,n)},function(n){t(n)})},function(){t(new C("unknown error"))})},b.prototype.fstat=function(n,t){var e=this;this.promise.then(function(){function r(n,t){if(n)i.reject(n);else{var r=new o(t,e.name);i.resolve(r)}}var i=w.defer(),a=e.db.transaction([$],q),c=a.objectStore($),s=e.openFiles[n];s?g(c,s,r):i.reject(new N("invalid file descriptor")),i.promise.then(function(n){t(void 0,n)},function(n){t(n)})},function(){t(new C("unknown error"))})},b.prototype.link=function(n,t,e){var r=this;this.promise.then(function(){function o(n){n?i.reject(n):i.resolve()}var i=w.defer(),a=r.db.transaction([$],q),c=a.objectStore($);y(c,n,t,o),i.promise.then(function(){e()},function(n){e(n)})},function(){e(new C("unknown error"))})},b.prototype.unlink=function(n,t){var e=this;this.promise.then(function(){function r(n){n?o.reject(n):o.resolve()}var o=w.defer(),i=e.db.transaction([$],q),a=i.objectStore($);m(a,n,r),o.promise.then(function(){t()},function(n){t(n)})},function(){t(new C("unknown error"))})},b.prototype.read=function(n,t,e,r,o,i){var a=this;this.promise.then(function(){function c(n,t){n?s.reject(n):s.resolve(t)}var s=w.defer(),u=a.db.transaction([$],q),l=u.objectStore($);e=void 0===e?0:e,r=void 0===r?t.length-e:r;var f=a.openFiles[n];f?x(f.flags).contains(V)?d(l,f,t,e,r,o,c):s.reject(new N("descriptor does not permit reading")):s.reject(new N("invalid file descriptor")),s.promise.then(function(n){i(void 0,n)},function(n){i(n)})},function(){i(new C("unknown error"))})},b.prototype.write=function(n,t,e,r,o,i){var a=this;this.promise.then(function(){function c(n,t){n?s.reject(n):s.resolve(t)}var s=w.defer(),u=a.db.transaction([$],q),l=u.objectStore($);e=void 0===e?0:e,r=void 0===r?t.length-e:r;var f=a.openFiles[n];f?x(f.flags).contains(X)?r>t.length-e?s.reject(new T("intput buffer is too small")):h(l,f,t,e,r,o,c):s.reject(new N("descriptor does not permit writing")):s.reject(new N("invalid file descriptor")),s.promise.then(function(n){i(void 0,n)},function(n){i(n)})},function(){i(new C("unknown error"))})},b.prototype.getxattr=function(){},b.prototype.setxattr=function(){},b.prototype.lseek=function(n,t,e,r){var o=this;this.promise.then(function(){function i(n,e){n?a.reject(n):0>e.size+t?a.reject(new F("resulting file offset would be negative")):(c.position=e.size+t,a.resolve(c.position))}var a=w.defer(),c=o.openFiles[n];if(c||a.reject(new N("invalid file descriptor")),"SET"===e)0>t?a.reject(new F("resulting file offset would be negative")):(c.position=t,a.resolve(c.position));else if("CUR"===e)0>c.position+t?a.reject(new F("resulting file offset would be negative")):(c.position+=t,a.resolve(c.position));else if("END"===e){var s=o.db.transaction([$],q),u=s.objectStore($);g(u,c,i)}else a.reject(new F("whence argument is not a proper value"));a.promise.then(function(n){r(void 0,n)},function(n){r(n)})},function(){r(new C("unknown error"))})},b.prototype.readdir=function(){},b.prototype.utimes=function(){},b.prototype.rename=function(){},b.prototype.truncate=function(){},b.prototype.ftruncate=function(){},b.prototype.symlink=function(){},b.prototype.readlink=function(){},b.prototype.realpath=function(){},b.prototype.lstat=function(){},{FileSystem:b}});var o=t("src/file-system");return o}); \ No newline at end of file diff --git a/examples/refactoring-test.html b/examples/refactoring-test.html index 75a3244..efba458 100644 --- a/examples/refactoring-test.html +++ b/examples/refactoring-test.html @@ -38,6 +38,10 @@ fs.open('/tmp', 'w+', function(error, fd) { fs.stat('/tmp', function(error, stats) { if(error) throw error; console.log('stats:', stats); + fs.readdir('/', function(error, files) { + if(error) throw error; + console.log('ls:', files); + }); }); }); }); diff --git a/src/file-system.js b/src/file-system.js index e19e34c..20f4174 100644 --- a/src/file-system.js +++ b/src/file-system.js @@ -748,6 +748,35 @@ define(function(require) { } }; + function read_directory(objectStore, path, callback) { + path = normalize(path); + var name = basename(path); + + var directoryNode; + var directoryData; + + find_node(objectStore, path, read_directory_data); + + function read_directory_data(error, result) { + if(error) { + callback(error); + } else { + directoryNode = result; + read_object(objectStore, directoryNode.data, handle_directory_data); + } + }; + + function handle_directory_data(error, result) { + if(error) { + callback(error); + } else { + directoryData = result; + var files = Object.keys(directoryData); + callback(undefined, files); + } + }; + }; + /* * FileSystem */ @@ -1259,7 +1288,37 @@ define(function(require) { ); }; FileSystem.prototype.readdir = function readdir(path, callback) { + var that = this; + this.promise.then( + function() { + var deferred = when.defer(); + var transaction = that.db.transaction([FILE_STORE_NAME], IDB_RW); + var files = transaction.objectStore(FILE_STORE_NAME); + function check_result(error, files) { + if(error) { + // if(transaction.error) transaction.abort(); + deferred.reject(error); + } else { + deferred.resolve(files); + } + }; + + read_directory(files, path, check_result); + + deferred.promise.then( + function(result) { + callback(undefined, result); + }, + function(error) { + callback(error); + } + ); + }, + function() { + callback(new EFileSystemError('unknown error')); + } + ); }; FileSystem.prototype.utimes = function utimes(path, atime, mtime, callback) { diff --git a/tests/spec/idbfs.spec.js b/tests/spec/idbfs.spec.js index 51aae2f..a4f3dfc 100644 --- a/tests/spec/idbfs.spec.js +++ b/tests/spec/idbfs.spec.js @@ -284,6 +284,67 @@ describe('fs.mkdir', function() { }); }); +describe('fs.readdir', function() { + beforeEach(function() { + this.db_name = mk_db_name(); + this.fs = new IDBFS.FileSystem(this.db_name, 'FORMAT'); + }); + + afterEach(function() { + indexedDB.deleteDatabase(this.db_name); + delete this.fs; + }); + + it('should be a function', function() { + expect(typeof this.fs.readdir).toEqual('function'); + }); + + it('should return an error if the path does not exist', function() { + var complete = false; + var _error; + var that = this; + + that.fs.readdir('/tmp/mydir', function(error) { + _error = error; + + complete = true; + }); + + waitsFor(function() { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function() { + expect(_error).toBeDefined(); + }); + }); + + it('should return a list of files from an existing directory', function() { + var complete = false; + var _error, _files; + var that = this; + + that.fs.mkdir('/tmp', function(error) { + that.fs.readdir('/', function(error, result) { + _error = error; + _files = result; + + complete = true; + }); + }); + + waitsFor(function() { + return complete; + }, 'test to complete', DEFAULT_TIMEOUT); + + runs(function() { + expect(_error).not.toBeDefined(); + expect(_files.length).toEqual(1); + expect(_files[0]).toEqual('tmp'); + }); + }); +}); + describe('fs.rmdir', function() { beforeEach(function() { this.db_name = mk_db_name();