text: var SFTP,__extends=this&&this.__extends||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);function r(){this.constructor=t}t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};!function(t){function e(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);function r(){this.constructor=t}r.prototype=e.prototype,t.prototype=new r}var n=function(){function t(){this._events={}}return t.listenerCount=function(t,e){if(!t||void 0===t._events)return 0;var n=t._events[e];return n?n.length:0},t.prototype.addListener=function(t,e){var n=this._events[t]||[];return n.push(e),this._events[t]=n,this},t.prototype.on=function(t,e){return this.addListener(t,e)},t.prototype.once=function(t,e){var n=this,r=function(){for(var i=[],o=0;o<arguments.length;o++)i[o-0]=arguments[o];n.removeListener(t,r),e.apply(n,i)};return this.addListener(t,r)},t.prototype.removeListener=function(t,e){var n=this._events[t];if(Array.isArray(n)){var r=n.indexOf(e);return r>=0&&n.splice(r,1),this}},t.prototype.removeAllListeners=function(t){return"string"==typeof t?delete this._events[t]:void 0===t&&(this._events={}),this},t.prototype.listeners=function(t){return this._events[t]},t.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=this._events[t],i=!1;if(Array.isArray(r))for(var o=0;o<r.length;o++)r[o].apply(null,e),i=!0;if(!i&&"error"==t){var s=e[0];throw console.error(s),s}return i},t}(),r=function(){function t(){}return t.nextTick=function(t){window.setTimeout(t,0)},t.platform="browser",t}();var i=function(t){function n(){t.call(this)}return e(n,t),n.prototype.on=function(e,n){return t.prototype.on.call(this,e,n)},n}(n),o=function(t,e){e=e||0,"undefined"!=typeof Buffer&&t instanceof Buffer?(this.storage=new Array(8),this.storage[0]=t[0+e],this.storage[1]=t[1+e],this.storage[2]=t[2+e],this.storage[3]=t[3+e],this.storage[4]=t[4+e],this.storage[5]=t[5+e],this.storage[6]=t[6+e],this.storage[7]=t[7+e]):t instanceof Array?this.storage=t.slice(e,8):(this.storage=this.storage||new Array(8),this.setValue.apply(this,arguments))};function s(t,e,r){return function(i){for(var o=[],s=1;s<arguments.length;s++)o[s-1]=arguments[s];var a=arguments[0];try{if("function"==typeof r)r.apply(t,arguments),a=null;else if(e)if(a)n.listenerCount(e,"error")&&(e.emit("error",a),a=null),e.emit("finish",a);else switch(arguments.length){case 0:case 1:e.emit("success"),e.emit("finish",a);break;case 2:e.emit("success",arguments[1]),e.emit("finish",a,arguments[1]);break;case 3:e.emit("success",arguments[1],arguments[2]),e.emit("finish",a,arguments[1],arguments[2]);break;default:arguments[0]="success",e.emit.apply(e,arguments),n.listenerCount(e,"finish")>0&&(arguments[0]="finish",Array.prototype.splice.call(arguments,1,0,a),e.emit.apply(e,arguments))}}catch(i){a&&t.emit("error",a),a=i}a&&t.emit("error",a)}}o.MAX_INT=Math.pow(2,53),o.prototype={toNumber:function(t){for(var e=this.storage,n=128&e[0],r=0,i=1,s=7,a=1;s>=0;s--,a*=256){var h=e[0+s];n&&(i=(h=(255^h)+i)>>8,h&=255),r+=h*a}return!t&&r>=o.MAX_INT?n?-1/0:1/0:n?-r:r}};var a=function(){function t(t){if("utf8"!=(t+"").toLowerCase().replace("-",""))throw new Error("Encoding not supported: "+t)}return t.prototype.getEncoder=function(t){return new h(t)},t.prototype.getDecoder=function(){return new c},t.prototype.encode=function(t,e,n,r){return u(t,e,n,r)},t.prototype.decode=function(t,e,n){return f(t,e,n)},t.UTF8=new t("utf8"),t}(),h=function(){function t(t){"string"!=typeof t&&(t=""+t),this._value=t}return t.prototype.finished=function(){return this._done},t.prototype.read=function(t,e,n){return u(this._value,t,e,n,this)},t}();function u(t,e,n,r,i){var o,s,a;r=r||e.length,i?(o=0|i._code,s=0|i._length,a=0|i._position):(o=0,s=0,a=0);for(var h=!1,u=n;;){if(s>0){if(n>=r)break;if(e[n++]=o>>12|128,s>1){o=(4095&o)<<6,s--;continue}s=0,o=0}if(a>=t.length){if(a=0,0==o){h=!0;break}t=String.fromCharCode(65533),o=0}if(n>=r)break;var c=t.charCodeAt(a++);if(0==o){if(o=c,c>=55296&&c<56320){o=65536+((1023&o)<<10);continue}o=c>=56320&&c<57344?65533:c}else c>=56320&&c<57344?o+=1023&c:o=65533;o<=127?(e[n++]=o,o=0):o<=2047?(s=1,e[n++]=o>>6|192,o=(63&o)<<12):o<=65535?(s=2,e[n++]=o>>12|224,o=(4095&o)<<6):o<=1114111?(s=3,e[n++]=o>>18|240,o&=2097151):(o=65533,s=2,e[n++]=o>>12|224,o=(4095&o)<<6)}if(i)i._code=o,i._length=s,i._position=a,i._done=h;else if(!h)return-1;return n-u}var c=function(){function t(){}return t.prototype.text=function(){return this._text},t.prototype.write=function(t,e,n){f(t,e,n,this);var r=this._text;this._removeBom&&r.length>0&&(65279==r.charCodeAt(0)&&(this._text=r.substr(1)),this._removeBom=!1)},t}();function f(t,e,n,r){var i,o,s;for(n=n||t.length,r?(i=r._text||"",o=0|r._code,s=0|r._length):(i="",o=0,s=0);e<n;){var a=t[e++];if(s>0){if(128!=(192&a))o=65533,s=0;else if(o=o<<6|63&a,--s>0)continue}else if(a<=128)o=a,s=0;else switch(224&a){case 224:16&a?(o=7&a,s=3):(o=15&a,s=2);continue;case 192:o=31&a,s=1;continue;default:o=65533,s=0}o>=65536&&((o-=65536)>1048575?o=65533:(i+=String.fromCharCode(55296+(o>>10&1023)),o=56320+(1023&o))),i+=String.fromCharCode(o)}return r?(r._code=o,r._length=s,r._text=i,null):(s>0&&(i+=String.fromCharCode(65533)),i)}var l=function(){function t(t,e){"string"!=typeof t&&(t=""+t),this.path=t,this.fs=e||null}return t.prototype._windows=function(){return this.fs&&this.fs.isWindows&&!0},t.prototype.isTop=function(){var t=this.path;if(0==t.length||"/"==t)return!0;if(this._windows()){if("\\"==t)return!0;if(":"!=t[1])return!1;if(2==t.length)return!0;if(3==t.length&&("/"==t[2]||"\\"==t[2]))return!0}return!1},t.prototype.getName=function(){var t=this.path,e=this._windows(),n=t.lastIndexOf("/");return n<0&&e&&(n=t.lastIndexOf("\\")),n<0?t:t.substr(n+1)},t.prototype.getParent=function(){var e=this.path,n=this._windows(),r=e.lastIndexOf("/");return r<0&&n&&(r=e.lastIndexOf("\\")),new t(e=r<0?"":0==r?"/":e.substr(0,r),this.fs)},t.prototype.startsWith=function(t){if(0==t.length)return!1;var e=this.path;if(e.length<t.length)return!1;if(1==t.length)return e[0]===t;for(var n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0},t.prototype.endsWithSlash=function(){var t=this.path[this.path.length-1];return"/"==t||!("\\"!=t||!this._windows())},t.prototype.removeTrailingSlash=function(){var e=this.path,n=this._windows(),r=e.length;if(r>1){var i=e[r-1];("/"==i||"\\"==i&&n)&&(e=e.substr(0,r-1))}return new t(e,this.fs)},t.prototype.normalize=function(){var e=this.path;return new t(e=this._windows()?e.replace(/\//g,"\\"):e.replace(/\\/g,"/"),this.fs)},t.prototype.toString=function(){return this.path},t.prototype.join=function(){for(var e=[],n=0;n<arguments.length;n++)e[n-0]=arguments[n];var r=""+this.path,i=this._windows();return e.forEach(function(t){if(void 0!==t&&0!=(t=""+t).length)if(0==r.length||"/"===t[0]||"~"===t||"~"===t[0]&&"/"===t[1])r=t;else if(i&&("\\"===t[0]||"~"===t[0]&&"\\"===t[1]||":"===t[1]))r=t;else{var e=r[r.length-1];"/"===e||i&&"\\"===e?r+=t:r=r+"/"+t}}),0==r.length?r=".":i&&(r=r.replace(/\//g,"\\")),new t(r,this.fs)},t.create=function(e,n,r){return new t(e=t.check(e,r),n).normalize()},t.check=function(t,e){if(void 0===e&&(e="path"),"string"!=typeof t){if(null===t||void 0===t)throw new Error("Missing "+e);if("function"==typeof t)throw new Error("Invalid "+e);t=""+t}if(0==t.length)throw new Error("Empty "+e);return t},t}(),p=function(){function t(){}return t.isDirectory=function(t){return!!t&&16384==(61440&t.mode)},t.isFile=function(t){return!!t&&32768==(61440&t.mode)},t.toString=function(t,e){var n,r=e.mode;switch(61440&r){case 8192:n="c";break;case 16384:n="d";break;case 24576:n="b";break;case 32768:n="-";break;case 40960:n="l";break;case 49152:n="s";break;case 4096:n="p";break;default:n="-"}r&=511;for(var i=0;i<3;i++){var o=r>>3*(2-i)&7;n+=4&o?"r":"-",n+=2&o?"w":"-",n+=1&o?"x":"-"}var s=e.size.toString();s=s.length<9?"         ".slice(s.length-9)+s:" "+s;var a=e.mtime,h=((new Date).getTime()-a.getTime())/86400,u=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][a.getUTCMonth()],c=a.getUTCDate();return u+=(c<=9?"  ":" ")+c,u+=h<-30||h>180?"  "+a.getUTCFullYear():" "+("0"+a.getUTCHours()).slice(-2)+":"+("0"+a.getUTCMinutes()).slice(-2),n+" "+(void 0===e.nlink?1:e.nlink)+" user group "+s+" "+u+" "+t},t.mkdir=function(e,n,r){e.stat(n,function(i,o){return i?"ENOENT"!=i.code?r(i):void e.mkdir(n,null,r):t.isDirectory(o)?r(null):r(new Error("Path is not a directory"))})},t.copy=function(t,e,n,r){var i=!0,o=!0,s=!1,a=!1,h=null,u=0,c=null;function f(){var r=t.read();return!!r&&(i=!1,o=e.write(r,function(){u+=r.length,n.emit("progress",t.path,u,t.length)}))}function l(){if(!s)return t.close();a||(a=!0,r(h))}t.on("readable",function(){for(null==c&&function(){var r=t.name;void 0===r&&(r=""+e.name);var i=t.relativePath;void 0===i&&(i=r);c={filename:r,stats:t.stats||{size:t.length},path:i},n.emit("transferring",c)}();o&&f(););}),t.on("end",function(){s=!0,i&&e.acceptsEmptyBlocks&&e.write(new Uint8Array(0)),e.end()}),t.on("error",function(t){h=h||t||new Error("Unspecified error"),s=!0,e.end()}),e.on("drain",function(){o=!0;do{if(!f())break}while(o)}),e.on("finish",function(){c&&n.emit("transferred",c),l()}),e.on("error",function(t){h=h||t||new Error("Unspecified error"),l()})},t}();function d(t,e,n,r,i){if(0==e.length)throw new Error("Empty path");n||(n={emit:function(t){return!1}});var o=!(r=r||{}).onlydir,s=!r.nodir,a=r.noglobstar||!1,h=0|r.depth,u=r.dotdirs||!1,c=r.listonly||!1,f=!r.noexpand;if(!o&&!s)throw new Error("Not matching anything with the specified options");var d=1==t.isWindows;"/"==(e=new l(e,null).normalize().path)[e.length-1]&&(f?e+="*":(e=e.substr(0,e.length-1),c=!0));var y,v,w=[],m=[],g=[],_=e.indexOf("*"),b=e.indexOf("?"),k=_<0?b:b<0?_:b;if(k>=0){if(r.nowildcard||r.itemonly)throw new Error("Wildcards not allowed");if(r.listonly)if(e.indexOf("/",k)>k)throw new Error("Wildcards only allowed in the last path segment");k=e.lastIndexOf("/",k);var E=e.substr(k+1);x(e=k>=0?e.substr(0,k):".",E)}else t.stat(e,function(t,o){if(t)return i(t,null);try{if(!r.itemonly)if(p.isDirectory(o)){if(f)return x(e,"*")}else{if(c)return i(new Error("The specified path is not a directory"),null);if(!p.isFile(o))return i(null,w)}var s;(k=e.lastIndexOf("/"))<0?e="./"+(s=e):s=e.substr(k+1);var a={filename:s,stats:o,path:e,relativePath:s};return w.push(a),n.emit("item",a),i(null,w)}catch(t){return i(t,null)}});return;function x(e,c){(0==e.length||d&&2==e.length&&":"==e[1])&&(e+="/"),y=new l(e,t).normalize(),c="/"+c;var f=null;if(!a){var _=c.indexOf("/**");_>=0&&(_==c.length-3?(f="*",c=c.substr(0,_)):"/"==c[_+3]&&(f=c.substr(_+4),c=c.substr(0,_)))}for(var b=c.split("/"),k=1;k<b.length;k++){var E=S(c=b[k],!1);g.push(E)}null!=f&&(g.push(null),v=S(f,!0)),m.push({path:new l("",null),pattern:0,depth:0}),function(){var e=m.shift();if(!e)return r.nosort||w.sort(function(t,e){return t.relativePath<e.relativePath?-1:t.relativePath>e.relativePath?1:0}),i(null,w);var a;var c;var f;var d;var _;var b;var k;try{if(a=e.path,c=e.pattern,d=e.depth,f=g[c]){var E=(_=c+1)==g.length;b=E&&null==v,k=!E}else _=c,b=!0,k=0==h||h>0&&d<h,d++;var x=y.join(a).normalize().path;t.opendir(x,function(e,a){if(e)return i(e,null);n.emit("traversing",x);var c=null,f=1;t.readdir(a,function e(d,_){try{if(f--,(c=c||d)||!_){if(f>0)return;return void t.close(a,function(a){if(c=c||a,a)return i(c,null);n.emit("traversed",x),function f(){var a=m.shift();if(!a)return r.nosort||w.sort(function(t,e){return t.relativePath<e.relativePath?-1:t.relativePath>e.relativePath?1:0}),i(null,w);var c;var d;var _;var b;var k;var E;var x;try{if(c=a.path,d=a.pattern,b=a.depth,_=g[d]){var P=(k=d+1)==g.length;E=P&&null==v,x=!P}else k=d,E=!0,x=0==h||h>0&&b<h,b++;var S=y.join(c).normalize().path;t.opendir(S,function(r,o){if(r)return i(r,null);n.emit("traversing",S);var s=null,a=1;t.readdir(o,function(r,h){try{if(a--,(s=s||r)||!h){if(a>0)return;return void t.close(o,function(t){if(s=s||t,t)return i(s,null);n.emit("traversed",S),f()})}for(h.forEach(I);a<2;)t.readdir(o,e),a++}catch(r){return i(s=s||r,null)}})})}catch(t){return i(t,null)}function I(e){var r=p.isDirectory(e.stats),i=p.isFile(e.stats),a="."==e.filename||".."==e.filename;if((!a||u)&&(r||i)){var h=c.join(e.filename);if(x&&r&&!a&&m.push({path:h,pattern:k,depth:b}),E&&(!r||s)&&(!i||o)){if(_){if(!_.test(e.filename))return}else if(!v.test(h.path))return;var f=new l(h.path,t).normalize();e.path=y.join(f).path,e.relativePath=f.path,w.push(e),n.emit("item",e)}}}}()})}for(_.forEach(P);f<2;)t.readdir(a,e),f++}catch(d){return i(c=c||d,null)}})})}catch(t){return i(t,null)}function P(e){var r=p.isDirectory(e.stats),i=p.isFile(e.stats),h="."==e.filename||".."==e.filename;if((!h||u)&&(r||i)){var c=a.join(e.filename);if(k&&r&&!h&&m.push({path:c,pattern:_,depth:d}),b&&(!r||s)&&(!i||o)){if(f){if(!f.test(e.filename))return}else if(!v.test(c.path))return;var g=new l(c.path,t).normalize();e.path=y.join(g).path,e.relativePath=g.path,w.push(e),n.emit("item",e)}}}}()}function P(){var e,a,c,f,d,_,b,k=m.shift();if(!k)return r.nosort||w.sort(function(t,e){return t.relativePath<e.relativePath?-1:t.relativePath>e.relativePath?1:0}),i(null,w);try{if(e=k.path,a=k.pattern,f=k.depth,c=g[a]){var E=(d=a+1)==g.length;_=E&&null==v,b=!E}else d=a,_=!0,b=0==h||h>0&&f<h,f++;var x=y.join(e).normalize().path;t.opendir(x,function(e,r){if(e)return i(e,null);n.emit("traversing",x);var o=null,s=1;t.readdir(r,function(e,a){try{if(s--,(o=o||e)||!a){if(s>0)return;return void t.close(r,function(t){if(o=o||t,t)return i(o,null);n.emit("traversed",x),P()})}for(a.forEach(S);s<2;)t.readdir(r,de),s++}catch(e){return i(o=o||e,null)}})})}catch(t){return i(t,null)}function S(r){var i=p.isDirectory(r.stats),a=p.isFile(r.stats),h="."==r.filename||".."==r.filename;if((!h||u)&&(i||a)){var g=e.join(r.filename);if(b&&i&&!h&&m.push({path:g,pattern:d,depth:f}),_&&(!i||s)&&(!a||o)){if(c){if(!c.test(r.filename))return}else if(!v.test(g.path))return;var k=new l(g.path,t).normalize();r.path=y.join(k).path,r.relativePath=k.path,w.push(r),n.emit("item",r)}}}}function S(t,e){var n="^";e&&(n+=".*");for(var r=0;r<t.length;r++){var i=t[r];switch(i){case"/":var o=t.substr(r,4);"/**/"==o||"/**"==o?(n+=".*",r+=3):n+="/";break;case"*":n+=e?"[^/]*":".*";break;case"?":n+=".";break;default:n+=i>="a"&&i<="z"||i>="A"&&i<="Z"||i>="0"&&i<="9"?i:"\\"+i}}return n+="$",new RegExp(n,d?"i":"")}}var y=function(t){function n(e,n,r,i,o){t.call(this),this.fs=e,this.path=""+n,this.name=new l(n,e).getName(),null!==r&&void 0!==r&&(this.relativePath=""+r),i?(this.length=i.size,this.stats=i):(this.length=null,this.stats=null),this.handle=null,this.nextChunkPosition=this.expectedPosition=o||0,this.queue=[],this.started=!1,this.eof=!1,this.closed=!1,this.ended=!1,this.requests=0,this.readable=!1,this.failed=!1}return e(n,t),n.prototype.on=function(e,n){return this._flush(),t.prototype.on.call(this,e,n)},n.prototype._flush=function(){var e=this;try{if(this.closed||this.eof){if(this.requests>0)return;if(null!=this.handle)return this._close();if(this.readable)return;return void(this.ended||(this.ended=!0,this.failed||r.nextTick(function(){return t.prototype.emit.call(e,"end")})))}if(!this.started)return this._open();if(null==this.handle)return;for(;this.requests<4&&!this.closed&&!(this.nextChunkPosition-this.expectedPosition>131072);){this._next(this.nextChunkPosition,32768),this.nextChunkPosition+=32768}}catch(t){this._error(t)}},n.prototype._next=function(e,n){var r=this;this.requests++;try{this.fs.read(this.handle,new Uint8Array(n),0,n,e,function(i,o,s){if(r.requests--,i)return r._error(i);if(r.closed)r._flush();else{if(0==o)return r.eof=!0,void r._flush();try{var a=s.subarray(0,o);a.position=e;for(var h=r.queue.length;--h>=0&&!(e>r.queue[h].position););r.queue.splice(++h,0,a),o>0&&o<n&&r._next(e+o,n-o),r._flush(),r.readable||0!=h||a.position!=r.expectedPosition||(r.readable=!0,a.length>0&&t.prototype.emit.call(r,"readable"))}catch(i){r._error(i)}}})}catch(t){this.requests--,this._error(t)}},n.prototype.read=function(){var t=this.queue[0];return t&&t.position==this.expectedPosition?(this.expectedPosition+=t.length,this.queue.shift(),0!=this.queue.length&&this.queue[0].position==this.expectedPosition||(this.readable=!1)):t=null,this._flush(),t},n.prototype._error=function(e){var n=this;this.closed=!0,this.failed=!0,this.queue=[],this._flush(),r.nextTick(function(){return t.prototype.emit.call(n,"error",e)})},n.prototype._open=function(){var t=this;if(!this.started){this.started=!0;try{this.fs.open(this.path,"r",function(e,n){if(e)return t._error(e);if(t.stats)return t.handle=n,void t._flush();try{t.fs.fstat(n,function(e,r){if(e)return t._error(e);t.handle=n,t.stats=r,t.length=r.size,t._flush()})}catch(e){t._error(e)}})}catch(t){this._error(t)}}},n.prototype._close=function(){var t=this;if(this.handle){var e=this.handle;this.handle=null;try{return void this.fs.close(e,function(e){if(e)return t._error(e);t._flush()})}catch(t){this._error(t)}}},n.prototype.close=function(){this.closed=!0,this.queue=[],this._flush()},n}(n),v=function(t){function n(e,n){var r=this;t.call(this),this.name=e.name,this.length=e.size,this.blob=e,this.pos=n,this.reader=new FileReader,this.busy=!1,this.readable=!1,this.finished=!1,this.ended=!1,this.queue=[],this.reader.onload=function(e){if(r.busy=!1,!r.finished){var n=new Uint8Array(e.target.result);n.length>0?(r.queue.push(n),r.readable||(r.readable=!0,t.prototype.emit.call(r,"readable"))):r.finished=!0}r.flush()}}return e(n,t),n.prototype.on=function(e,n){return this.flush(),t.prototype.on.call(this,e,n)},n.prototype.flush=function(){var e=this;try{if(this.finished)return void(this.ended||(this.ended=!0,r.nextTick(function(){return t.prototype.emit.call(e,"end")})));if(!this.busy&&this.queue.length<4){var n=this.blob.slice(this.pos,this.pos+32768);this.pos+=n.size,this.busy=!0,this.reader.readAsArrayBuffer(n)}}catch(n){this.finished=!0,this.ended=!0,this.queue=[],r.nextTick(function(){return t.prototype.emit.call(e,"error",n)})}},n.prototype.read=function(){var t=this.queue.shift();return t||(t=null,this.readable=!1),this.flush(),t},n.prototype.close=function(){this.finished=!0,this.flush()},n}(n);function w(t,e,n,i){try{o(e,i)}catch(t){r.nextTick(function(){return i(t)})}function o(e,u){if(h(e))return function(e){var n=[],s=[];function u(){try{var e=s.shift();if(!e)return i(null,n);if(h(e))throw new Error("Unsupported array of arrays data source");a(e)?function(e,n){if(!t)throw new Error("Source file system not available");t.stat(e,function(r,i){if(r)return n(r,null);var o=new y(t,e,null,i,0);n(null,[o])})}(e,c):o(e,c)}catch(t){r.nextTick(function(){return i(t)})}}function c(t,e){if(t)return i(t,null);Array.prototype.push.apply(n,e),u()}Array.prototype.push.apply(s,e),u()}(e);if(a(e))return function(e){if(!t)throw new Error("Source file system not available");d(t,e,n,{noexpand:!0},function(e,n){if(e)return i(e,null);var r=[];n.forEach(function(e){var n=new y(t,e.path,e.relativePath,e.stats,0);r.push(n)}),i(null,r)})}(e);if(s(e))return c=e,void r.nextTick(function(){var t=new v(c,0);i(null,[t])});var c;throw new Error("Unsupported source")}function s(t){return"object"==typeof t&&"number"==typeof t.size&&"string"==typeof t.name&&"function"==typeof t.slice}function a(t){return"string"==typeof t}function h(t){return!!Array.isArray(t)||"object"==typeof t&&"number"==typeof t.length&&(0==t.length||(a(t)||s(t[0])))}}var m=function(t){function n(e,r){t.call(this),this.fs=e,this.path=""+r,this.name=new l(this.path,e).getName(),this.handle=null,this.position=0,this.queue=[],this.requests=0,this.started=!1,this.ready=!1,this.ended=!1,this.finished=!1,n.prototype.acceptsEmptyBlocks=!0}return e(n,t),n.prototype.on=function(e,n){return t.prototype.on.call(this,e,n)},n.prototype._flush=function(e){var n=this;if(this.ended&&0==this.requests&&0==this.queue.length)return null!=this.handle?this._close():void(this.finished||(this.finished=!0,e?r.nextTick(function(){return t.prototype.emit.call(n,"finish")}):t.prototype.emit.call(this,"finish")));if(this.handle)try{if(this.requests>=4)return void(this.ready=!1);for(;this.requests<4;){var i=this.queue.shift();if(!i)break;this._next(i,this.position),this.position+=i.length}this.ready||this.ended||(this.ready=!0,e||t.prototype.emit.call(this,"drain"))}catch(t){this._error(t)}},n.prototype._next=function(t,e){var n=this,r=t.length;this.requests++;try{this.fs.write(this.handle,t,0,r,e,function(e){if(n.requests--,e)return n._error(e);"function"==typeof t.callback&&t.callback(),n._flush(!1)})}catch(t){this.requests--,this._error(t)}},n.prototype._error=function(e){var n=this;this.ready=!1,this.ended=!0,this.finished=!0,this.queue=[],this._flush(!1),r.nextTick(function(){return t.prototype.emit.call(n,"error",e)})},n.prototype.write=function(t,e){return!this.ended&&(t.length>0&&(t.callback=e,this.queue.push(t)),this.started?(this._flush(!0),this.ready):(this._open(),!1))},n.prototype._open=function(){var t=this;if(!this.started){this.started=!0;try{this.fs.open(this.path,"w",function(e,n){if(e)return t._error(e);t.handle=n,t._flush(!1)})}catch(t){this._error(t)}}},n.prototype._close=function(){var t=this;if(this.handle){var e=this.handle;this.handle=null;try{this.fs.close(e,function(e){if(e)return t._error(e);t._flush(!1)})}catch(t){this._error(t)}}},n.prototype.end=function(){this.ready=!1,this.ended=!0,this._flush(!0)},n}(n),g=function(t){function n(){t.call(this)}return e(n,t),n.prototype.on=function(e,n){return t.prototype.on.call(this,e,n)},n.prototype._data=function(e){t.prototype.emit.call(this,"data",e)},n.prototype._end=function(){t.prototype.emit.call(this,"end")},n.prototype.write=function(t,e){return this._data(t),"function"==typeof e&&e(),!0},n.prototype.end=function(){this._end(),t.prototype.emit.call(this,"finish")},n}(n),_=function(t){function n(e){t.call(this),this._decoder=new a(e).getDecoder()}return e(n,t),n.prototype._data=function(t){this._decoder.write(t,0,t.length)},n.prototype._end=function(){},n.prototype.result=function(){return this._decoder.text()},n}(g),b=function(t){function n(e){t.call(this),this._chunks=[],this._mimeType=e}return e(n,t),n.prototype._data=function(t){this._chunks.push(t)},n.prototype._end=function(){var t;this._mimeType&&(t={type:this._mimeType}),this._blob=new Blob(this._chunks,t),this._chunks.length=0},n.prototype.result=function(){return this._blob},n}(g),k=function(t){function n(){t.call(this),this._chunks=[],this._length=0}return e(n,t),n.prototype._data=function(t){this._length+=t.length,this._chunks.push(t)},n.prototype._end=function(){this._buffer=new Uint8Array(this._length);for(var t=0,e=0;e<this._chunks.length;e++){var n=this._chunks[e];this._buffer.set(n,t),t+=n.length}this._chunks.length=0},n.prototype.result=function(){return this._buffer},n}(g),E=function(t){function n(e,n){t.call(this),this._fs=e,this._local=n}return e(n,t),n.prototype.open=function(t,e,n,r){"function"==typeof n&&void 0===r&&(r=n,n=null),r=s(this,null,r),this._fs.open(t,e,n,r)},n.prototype.close=function(t,e){e=s(this,null,e),this._fs.close(t,e)},n.prototype.read=function(t,e,n,r,i,o){o=s(this,null,o),this._fs.read(t,e,n,r,i,o)},n.prototype.write=function(t,e,n,r,i,o){o=s(this,null,o),this._fs.write(t,e,n,r,i,o)},n.prototype.lstat=function(t,e){e=s(this,null,e),this._fs.lstat(t,e)},n.prototype.fstat=function(t,e){e=s(this,null,e),this._fs.fstat(t,e)},n.prototype.setstat=function(t,e,n){n=s(this,null,n),this._fs.setstat(t,e,n)},n.prototype.fsetstat=function(t,e,n){n=s(this,null,n),this._fs.fsetstat(t,e,n)},n.prototype.opendir=function(t,e){e=s(this,null,e),this._fs.opendir(t,e)},n.prototype.readdir=function(t,e){if("string"!=typeof t)return e=s(this,null,e),this._fs.readdir(t,e);var n=l.check(t,"path");d(this._fs,n,null,{noglobstar:!0,nowildcard:!0,listonly:!0,dotdirs:!0},e)},n.prototype.unlink=function(t,e){e=s(this,null,e),this._fs.unlink(t,e)},n.prototype.mkdir=function(t,e,n){"function"==typeof e&&void 0===n&&(n=e,e=null),n=s(this,null,n),this._fs.mkdir(t,e,n)},n.prototype.rmdir=function(t,e){e=s(this,null,e),this._fs.rmdir(t,e)},n.prototype.realpath=function(t,e){e=s(this,null,e),this._fs.realpath(t,e)},n.prototype.stat=function(t,e){e=s(this,null,e),this._fs.stat(t,e)},n.prototype.rename=function(t,e,n){n=s(this,null,n),this._fs.rename(t,e,n)},n.prototype.readlink=function(t,e){e=s(this,null,e),this._fs.readlink(t,e)},n.prototype.symlink=function(t,e,n){n=s(this,null,n),this._fs.symlink(t,e,n)},n.prototype.join=function(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];var n=new l("",this._fs);return n.join.apply(n,arguments).normalize().path},n.prototype.link=function(t,e,n){n=s(this,null,n),this._fs.link(t,e,n)},n.prototype.list=function(t,e){t=l.check(t,"remotePath");var n=new i;return e=s(this,n,e),d(this._fs,t,n,{directories:!0,files:!0,nosort:!1,dotdirs:!1,noglobstar:!0,listonly:!0},e),n},n.prototype.search=function(t,e,n){t=l.check(t,"remotePath");"function"==typeof e&&void 0===n&&(n=e,e=null);var r=new i;return n=s(this,r,n),d(this._fs,t,r,e,n),r},n.prototype.info=function(t,e){t=l.check(t,"remotePath");var n=new i;return e=s(this,n,e),d(this._fs,t,n,{itemonly:!0},function(t,n){return t?e(t,null):n&&1==n.length?void e(null,n[0]):e(new Error("Unexpected result"),null)}),n},n.prototype.readFile=function(t,e,n){var r=l.create(t,this._fs,"remotePath");"function"==typeof e&&void 0===n&&(n=e,e=null);var o=new i;n=s(this,o,n);var a,h=(e=e||{}).type,u=e.encoding;switch(h?"string"!=(h=(h+"").toLowerCase())&&"text"!=h||(u=u||"utf8"):h=u?"string":"buffer",h){case"text":case"string":a=new _(u);break;case"array":case"buffer":a=new k;break;case"blob":a=new b(e.mimeType);break;default:throw new Error("Unsupported data kind: "+e.type)}var c=new y(r.fs,r.path);return p.copy(c,a,o,function(t){if(t)return n(t,null);n(null,a.result())}),o},n.prototype.putFile=function(t,e,n){var r=l.create(t,this._local,"localPath"),i=l.create(e,this._fs,"remotePath");return this._copyFile(r,i,n)},n.prototype.getFile=function(t,e,n){var r=l.create(t,this._fs,"remotePath"),i=l.create(e,this._local,"localPath");return this._copyFile(r,i,n)},n.prototype._copyFile=function(t,e,n){var r=new i;if(n=s(this,r,n),e.endsWithSlash()){var o=t.getName();e=e.join(o)}var a=new y(t.fs,t.path),h=new m(e.fs,e.path);return p.copy(a,h,r,function(t){return n(t)}),r},n.prototype.upload=function(t,e,n){var r=l.create(e,this._fs,"remotePath");return this._copy(t,this._local,r,n)},n.prototype.download=function(t,e,n){var r=l.create(e,this._local,"localPath");return this._copy(t,this._fs,r,n)},n.prototype._copy=function(t,e,n,r){var o=new i;r=s(this,o,r);var a=null,h=n.fs;n=n.removeTrailingSlash(),h.stat(n.path,function(i,s){if(i)return r(i);if(!p.isDirectory(s))return r(new Error("Target path is not a directory"));try{w(e,t,o,function(t,i){if(t)return r(t);try{(a=i).forEach(function(t){}),function t(){var i=a.shift();if(!i)return r(null);var s;if("string"==typeof i.relativePath){var c=new l(i.relativePath,e);s=n.join(c).normalize().path,function t(e,r){var i=e.getParent();if(i.isTop())return r(null);var o=u[i];if(o)return r(null);t(i,function(t){if(t)return r(t);try{var e=n.join(i).path;p.mkdir(h,e,function(t){if(t)return r(t);u[i]=!0,r(null)})}catch(t){r(t)}})}(c,f)}else s=n.join(i.name).path,f(null);function f(t){if(t)return r(t);if(p.isDirectory(i.stats))p.mkdir(h,s,d);else{var e=new m(h,s);p.copy(i,e,o,d)}}function d(e){if(e)return r(e);t()}}()}catch(t){r(t)}})}catch(i){r(i)}});var u={};return o},n}(n),x=function(){function t(t){var e=this;this.ws=t,this.failed=!1,this.wasConnected=t.readyState==WebSocket.OPEN,this.ws.onclose=function(t){var n=t.code,r=t.reason;e.close(n,r)},this.ws.onerror=function(t){e.failed=!0},this.ws.onmessage=function(t){var n;n=new Uint8Array(t.data),"function"==typeof e.onmessage&&e.onmessage(n)}}return t.prototype.open=function(t){var e=this;"function"!=typeof t&&(t=function(){});var n=0,i=null;switch(this.ws.readyState){case WebSocket.CLOSED:case WebSocket.CLOSING:n=999,i="WebSocket has been closed";break;case WebSocket.OPEN:return this.wasConnected=!0,void r.nextTick(function(){return t()});case WebSocket.CONNECTING:break;default:n=999,i="WebSocket state is unknown"}null==i?(this.onopen=t,this.ws.onopen=function(){e.wasConnected=!0;var t=e.onopen;e.onopen=null,"function"==typeof t&&t()}):r.nextTick(function(){e.close(n,i)})},t.prototype.on=function(t,e){switch(t){case"ready":this.open(e);break;case"message":this.onmessage=e;break;case"close":this.onclose=e;break;case"error":this.onerror=e}return this},t.prototype.reportError=function(t){if("function"!=typeof this.onerror)throw t;this.onerror(t)},t.prototype.close=function(t,e,n){if("number"!=typeof t&&(t=1e3),e=""+e,n=n||"EFAILURE",null!=this.ws)try{this.ws.close()}catch(o){this.reportError(o)}finally{this.ws=null}var r=this.onclose;if(this.onopen=null,this.onclose=null,"function"==typeof r){var i,o=null;switch(t){case 999:i=e;break;case 1e3:i="Connection closed",n="ECONNRESET";break;case 1006:i="Connection aborted",n="ECONNABORTED";break;default:i="Connection failed",n="ECONNRESET"}this.wasConnected&&!this.failed&&1e3==t||(this.wasConnected?this.failed&&(i="Connection failed",n="ECONNRESET"):(i="Unable to connect",n="ECONNREFUSED"),o=new Error(i),t>=1e3&&(o.reason=t),o.code=n),r(o)}},t.prototype.send=function(t){var e=this;if(null!=this.ws)try{this.ws.send(t)}catch(t){r.nextTick(function(){e.reportError(t)})}},t}(),P=function(){function t(){}return t.prototype.check=function(t){if(t>this.length-this.position)throw new Error("Unexpected end of packet")},t.prototype.skip=function(t){this.check(t),this.position+=t},t.isBuffer=function(t){return t&&t.buffer instanceof ArrayBuffer&&void 0!==t.byteLength},t}(),S=function(t){function n(e){if(t.call(this),this.buffer=e,this.position=0,this.length=e.length,this.readInt32()+4!=this.length)throw new Error("Invalid packet received");this.type=this.readByte(),1==this.type||2==this.type?this.id=null:(this.id=this.readInt32(),200==this.type&&(this.type=this.readString()))}return e(n,t),n.prototype.readByte=function(){return this.check(1),255&this.buffer[this.position++]},n.prototype.readInt32=function(){var t=this.readUint32();return 2147483648&t&&(t-=4294967296),t},n.prototype.readUint32=function(){this.check(4);var t=0;return t|=(255&this.buffer[this.position++])<<24,t|=(255&this.buffer[this.position++])<<16,t|=(255&this.buffer[this.position++])<<8,t|=255&this.buffer[this.position++]},n.prototype.readInt64=function(){var t=[this.buffer[this.position++],this.buffer[this.position++],this.buffer[this.position++],this.buffer[this.position++],this.buffer[this.position++],this.buffer[this.position++],this.buffer[this.position++],this.buffer[this.position++]];return new o(t).toNumber(!1)},n.prototype.readString=function(){var t=this.readInt32();this.check(t);var e=this.position+t,n=f(this.buffer,this.position,e);return this.position=e,n},n.prototype.skipString=function(){var t=this.readInt32();this.check(t);var e=this.position+t;this.position=e},n.prototype.readData=function(t){var e=this.readInt32();this.check(e);var n=this.position,r=n+e;this.position=r;var i=this.buffer.subarray(n,r);if(t){var o=new Uint8Array(e);return o.set(i,0),o}return i},n}(P),I=function(t){function n(e){t.call(this),this.buffer=new Uint8Array(e),this.position=0,this.length=e}return e(n,t),n.prototype.start=function(){this.position=0,this.writeInt32(0),"number"==typeof this.type?this.writeByte(this.type):this.writeByte(200),1==this.type||2==this.type||(this.writeInt32(0|this.id),"number"!=typeof this.type&&this.writeString(this.type))},n.prototype.finish=function(){var t=this.position;return this.position=0,this.writeInt32(t-4),this.buffer.subarray(0,t)},n.prototype.writeByte=function(t){this.check(1),this.buffer[this.position++]=255&t},n.prototype.writeInt32=function(t){this.check(4),this.buffer[this.position++]=t>>24&255,this.buffer[this.position++]=t>>16&255,this.buffer[this.position++]=t>>8&255,this.buffer[this.position++]=255&t},n.prototype.writeInt64=function(t){var e=t/4294967296|0,n=4294967295&t|0;this.writeInt32(e),this.writeInt32(n)},n.prototype.writeString=function(t){"string"!=typeof t&&(t=""+t);var e=this.position;this.writeInt32(0);var n=u(t,this.buffer,this.position);if(n<0)throw new Error("Not enough space in the buffer");this.position=e,this.writeInt32(n),this.position+=n},n.prototype.writeData=function(t,e,n){void 0!==e&&(t=t.subarray(e,n));var r=t.length;this.writeInt32(r),this.check(r),this.buffer.set(t,this.position),this.position+=r},n}(P),q=function(){function t(){}return t.toNumber=function(t){if("number"==typeof t)return 63&t;switch(t){case"r":return 1;case"r+":return 3;case"w":return 26;case"w+":return 27;case"wx":case"xw":return 42;case"wx+":case"xw+":return 43;case"a":return 14;case"a+":return 15;case"ax":case"xa":return 46;case"ax+":case"xa+":return 47;default:throw Error("Invalid flags '"+t+"'")}},t.fromNumber=function(t){switch(0!=(32&(t&=63))&&(t&=47),0!=(16&t)&&(t&=59),0==(3&t)&&(t|=1),0==(8&t)?t&=3:t|=2,t){case 1:return["r"];case 2:case 3:return["r+"];case 10:return["wx","r+"];case 11:return["wx+","r+"];case 14:return["a"];case 15:return["a+"];case 26:return["w"];case 27:return["w+"];case 42:return["wx"];case 43:return["wx+"];case 46:return["ax"];case 47:return["ax+"]}throw Error("Unsupported flags")},t}(),T=function(){function t(){}return t.isKnown=function(e){return t.hasOwnProperty("_"+e)},t.POSIX_RENAME="posix-rename@openssh.com",t.STATVFS="statvfs@openssh.com",t.FSTATVFS="fstatvfs@openssh.com",t.HARDLINK="hardlink@openssh.com",t.FSYNC="fsync@openssh.com",t.NEWLINE="newline@sftp.ws",t.CHARSET="charset@sftp.ws",t._constructor=function(){for(var e in t)t.hasOwnProperty(e)&&(t["_"+t[e]]=!0)}(),t}(),C=(function(){function t(){}t.write=function(t,e,n){t.type=101,t.start(),t.writeInt32(e),t.writeString(n),t.writeInt32(0)},t.writeSuccess=function(t){this.write(t,0,"OK")}}(),function(){}(),function(){function t(t){if(void 0!==t){var e=this.flags=t.readUint32();if(1&e&&(this.size=t.readInt64()),2&e&&(this.uid=t.readInt32(),this.gid=t.readInt32()),4&e&&(this.mode=t.readUint32()),8&e&&(this.atime=new Date(1e3*t.readUint32()),this.mtime=new Date(1e3*t.readUint32())),2147483648&e){this.flags&=2147483647,this.size=t.readInt64();for(var n=0;n<this.size;n++)t.skipString(),t.skipString()}}else this.flags=0}return t.prototype.isDirectory=function(){return 16384==(61440&this.mode)},t.prototype.isFile=function(){return 32768==(61440&this.mode)},t.prototype.isSymbolicLink=function(){return 40960==(61440&this.mode)},t.prototype.write=function(t){var e=this.flags;t.writeInt32(e),1&e&&t.writeInt64(this.size),2&e&&(t.writeInt32(this.uid),t.writeInt32(this.gid)),4&e&&t.writeInt32(this.mode),8&e&&(t.writeInt32(this.atime.getTime()/1e3),t.writeInt32(this.mtime.getTime()/1e3)),2147483648&e&&t.writeInt32(0)},t.prototype.from=function(t){if(null==t||void 0===t)this.flags=0;else{var e=0;void 0!==t.size&&(e|=1,this.size=0|t.size),void 0===t.uid&&void 0===t.gid||(e|=2,this.uid=0|t.uid,this.gid=0|t.gid),void 0!==t.mode&&(e|=4,this.mode=0|t.mode),void 0===t.atime&&void 0===t.mtime||(e|=8,this.atime=t.atime,this.mtime=t.mtime),void 0!==t.nlink&&(this.nlink=t.nlink),this.flags=e}},t}()),N=function(){return function(){}}(),A=function(){function t(t,e){this._handle=t,this._this=e}return t.prototype.toString=function(){for(var t="0x",e=0;e<this._handle.length;e++){var n=this._handle[e],r=n.toString(16);n<16&&(t+="0"),t+=r}return t},t}(),O=function(){function t(){this._host=null,this._id=null,this._ready=!1,this._requests=[],this._extensions={},this._maxWriteBlockLength=32768,this._maxReadBlockLength=262144}return t.prototype.getRequest=function(t){var e=new I(this._maxWriteBlockLength+1024);if(e.type=t,e.id=this._id,1==t){if(null!=this._id)throw new Error("Already initialized");this._id=1}else this._id=this._id+1&4294967295;return e.start(),e},t.prototype.writeStats=function(t,e){var n=new C;n.from(e),n.write(t)},t.prototype.execute=function(t,e,n,i){var o=this;if("function"!=typeof e&&(e=function(t){if(t)throw t}),this._host){if(void 0!==this._requests[t.id])throw new Error("Duplicate request");var s=t.finish();this._host.send(s),this._requests[t.id]={callback:e,responseParser:n,info:i}}else r.nextTick(function(){var t=o.createError(6,"Not connected",i);e(t)})},t.prototype._init=function(t,e){var n=this;if(this._host)throw new Error("Already bound");this._host=t,this._extensions={};var r=this.getRequest(1);r.writeInt32(3);var i={command:"init"};this.execute(r,e,function(r,o){if(2!=r.type){t.close(3002);var s=n.createError(5,"Unexpected message",i);return e(new Error("Protocol violation"))}if(3!=r.readInt32()){t.close(3002);s=n.createError(5,"Unexpected protocol version",i);return e(s)}for(;r.length-r.position>=4;){var a,h=r.readString();a=T.isKnown(h)?r.readString():r.readData(!0);var u=n._extensions[h]||[];u.push(a),n._extensions[h]=u}n._ready=!0,e(null)},i)},t.prototype._process=function(t){var e=new S(t),n=this._requests[e.id];if(void 0===n)throw new Error("Unknown response ID");delete this._requests[e.id],e.info=n.info,n.responseParser.call(this,e,n.callback)},t.prototype._end=function(){this._host&&(this._host=null),this.failRequests(7,"Connection lost")},t.prototype.end=function(){var t=this._host;t&&(this._host=null,t.close()),this.failRequests(7,"Connection closed")},t.prototype.failRequests=function(t,e){var n=this,r=this._requests;this._requests=[],r.forEach(function(r){var i=n.createError(t,e,r.info);r.callback(i)})},t.prototype.open=function(t,e,n,r){t=this.checkPath(t,"path"),"function"==typeof n&&void 0===r&&(r=n,n=null);var i=this.getRequest(3);i.writeString(t),i.writeInt32(q.toNumber(e)),this.writeStats(i,n),this.execute(i,r,this.parseHandle,{command:"open",path:t})},t.prototype.close=function(t,e){var n=this.toHandle(t),r=this.getRequest(4);r.writeData(n),this.execute(r,e,this.parseStatus,{command:"close",handle:t})},t.prototype.read=function(t,e,n,r,i,o){var s=this,a=this.toHandle(t);this.checkBuffer(e,n,r),this.checkPosition(i),r>this._maxReadBlockLength&&(r=this._maxReadBlockLength);var h=this.getRequest(5);h.writeData(a),h.writeInt64(i),h.writeInt32(r),this.execute(h,o,function(t,h){return s.parseData(t,o,0,a,e,n,r,i)},{command:"read",handle:t})},t.prototype.write=function(t,e,n,r,i,o){var s=this.toHandle(t);if(this.checkBuffer(e,n,r),this.checkPosition(i),r>this._maxWriteBlockLength)throw new Error("Length exceeds maximum allowed data block length");var a=this.getRequest(6);a.writeData(s),a.writeInt64(i),a.writeData(e,n,n+r),this.execute(a,o,this.parseStatus,{command:"write",handle:t})},t.prototype.lstat=function(t,e){t=this.checkPath(t,"path"),this.command(7,[t],e,this.parseAttribs,{command:"lstat",path:t})},t.prototype.fstat=function(t,e){var n=this.toHandle(t),r=this.getRequest(8);r.writeData(n),this.execute(r,e,this.parseAttribs,{command:"fstat",handle:t})},t.prototype.setstat=function(t,e,n){t=this.checkPath(t,"path");var r=this.getRequest(9);r.writeString(t),this.writeStats(r,e),this.execute(r,n,this.parseStatus,{command:"setstat",path:t})},t.prototype.fsetstat=function(t,e,n){var r=this.toHandle(t),i=this.getRequest(10);i.writeData(r),this.writeStats(i,e),this.execute(i,n,this.parseStatus,{command:"fsetstat",handle:t})},t.prototype.opendir=function(t,e){t=this.checkPath(t,"path"),this.command(11,[t],e,this.parseHandle,{command:"opendir",path:t})},t.prototype.readdir=function(t,e){var n=this.toHandle(t),r=this.getRequest(12);r.writeData(n),this.execute(r,e,this.parseItems,{command:"readdir",handle:t})},t.prototype.unlink=function(t,e){t=this.checkPath(t,"path"),this.command(13,[t],e,this.parseStatus,{command:"unline",path:t})},t.prototype.mkdir=function(t,e,n){t=this.checkPath(t,"path"),"function"==typeof e&&void 0===n&&(n=e,e=null);var r=this.getRequest(14);r.writeString(t),this.writeStats(r,e),this.execute(r,n,this.parseStatus,{command:"mkdir",path:t})},t.prototype.rmdir=function(t,e){t=this.checkPath(t,"path"),this.command(15,[t],e,this.parseStatus,{command:"rmdir",path:t})},t.prototype.realpath=function(t,e){t=this.checkPath(t,"path"),this.command(16,[t],e,this.parsePath,{command:"realpath",path:t})},t.prototype.stat=function(t,e){t=this.checkPath(t,"path"),this.command(17,[t],e,this.parseAttribs,{command:"stat",path:t})},t.prototype.rename=function(t,e,n){t=this.checkPath(t,"oldPath"),e=this.checkPath(e,"newPath"),this.command(18,[t,e],n,this.parseStatus,{command:"rename",oldPath:t,newPath:e})},t.prototype.readlink=function(t,e){t=this.checkPath(t,"path"),this.command(19,[t],e,this.parsePath,{command:"readlink",path:t})},t.prototype.symlink=function(t,e,n){t=this.checkPath(t,"targetPath"),e=this.checkPath(e,"linkPath"),this.command(20,[t,e],n,this.parseStatus,{command:"symlink",targetPath:t,linkPath:e})},t.prototype.link=function(t,e,n){t=this.checkPath(t,"oldPath"),e=this.checkPath(e,"newPath"),this.command(T.HARDLINK,[t,e],n,this.parseStatus,{command:"link",oldPath:t,newPath:e})},t.prototype.toHandle=function(t){if(!t)throw new Error("Missing handle");if("object"==typeof t&&P.isBuffer(t._handle)&&t._this==this)return t._handle;throw new Error("Invalid handle")},t.prototype.checkBuffer=function(t,e,n){if(!P.isBuffer(t))throw new Error("Invalid buffer");if("number"!=typeof e||e<0)throw new Error("Invalid offset");if("number"!=typeof n||n<0)throw new Error("Invalid length");if(e+n>t.length)throw new Error("Offset or length is out of bands")},t.prototype.checkPath=function(t,e){return"~"===(t=l.check(t,e))[0]&&("/"===t[1]?t="."+t.substr(1):1==t.length&&(t=".")),t},t.prototype.checkPosition=function(t){if("number"!=typeof t||t<0||t>0x8000000000000000)throw new Error("Invalid position")},t.prototype.command=function(t,e,n,r,i){for(var o=this.getRequest(t),s=0;s<e.length;s++)o.writeString(e[s]);this.execute(o,n,r,i)},t.prototype.readStatus=function(t){var e=t.readInt32(),n=t.readString();if(0==e)return null;var r=t.info;return this.createError(e,n,r)},t.prototype.readItem=function(t){var e=new N;return e.filename=t.readString(),e.longname=t.readString(),e.stats=new C(t),e},t.prototype.createError=function(t,e,n){var r,i;switch(t){case 1:r="EOF",i=1;break;case 2:r="ENOENT",i=34;break;case 3:r="EACCES",i=3;break;case 0:case 4:case 5:r="EFAILURE",i=-2;break;case 6:r="ENOTCONN",i=31;break;case 7:r="ESHUTDOWN",i=46;break;case 8:r="ENOSYS",i=35;break;case 5:r="ESHUTDOWN",i=46;break;default:r="UNKNOWN",i=-1}var o=n.command,s=n.path||n.handle;s="string"==typeof s?"'"+s+"'":s?new String(s):"";var a=new Error(r+", "+o+" "+s);a.errno=i,a.code=r;for(var h in n)"command"!=h&&n.hasOwnProperty(h)&&(a[h]=n[h]);return a.nativeCode=t,a.description=e,a},t.prototype.checkResponse=function(t,e,n){if(101==t.type){var r=this.readStatus(t);if(null!=r)return n(r),!1}if(t.type!=e)throw new Error("Unexpected packet received");return!0},t.prototype.parseStatus=function(t,e){this.checkResponse(t,101,e)&&e(null)},t.prototype.parseAttribs=function(t,e){if(this.checkResponse(t,105,e)){var n=new C(t);delete n.flags,e(null,n)}},t.prototype.parseHandle=function(t,e){if(this.checkResponse(t,102,e)){var n=t.readData(!0);e(null,new A(n,this))}},t.prototype.parsePath=function(t,e){if(this.checkResponse(t,104,e)){if(1!=t.readInt32())throw new Error("Invalid response");e(null,t.readString())}},t.prototype.parseData=function(t,e,n,r,i,o,s,a){var h=this;if(101==t.type&&null!=(c=this.readStatus(t)))return void(1==c.nativeCode?e(null,0,i):e(c,0,null));var u=t.readData(!1);if(u.length>s)throw new Error("Received too much data");if(0==(s=u.length)){var c;if(n>4)return(c=this.createError(4,"Unable to read data",t.info)).code="EIO",c.errno=55,void e(c,0,null);var f=this.getRequest(5);return f.writeData(r),f.writeInt64(a),f.writeInt32(s),void this.execute(f,e,function(t,u){return h.parseData(t,e,n+1,r,i,o,s,a)},t.info)}i.set(u,o),e(null,s,i)},t.prototype.parseItems=function(t,e){if(101==t.type){var n=this.readStatus(t);if(null!=n)return void(1==n.nativeCode?e(null,!1):e(n,null))}if(104!=t.type)throw new Error("Unexpected packet received");for(var r=t.readInt32(),i=[],o=0;o<r;o++)i[o]=this.readItem(t);e(null,i)},t}(),D=function(t){function n(){t.call(this,null)}return e(n,t),n.prototype.on=function(e,n){return t.prototype.on.call(this,e,n)},n.prototype.once=function(e,n){return t.prototype.on.call(this,e,n)},n.prototype.connect=function(e,n,r){void 0===(n=n||{}).protocol&&(n.protocol="sftp");var i=[];"object"!=typeof n||void 0===n.protocol?i.push("sftp"):i.push(n.protocol);var o=new WebSocket(e,i);o.binaryType="arraybuffer";var s=new x(o);t.prototype.bind.call(this,s,r)},n}(function(t){function n(e){var n=new O;t.call(this,n,e)}return e(n,t),n.prototype.bind=function(t,e){var n=this,r=this._fs;if(this._bound)throw new Error("Already bound");this._bound=!0;var i=!1,o=this;function s(t){if("function"==typeof e)try{e(t),t=null}catch(e){t=e}t&&o.emit("error",t)}t.on("ready",function(){i=!0,r._init(t,function(t){if(t)return r._end(),n._bound=!1,s(t);s(null),n.emit("ready")})}),t.on("message",function(t){try{r._process(t)}catch(t){n.emit("error",t),r.end()}}),t.on("error",function(t){n.emit("error",t),r.end()}),t.on("close",function(t){i?(r._end(),n._bound=!1,n.emit("close",t)):s(t=t||new Error("Unable to connect"))})},n.prototype.end=function(){this._fs.end()},n}(E));t.Client=D}(SFTP||(SFTP={}));