(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.WebTorrent=e()}})(function(){var e,t,n;return function r(e,t,n){function i(o,s){if(!t[o]){if(!e[o]){var f=typeof require=="function"&&require;if(!s&&f)return f(o,!0);if(a)return a(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var u=t[o]={exports:{}};e[o][0].call(u.exports,function(t){var n=e[o][1][t];return i(n?n:t)},u,u.exports,r,e,t,n)}return t[o].exports}var a=typeof require=="function"&&require;for(var o=0;o0){return n[Math.random()*n.length|0]}else{return-1}}},{}],6:[function(e,t,n){var r=e("debug")("webtorrent:server");var i=e("http");var a=e("mime");var o=e("pump");var s=e("range-parser");var f=e("url");t.exports=function c(e,t){var n=i.createServer(t);n.on("connection",function(e){e.setTimeout(36e6)});n.on("request",function(t,n){r("onRequest");if(t.method==="OPTIONS"&&t.headers["access-control-request-headers"]){n.setHeader("Access-Control-Allow-Methods","POST, GET, OPTIONS");n.setHeader("Access-Control-Allow-Headers",t.headers["access-control-request-headers"]);n.setHeader("Access-Control-Max-Age","1728000");return n.end()}if(t.headers.origin){n.setHeader("Access-Control-Allow-Origin",t.headers.origin)}var i=f.parse(t.url).pathname;if(i==="/favicon.ico")return n.end();if(e.ready)c();else e.once("ready",c);function c(){if(i==="/"){n.setHeader("Content-Type","text/html");var f=e.files.map(function(e,t){return'
  • '+e.name+"
  • "}).join("
    ");return n.end("

    WebTorrent

      "+f+"
    ")}var c=Number(i.slice(1));if(Number.isNaN(c)||c>=e.files.length){n.statusCode=404;return n.end()}var u=e.files[c];n.setHeader("Accept-Ranges","bytes");n.setHeader("Content-Type",a.lookup(u.name));n.statusCode=200;n.setHeader("transferMode.dlna.org","Streaming");n.setHeader("contentFeatures.dlna.org","DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000");var l;if(t.headers.range){n.statusCode=206;l=s(u.length,t.headers.range)[0];r("range %s",JSON.stringify(l));n.setHeader("Content-Range","bytes "+l.start+"-"+l.end+"/"+u.length);n.setHeader("Content-Length",l.end-l.start+1)}else{n.setHeader("Content-Length",u.length)}if(t.method==="HEAD")n.end();o(u.createReadStream(l),n)}});return n}},{debug:117,http:52,mime:126,pump:149,"range-parser":150,url:76}],7:[function(e,t,n){(function(n,r){t.exports=E;var i=e("bitfield");var a=e("block-stream2");var o=e("debug")("webtorrent:storage");var s=e("dezalgo");var f=e("end-of-stream");var c=e("events").EventEmitter;var u=e("./file-stream");var l=e("inherits");var p=e("./mime.json");var d=e("multistream");var h=e("once");var m=e("path");var v=e("simple-sha1");var g=16*1024;var y=0;var b=1;var w=2;function _(){}l(x,c);function x(e,t,n,r){var i=this;c.call(i);if(!o.enabled)i.setMaxListeners(0);i.index=e;i.hash=t;i.noVerify=!!r;if(typeof n==="number"){i.buffer=null;i.length=n}else{i.buffer=n;i.length=n.length}i._reset()}x.prototype.readBlock=function(e,t,n){var r=this;n=s(n);if(!r.buffer||!r._verifyOffset(e)){return n(new Error("invalid block offset "+e))}n(null,r.buffer.slice(e,e+t))};x.prototype.writeBlock=function(e,t,n){var r=this;n=s(n);if(!r._verifyOffset(e)||!r._verifyBlock(e,t)){return n(new Error("invalid block "+e+":"+t.length))}r._lazyAllocBuffer();var i=e/g;if(r.blocks[i]===w){return n(null)}t.copy(r.buffer,e);r.blocks[i]=w;r.blocksWritten+=1;if(r.blocksWritten===r.blocks.length){r.verify()}n(null)};x.prototype.reserveBlock=function(e){var t=this;var n=t.blocks.length;for(var r=0;r0){var t=e.pieces[0].index;var n=e.pieces[e.pieces.length-1].index;e.storage.emit("select",t,n,false)}};k.prototype.deselect=function(){var e=this;if(e.pieces.length>0){var t=e.pieces[0].index;var n=e.pieces[e.pieces.length-1].index;e.storage.emit("deselect",t,n,false)}};k.prototype.createReadStream=function(e){var t=this;if(!e)e={};if(e.pieceLength==null)e.pieceLength=t.pieceLength;var n=new u(t,e);t.storage.emit("select",n.startPiece,n.endPiece,true,n.notify.bind(n));f(n,function(){t.storage.emit("deselect",n.startPiece,n.endPiece,true)});return n};k.prototype.getBlobURL=function(e){var t=this;if(typeof window==="undefined")throw new Error("browser-only method");t.getBuffer(function(n,r){if(n)return e(n);var i=p[m.extname(t.name).toLowerCase()];var a=i?new window.Blob([r],{type:i}):new window.Blob([r]);var o=window.URL.createObjectURL(a);e(null,o)})};k.prototype.getBuffer=function(e){var t=this;e=s(h(e));var n;if(t.storage.buffer){var i=function(){n=t.storage.buffer.slice(t.offset,t.offset+t.length);e(null,n)};if(t.done)i();else t.once("done",i)}else{n=new r(t.length);var a=0;t.createReadStream().on("data",function(e){e.copy(n,a);a+=e.length}).on("end",function(){e(null,n)}).on("error",e)}};k.prototype._checkDone=function(){var e=this;e.done=e.pieces.every(function(e){return e.verified});if(e.done){n.nextTick(function(){e.emit("done")})}};l(E,c);function E(e,t){var n=this;c.call(n);if(!o.enabled)n.setMaxListeners(0);if(!t)t={};n.bitfield=new i(e.pieces.length);n.done=false;n.closed=false;n.readonly=true;if(!t.nobuffer){n.buffer=new r(e.length)}var a=n.pieceLength=e.pieceLength;var s=e.lastPieceLength;var f=e.pieces.length;n.pieces=e.pieces.map(function(e,r){var i=r*a;var o=i+(r===f-1?s:a);var c=n.buffer?n.buffer.slice(i,o):o-i;var u=new x(r,e,c,!!t.noVerify);u.on("done",n._onPieceDone.bind(n,u));return u});n.files=e.files.map(function(e){var t=e.offset;var r=t+e.length-1;var i=t/a|0;var o=r/a|0;var s=n.pieces.slice(i,o+1);var f=new k(n,e,s,a);f.on("done",n._onFileDone.bind(n,f));return f})}E.BLOCK_LENGTH=g;E.prototype.load=function(e,t){var n=this;if(!Array.isArray(e))e=[e];t=h(t||function(){});var r=0;var i=new d(e);var o=new a(n.pieceLength,{zeroPadding:false});i.on("error",f);n.once("done",c);i.pipe(o).on("data",s).on("error",f);function s(e){var t=r;r+=1;var i=0;var o=new a(g,{zeroPadding:false});o.on("data",s);o.on("end",f);function s(e){var r=i*g;i+=1;n.writeBlock(t,r,e)}function f(){c()}function c(){o.removeListener("data",s);o.removeListener("end",f)}o.end(e)}function f(e){u();t(e)}function c(){u();t(null)}function u(){i.removeListener("error",f);o.removeListener("data",s);o.removeListener("error",f);n.removeListener("done",c)}};Object.defineProperty(E.prototype,"downloaded",{get:function(){var e=this;return e.pieces.reduce(function(e,t){return e+(t.verified?t.length:t.blocksWritten*g)},0)}});Object.defineProperty(E.prototype,"numMissing",{get:function(){var e=this;var t=e.pieces.length;for(var n=0,r=e.pieces.length;nt||e<0||t>=i.storage.pieces.length){throw new Error("invalid selection ",e,":",t)}n=Number(n)||0;o("select %s-%s (priority %s)",e,t,n);i._selections.push({from:e,to:t,offset:0,priority:n,notify:r||C});i._selections.sort(function(e,t){return t.priority-e.priority});i._updateSelections()};I.prototype.deselect=function(e,t,n){var r=this;n=Number(n)||0;o("deselect %s-%s (priority %s)",e,t,n);for(var i=0;i2*(t.swarm.numConns-t.swarm.numPeers)&&e.amInterested){e.destroy()}else{n=setTimeout(i,r);if(n.unref)n.unref()}}var a=0;function s(){if(e.peerPieces.length!==t.storage.pieces.length)return;for(;aw){o("got invalid block size request %s (from %s)",i,e.remoteAddress+":"+e.remotePort);return e.destroy()}t.storage.readBlock(n,r,i,a)});e.bitfield(t.storage.bitfield);e.interested();n=setTimeout(i,r);if(n.unref)n.unref();e.isSeeder=false;s()};I.prototype._onStorage=function(){var e=this;if(e.destroyed)return;o("on storage");e.storage.readonly=false;e.select(0,e.storage.pieces.length-1,false);e._rechokeIntervalId=setInterval(e._rechoke.bind(e),A);if(e._rechokeIntervalId.unref)e._rechokeIntervalId.unref();n.nextTick(function(){e.ready=true;e.emit("ready")})};I.prototype._onStoragePiece=function(e){var t=this;o("piece done %s",e.index);t._reservations[e.index]=null;t.swarm.wires.forEach(function(t){t.have(e.index)});t._gcSelections()};I.prototype._updateSelections=function(){var e=this;if(!e.swarm||e.destroyed)return;if(!e.metadata)return e.once("metadata",e._updateSelections.bind(e));n.nextTick(e._gcSelections.bind(e));e._updateInterest();e._update()};I.prototype._gcSelections=function(){var e=this;for(var t=0;t=n)return;var r=j(e,S);f(false)||f(true);function i(t,n,r,i){return function(a){return a>=t&&a<=n&&!(a in r)&&e.peerPieces.get(a)&&(!i||i(a))}}function a(){if(e.requests.length)return;for(var n=t._selections.length;n--;){var r=t._selections[n];var a;if(t.strategy==="rarest"){var o=r.from+r.offset;var s=r.to;var f=s-o+1;var c={};var u=0;var l=i(o,s,c);while(u=r.from+r.offset;--a){if(!e.peerPieces.get(a))continue;if(t._request(e,a,false))return}}}}function o(){var n=e.downloadSpeed()||1;if(n>k)return function(){return true};var r=Math.max(1,e.requests.length)*b.BLOCK_LENGTH/n;var i=10;var a=0;return function(e){if(!i||t.storage.bitfield.get(e))return true;var o=t.storage.pieces[e];var s=o.blocks.length-o.blocksWritten;for(;a0)continue;i--;return false}return true}}function s(e){var n=e;for(var r=e;r=r)return true;var a=o();for(var f=0;f0)e._rechokeOptimisticTime-=1;else e._rechokeOptimisticWire=null;var t=[];e.swarm.wires.forEach(function(n){if(!n.isSeeder&&n!==e._rechokeOptimisticWire){t.push({wire:n,downloadSpeed:n.downloadSpeed(),uploadSpeed:n.uploadSpeed(),salt:Math.random(),isChoked:true})}});t.sort(o);var n=0;var r=0;for(;r=k)continue;if(2*c>r||c>a)continue;o=f;a=c}if(!o)return false;for(s=0;s=s)return false;var f=e.requests.length===0&&i.storage.numMissing<30;var c=i.storage.reserveBlock(t,f);if(!c&&!f&&r&&i._hotswap(e,t)){c=i.storage.reserveBlock(t,false)}if(!c)return false;var u=i._reservations[t];if(!u){u=i._reservations[t]=[]}var l=u.indexOf(null);if(l===-1)l=u.length;u[l]=e;function p(r,a){if(!i.ready){i.once("ready",function(){p(r,a)});return}if(u[l]===e)u[l]=null;if(r){o("error getting piece %s (offset: %s length: %s) from %s: %s",t,c.offset,c.length,e.remoteAddress+":"+e.remotePort,r.message);i.storage.cancelBlock(t,c.offset);n.nextTick(i._update.bind(i));return false}else{o("got piece %s (offset: %s length: %s) from %s",t,c.offset,c.length,e.remoteAddress+":"+e.remotePort);i.storage.writeBlock(t,c.offset,a,function(e){if(e){o("error writing block");i.storage.cancelBlock(t,c.offset)}n.nextTick(i._update.bind(i))})}}e.request(t,c.offset,c.length,p);return true};I.prototype.createServer=function(e){var t=this;if(typeof y==="function"){return new y(t,e)}};I.prototype._onError=function(e){var t=this;o("torrent error: %s",e.message||e);t.emit("error",e);t.destroy()};function j(e,t){return Math.ceil(2+t*e.downloadSpeed()/b.BLOCK_LENGTH)}function L(e){return Math.random()*e|0}function R(e,t){var n=e.map(function(e,t){return t});for(var r=n.length-1;r>0;--r){var i=L(r+1);var a=n[r];n[r]=n[i];n[i]=a}n.forEach(function(n){t(e[n],n,e)})}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./rarity-map":5,"./server":6,"./storage":7,_process:58,"addr-to-ip-port":9,"bittorrent-swarm":11,"create-torrent":79,debug:117,events:51,inherits:125,"parse-torrent":132,"re-emitter":151,"run-parallel":152,"torrent-discovery":159,uniq:197,ut_metadata:198,ut_pex:46}],9:[function(e,t,n){var r=/^\[?([^\]]+)\]?:(\d+)$/;var i={};var a=0;t.exports=function o(e){if(a===1e5)i={};if(!i[e]){var t=r.exec(e);if(!t)throw new Error("invalid addr: "+e);i[e]=[t[1],Number(t[2])];a+=1}return i[e]};t.exports.reset=function s(){i={}}},{}],10:[function(e,t,n){(function(e){var n=typeof e!=="undefined"?e:typeof Int8Array!=="undefined"?Int8Array:function(e){var t=new Array(e);for(var n=0;n>3;if(e%8!==0)t++;return t}r.prototype.get=function(e){var t=e>>3;return t>e%8)};r.prototype.set=function(e,t){var n=e>>3;if(t||arguments.length===1){if(this.buffer.length>e%8}else if(n>e%8)}};r.prototype._grow=function(e){if(this.buffer.length=e.maxConns){return}a("drain (%s queued, %s/%s peers)",e.numQueued,e.numPeers,e.maxConns);var t=e._queue.shift();if(!t)return;a("tcp connect attempt to %s",t.addr);var n=i(t.addr);var r=n[0];var o=n[1];var s=t.conn=c.connect({host:r,port:o,localAddress:e._hostname});s.once("connect",function(){t.onConnect()});s.once("error",function(e){t.destroy(e)});t.setConnectTimeout();s.on("close",function(){if(e.destroyed)return;if(t.retries>=h.length){a("conn %s closed: will not re-add (max %s attempts)",t.addr,h.length);return}function n(){var n=u.createOutgoingTCPPeer(t.addr,e);n.retries=t.retries+1;e._queue.push(n);e._drain()}var r=h[t.retries];a("conn %s closed: will re-add to queue in %sms (attempt %s)",t.addr,r,t.retries+1);var i=setTimeout(n,r);if(i.unref)i.unref()})};m.prototype._onError=function(e){var t=this;t.emit("error",e);t.destroy()};m.prototype._validAddr=function(e){var t=this;var n=i(e);var r=n[0];var a=n[1];return a>0&&a<65535&&!(r==="127.0.0.1"&&a===t._port)}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/peer":12,"./lib/tcp-pool":13,_process:58,"addr-to-ip-port":46,buffer:47,debug:26,dezalgo:29,events:51,inherits:32,net:46,speedometer:33}],12:[function(e,t,n){var r=e("debug")("bittorrent-swarm:peer");var i=e("bittorrent-protocol");var a=25e3;var o=25e3;n.createWebRTCPeer=function(e,t){var n=new s(e.id);n.conn=e;n.swarm=t;if(n.conn.connected){n.onConnect()}else{n.conn.once("connect",function(){n.onConnect()});n.conn.once("error",function(e){n.destroy(e)});n.setConnectTimeout()}return n};n.createIncomingTCPPeer=function(e){var t=e.remoteAddress+":"+e.remotePort;var n=new s(t);n.conn=e;n.addr=t;n.onConnect();return n};n.createOutgoingTCPPeer=function(e,t){var n=new s(e);n.swarm=t;n.addr=e;return n};function s(e){var t=this;t.id=e;r("new Peer %s",e);t.addr=null;t.conn=null;t.swarm=null;t.wire=null;t.destroyed=false;t.timeout=null;t.retries=0;t.sentHandshake=false}s.prototype.onConnect=function(){var e=this;r("Peer %s connected",e.id);clearTimeout(e.connectTimeout);var t=e.conn;t.once("end",function(){e.destroy()});t.once("close",function(){e.destroy()});t.once("finish",function(){e.destroy()});t.once("error",function(t){e.destroy(t)});var n=e.wire=new i;n.once("end",function(){e.destroy()});n.once("finish",function(){e.destroy()});n.once("error",function(t){e.destroy(t)});n.once("handshake",function(t,n){e.onHandshake(t,n)});e.setHandshakeTimeout();t.pipe(n).pipe(t);if(e.swarm)e.handshake()};s.prototype.onHandshake=function(e,t){var n=this;if(!n.swarm)return;var i=e.toString("hex");var a=t.toString("hex");if(n.swarm.destroyed)return n.destroy(new Error("swarm already destroyed"));if(i!==n.swarm.infoHashHex){return n.destroy(new Error("unexpected handshake info hash for this swarm"))}if(a===n.swarm.peerIdHex){return n.destroy(new Error("refusing to handshake with self"))}r("Peer %s got handshake %s",n.id,i);clearTimeout(n.handshakeTimeout);n.retries=0;n.wire.on("download",function(e){n.swarm.downloaded+=e;n.swarm.downloadSpeed(e);n.swarm.emit("download",e)});n.wire.on("upload",function(e){n.swarm.uploaded+=e;n.swarm.uploadSpeed(e);n.swarm.emit("upload",e)});if(!n.sentHandshake)n.handshake();n.swarm.wires.push(n.wire);var o=n.addr;if(!o&&n.conn.remoteAddress){o=n.conn.remoteAddress+":"+n.conn.remotePort}n.swarm.emit("wire",n.wire,o)};s.prototype.handshake=function(){var e=this;e.wire.handshake(e.swarm.infoHash,e.swarm.peerId,e.swarm.handshakeOpts);e.sentHandshake=true};s.prototype.setConnectTimeout=function(){var e=this;clearTimeout(e.connectTimeout);e.connectTimeout=setTimeout(function(){e.destroy(new Error("connect timeout"))},a);if(e.connectTimeout.unref)e.connectTimeout.unref()};s.prototype.setHandshakeTimeout=function(){var e=this;clearTimeout(e.handshakeTimeout);e.handshakeTimeout=setTimeout(function(){e.destroy(new Error("handshake timeout"))},o);if(e.handshakeTimeout.unref)e.handshakeTimeout.unref()};s.prototype.destroy=function(e){var t=this;if(t.destroyed)return;t.destroyed=true;r("destroy Peer %s (error: %s)",t.id,e&&(e.message||e));if(t.swarm)t.swarm.wires.splice(t.swarm.wires.indexOf(t.wire),1);if(t.conn)t.conn.destroy();if(t.wire)t.wire.destroy();if(t.swarm){t.swarm.removePeer(t.id);t.swarm._drain()}clearTimeout(t.connectTimeout);clearTimeout(t.handshakeTimeout);t.conn=null;t.swarm=null;t.wire=null}},{"bittorrent-protocol":14,debug:26}],13:[function(e,t,n){(function(n){t.exports=f;var r=e("debug")("bittorrent-swarm:tcp-pool");var i=e("dezalgo");var a=e("net");var o=e("./peer");var s={};function f(e,t){var n=this;n.port=e;n.listening=false;n.swarms={};r("new TCPPool (port: %s, hostname: %s)",e,t);n.pendingConns=[];n.server=a.createServer();n.server.on("connection",function(e){n._onConnection(e)});n.server.on("error",function(e){n._onError(e)});n.server.on("listening",function(){n._onListening()});n.server.listen(n.port,t)}f.addSwarm=function(e){var t=s[e._port];if(!t)t=s[e._port]=new f(e._port,e._hostname);t.addSwarm(e);return t};f.removeSwarm=function(e,t){var r=s[e._port];if(!r)return t();r.removeSwarm(e);var i=0;for(var a in r.swarms){var o=r.swarms[a];if(o)i+=1}if(i===0)r.destroy(t);else n.nextTick(t)};f.getDefaultListenPort=function(e){for(var t in s){var n=s[t];if(n&&!n.swarms[e])return n.port}return 0};f.prototype.addSwarm=function(e){var t=this;if(t.swarms[e.infoHashHex]){n.nextTick(function(){e._onError(new Error("There is already a swarm with info hash "+e.infoHashHex+" "+"listening on port "+e._port))});return}t.swarms[e.infoHashHex]=e;if(t.listening){n.nextTick(function(){e._onListening(t.port)})}r("add swarm %s to tcp pool %s",e.infoHashHex,t.port)};f.prototype.removeSwarm=function(e){var t=this;r("remove swarm %s from tcp pool %s",e.infoHashHex,t.port);t.swarms[e.infoHashHex]=null};f.prototype.destroy=function(e){var t=this;if(e)e=i(e);r("destroy tcp pool %s",t.port);t.listening=false;t.pendingConns.forEach(function(e){e.destroy()});s[t.port]=null;try{t.server.close(e)}catch(n){if(e)e(null)}};f.prototype._onListening=function(){var e=this;var t=e.server.address().port;r("tcp pool listening on %s",t);if(t!==e.port){s[e.port]=null;e.port=t;s[e.port]=e}e.listening=true;for(var n in e.swarms){var i=e.swarms[n];if(i)i._onListening(e.port)}};f.prototype._onConnection=function(e){var t=this;t.pendingConns.push(e);e.once("close",n);function n(){t.pendingConns.splice(t.pendingConns.indexOf(e))}var r=o.createIncomingTCPPeer(e);r.wire.once("handshake",function(i,a){var o=i.toString("hex");n();e.removeListener("close",n);var s=t.swarms[o];if(s){r.swarm=s;s._addIncomingPeer(r);r.onHandshake(i,a)}else{var f=new Error("Unexpected info hash "+o+" from incoming peer "+r.id+": destroying peer");r.destroy(f)}})};f.prototype._onError=function(e){var t=this;t.destroy();for(var n in t.swarms){var r=t.swarms[n];if(r){t.removeSwarm(r);r._onError(e)}}}}).call(this,e("_process"))},{"./peer":12,_process:58,debug:26,dezalgo:29,net:46}],14:[function(e,t,n){(function(n){t.exports=w;var r=e("bitfield");var i=e("bencode");var a=e("debug")("bittorrent-protocol");var o=e("xtend");var s=e("inherits");var f=e("speedometer");var c=e("stream");var u=4e5;var l=new n("BitTorrent protocol");var p=new n([0,0,0,0]);var d=new n([0,0,0,1,0]);var h=new n([0,0,0,1,1]);var m=new n([0,0,0,1,2]);var v=new n([0,0,0,1,3]);var g=[0,0,0,0,0,0,0,0];var y=[0,0,0,3,9,0,0];function b(e,t,n,r){this.piece=e;this.offset=t;this.length=n;this.callback=r}s(w,c.Duplex);function w(){if(!(this instanceof w))return new w;c.Duplex.call(this);a("new wire");this.amChoking=true;this.amInterested=false;this.peerChoking=true;this.peerInterested=false;this.peerPieces=new r(0,{grow:u});this.peerExtensions={};this.requests=[];this.peerRequests=[];this.extendedMapping={};this.peerExtendedMapping={};this.extendedHandshake={};this.peerExtendedHandshake={};this._ext={};this._nextExt=1;this.uploaded=0;this.downloaded=0;this.uploadSpeed=f();this.downloadSpeed=f();this._keepAlive=null;this._timeout=null;this._timeoutMs=0;this.destroyed=false;this._finished=false;this._buffer=[];this._bufferSize=0;this._parser=null;this._parserSize=0;this.on("finish",this._onfinish);this._parseHandshake()}w.prototype.setKeepAlive=function(e){clearInterval(this._keepAlive);if(e===false)return;this._keepAlive=setInterval(this._push.bind(this,p),6e4)};w.prototype.setTimeout=function(e,t){this._clearTimeout();this._timeoutMs=e;this._timeoutUnref=!!t;this._updateTimeout()};w.prototype.destroy=function(){if(this.destroyed)return;this.destroyed=true;a("destroy");this.end()};w.prototype.end=function(){this._onUninterested();this._onChoke();c.Duplex.prototype.end.apply(this,arguments)};w.prototype.use=function(e){var t=e.prototype.name;if(!t){throw new Error("Extension API requires a named function, e.g. function name() {}")}var n=this._nextExt;var r=new e(this);function i(){}if(typeof r.onHandshake!=="function"){r.onHandshake=i}if(typeof r.onExtendedHandshake!=="function"){r.onExtendedHandshake=i}if(typeof r.onMessage!=="function"){r.onMessage=i}this.extendedMapping[n]=t;this._ext[t]=r;this[t]=r;this._nextExt+=1};w.prototype.handshake=function(e,t,r){if(typeof e==="string")e=new n(e,"hex");if(typeof t==="string")t=new n(t,"hex");if(e.length!==20||t.length!==20){throw new Error("infoHash and peerId MUST have length 20")}var i=new n(g);i[5]|=16;if(r&&r.dht)i[7]|=1;this._push(n.concat([l,i,e,t]));this._handshakeSent=true;if(this.peerExtensions.extended){this._sendExtendedHandshake()}};w.prototype._sendExtendedHandshake=function(){var e=o(this.extendedHandshake);e.m={};for(var t in this.extendedMapping){var n=this.extendedMapping[t];e.m[n]=Number(t)}this.extended(0,i.encode(e))};w.prototype.choke=function(){if(this.amChoking)return;this.amChoking=true;this.peerRequests.splice(0,this.peerRequests.length);this._push(d)};w.prototype.unchoke=function(){if(!this.amChoking)return;this.amChoking=false;this._push(h)};w.prototype.interested=function(){if(this.amInterested)return;this.amInterested=true;this._push(m)};w.prototype.uninterested=function(){if(!this.amInterested)return;this.amInterested=false;this._push(v)};w.prototype.have=function(e){this._message(4,[e],null)};w.prototype.bitfield=function(e){if(!n.isBuffer(e))e=e.buffer;this._message(5,[],e)};w.prototype.request=function(e,t,n,r){if(!r)r=function(){};if(this._finished)return r(new Error("wire is closed"));if(this.peerChoking)return r(new Error("peer is choking"));this.requests.push(new b(e,t,n,r));this._updateTimeout();this._message(6,[e,t,n],null)};w.prototype.piece=function(e,t,n){this.uploaded+=n.length;this.uploadSpeed(n.length);this.emit("upload",n.length);this._message(7,[e,t],n)};w.prototype.cancel=function(e,t,n){this._callback(_(this.requests,e,t,n),new Error("request was cancelled"),null);this._message(8,[e,t,n],null)};w.prototype.port=function(e){var t=new n(y);t.writeUInt16BE(e,5);this._push(t)};w.prototype.extended=function(e,t){if(typeof e==="string"&&this.peerExtendedMapping[e]){e=this.peerExtendedMapping[e]}if(typeof e==="number"){var r=new n([e]);var a=n.isBuffer(t)?t:i.encode(t);this._message(20,[],n.concat([r,a]))}else{throw new Error("Unrecognized extension: "+e)}};w.prototype._onKeepAlive=function(){this.emit("keep-alive")};w.prototype._onHandshake=function(e,t,n){this.peerId=t;this.peerExtensions=n;this.emit("handshake",e,t,n);var r;for(r in this._ext){this._ext[r].onHandshake(e,t,n)}if(n.extended&&this._handshakeSent){this._sendExtendedHandshake()}};w.prototype._onChoke=function(){this.peerChoking=true;this.emit("choke");while(this.requests.length){this._callback(this.requests.shift(),new Error("peer is choking"),null)}};w.prototype._onUnchoke=function(){this.peerChoking=false;this.emit("unchoke")};w.prototype._onInterested=function(){this.peerInterested=true;this.emit("interested")};w.prototype._onUninterested=function(){this.peerInterested=false;this.emit("uninterested")};w.prototype._onHave=function(e){if(this.peerPieces.get(e))return;this.peerPieces.set(e,true);this.emit("have",e)};w.prototype._onBitField=function(e){this.peerPieces=new r(e);this.emit("bitfield",this.peerPieces)};w.prototype._onRequest=function(e,t,n){if(this.amChoking)return;var r=function(r,a){if(i!==_(this.peerRequests,e,t,n))return;if(r)return;this.piece(e,t,a)}.bind(this);var i=new b(e,t,n,r);this.peerRequests.push(i);this.emit("request",e,t,n,r)};w.prototype._onPiece=function(e,t,n){this._callback(_(this.requests,e,t,n.length),null,n);this.downloaded+=n.length;this.downloadSpeed(n.length);this.emit("download",n.length);this.emit("piece",e,t,n)};w.prototype._onCancel=function(e,t,n){_(this.peerRequests,e,t,n);this.emit("cancel",e,t,n)};w.prototype._onPort=function(e){this.emit("port",e)};w.prototype._onExtended=function(e,t){var n,r;if(e===0&&(n=x(t))){this.peerExtendedHandshake=n;if(typeof n.m==="object"){for(r in n.m){this.peerExtendedMapping[r]=Number(n.m[r].toString())}}for(r in this._ext){if(this.peerExtendedMapping[r]){this._ext[r].onExtendedHandshake(this.peerExtendedHandshake)}}this.emit("extended","handshake",this.peerExtendedHandshake)}else{if(this.extendedMapping[e]){e=this.extendedMapping[e];if(this._ext[e]){this._ext[e].onMessage(t)}}this.emit("extended",e,t)}};w.prototype._onTimeout=function(){this._callback(this.requests.shift(),new Error("request has timed out"),null);this.emit("timeout")};w.prototype._push=function(e){if(this._finished)return;return this.push(e)};w.prototype._write=function(e,t,r){this._bufferSize+=e.length;this._buffer.push(e);while(this._bufferSize>=this._parserSize){var i=this._buffer.length===1?this._buffer[0]:n.concat(this._buffer);this._bufferSize-=this._parserSize;this._buffer=this._bufferSize?[i.slice(this._parserSize)]:[];this._parser(i.slice(0,this._parserSize))}r(null)};w.prototype._read=function(){};w.prototype._callback=function(e,t,n){if(!e)return;this._clearTimeout();if(!this.peerChoking&&!this._finished)this._updateTimeout();e.callback(t,n)};w.prototype._clearTimeout=function(){if(!this._timeout)return;clearTimeout(this._timeout);this._timeout=null};w.prototype._updateTimeout=function(){if(!this._timeoutMs||!this.requests.length||this._timeout)return;this._timeout=setTimeout(this._onTimeout.bind(this),this._timeoutMs);if(this._timeoutUnref&&this._timeout.unref)this._timeout.unref()};w.prototype._parse=function(e,t){this._parserSize=e;this._parser=t};w.prototype._message=function(e,t,r){var i=r?r.length:0;var a=new n(5+4*t.length);a.writeUInt32BE(a.length+i-4,0);a[4]=e;for(var o=0;o0){this._parse(t,this._onmessage)}else{this._onKeepAlive();this._parse(4,this._onmessagelength)}};w.prototype._onmessage=function(e){this._parse(4,this._onmessagelength);switch(e[0]){case 0:return this._onChoke();case 1:return this._onUnchoke();case 2:return this._onInterested();case 3:return this._onUninterested();case 4:return this._onHave(e.readUInt32BE(1));case 5:return this._onBitField(e.slice(1));case 6:return this._onRequest(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 7:return this._onPiece(e.readUInt32BE(1),e.readUInt32BE(5),e.slice(9));case 8:return this._onCancel(e.readUInt32BE(1),e.readUInt32BE(5),e.readUInt32BE(9));case 9:return this._onPort(e.readUInt16BE(1));case 20:return this._onExtended(e.readUInt8(1),e.slice(2));default:return this.emit("unknownmessage",e)}};w.prototype._parseHandshake=function(){this._parse(1,function(e){var t=e.readUInt8(0);this._parse(t+48,function(e){var n=e.slice(0,t);if(n.toString()!=="BitTorrent protocol"){a("Error: wire not speaking BitTorrent protocol (%s)",n.toString());this.end();return}e=e.slice(t);this._onHandshake(e.slice(8,28),e.slice(28,48),{dht:!!(e[7]&1),extended:!!(e[5]&16)});this._parse(4,this._onmessagelength)}.bind(this))}.bind(this))};w.prototype._onfinish=function(){this._finished=true;this.push(null);while(this.read()){}clearInterval(this._keepAlive);this._parse(Number.MAX_VALUE,function(){});this.peerRequests=[];while(this.requests.length){this._callback(this.requests.shift(),new Error("wire was closed"),null)}};function _(e,t,n,r){for(var i=0;i=31}n.formatters.j=function(e){return JSON.stringify(e)};function a(){var e=arguments;var t=this.useColors;e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff);if(!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var i=0;var a=0;e[0].replace(/%[a-z%]/g,function(e){if("%%"===e)return;i++;if("%c"===e){a=i}});e.splice(a,0,r);return e}function o(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{if(null==e){r.removeItem("debug")}else{r.debug=e}}catch(t){}}function f(){var e;try{e=r.debug}catch(t){}return e}n.enable(f());function c(){try{return window.localStorage}catch(e){}}},{"./debug":21}],21:[function(e,t,n){n=t.exports=o;n.coerce=u;n.disable=f;n.enable=s;n.enabled=c;n.humanize=e("ms");n.names=[];n.skips=[];n.formatters={};var r=0;var i;function a(){return n.colors[r++%n.colors.length]}function o(e){function t(){}t.enabled=false;function r(){var e=r;var t=+new Date;var o=t-(i||t);e.diff=o;e.prev=i;e.curr=t;i=t;if(null==e.useColors)e.useColors=n.useColors();if(null==e.color&&e.useColors)e.color=a();var s=Array.prototype.slice.call(arguments);s[0]=n.coerce(s[0]);if("string"!==typeof s[0]){s=["%o"].concat(s)}var f=0;s[0]=s[0].replace(/%([a-z%])/g,function(t,r){if(t==="%%")return t;f++;var i=n.formatters[r];if("function"===typeof i){var a=s[f];t=i.call(e,a);s.splice(f,1);f--}return t});if("function"===typeof n.formatArgs){s=n.formatArgs.apply(e,s)}var c=r.log||n.log||console.log.bind(console);c.apply(e,s)}r.enabled=true;var o=n.enabled(e)?r:t;o.namespace=e;return o}function s(e){n.save(e);var t=(e||"").split(/[\s,]+/);var r=t.length;for(var i=0;i=o)return Math.round(e/o)+"d";if(e>=a)return Math.round(e/a)+"h";if(e>=i)return Math.round(e/i)+"m";if(e>=r)return Math.round(e/r)+"s";return e+"ms"}function u(e){return l(e,o,"day")||l(e,a,"hour")||l(e,i,"minute")||l(e,r,"second")||e+" ms"}function l(e,t,n){if(et)f=t;s=r;while(f--){if(o===t)o=0;n[o]=n[o===0?t-1:o-1];o++}if(e)n[o-1]+=e;var c=n[o-1];var u=n.length=this.size){var i=n.concat(this._buffered);this._bufferedBytes-=this.size;this.push(i.slice(0,this.size));this._buffered=[i.slice(this.size,i.length)]}r()};o.prototype._flush=function(){if(this._bufferedBytes&&this._zeroPadding){var e=new n(this.size-this._bufferedBytes);e.fill(0);this._buffered.push(e);this.push(n.concat(this._buffered));this._buffered=null}else if(this._bufferedBytes){this.push(n.concat(this._buffered));this._buffered=null}this.push(null)}}).call(this,e("buffer").Buffer)},{buffer:47,defined:35,inherits:125,"readable-stream":44}],35:[function(e,t,n){t.exports=function(){for(var e=0;e0){if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var o=new Error("stream.unshift() after end event");e.emit("error",o)}else{if(t.decoder&&!i&&!r)n=t.decoder.write(n);t.length+=t.objectMode?1:n.length;if(i){t.buffer.unshift(n)}else{t.reading=false;t.buffer.push(n)}if(t.needReadable)y(e);w(e,t)}}else if(!i){t.reading=false}return p(t)}function p(e){return!e.ended&&(e.needReadable||e.length=d){e=d}else{e--;for(var t=1;t<32;t<<=1)e|=e>>t;e++}return e}function m(e,t){if(t.length===0&&t.ended)return 0;if(t.objectMode)return e===0?0:1;if(e===null||isNaN(e)){if(t.flowing&&t.buffer.length)return t.buffer[0].length;else return t.length}if(e<=0)return 0;if(e>t.highWaterMark)t.highWaterMark=h(e);if(e>t.length){if(!t.ended){t.needReadable=true;return 0}else return t.length}return e}u.prototype.read=function(e){var t=this._readableState;t.calledRead=true;var n=e;var r;if(typeof e!=="number"||e>0)t.emittedReadable=false;if(e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended)){y(this);return null}e=m(e,t);if(e===0&&t.ended){r=null;if(t.length>0&&t.decoder){r=A(e,t);t.length-=r.length}if(t.length===0)T(this);return r}var i=t.needReadable;if(t.length-e<=t.highWaterMark)i=true;if(t.ended||t.reading)i=false;if(i){t.reading=true;t.sync=true;if(t.length===0)t.needReadable=true;this._read(t.highWaterMark);t.sync=false}if(i&&!t.reading)e=m(n,t);if(e>0)r=A(e,t);else r=null;if(r===null){t.needReadable=true;e=0}t.length-=e;if(t.length===0&&!t.ended)t.needReadable=true;if(t.ended&&!t.endEmitted&&t.length===0)T(this);return r};function v(e,t){var n=null;if(!i.isBuffer(t)&&"string"!==typeof t&&t!==null&&t!==undefined&&!e.objectMode){n=new TypeError("Invalid non-string/buffer chunk")}return n}function g(e,t){if(t.decoder&&!t.ended){var n=t.decoder.end();if(n&&n.length){t.buffer.push(n);t.length+=t.objectMode?1:n.length}}t.ended=true;if(t.length>0)y(e);else T(e)}function y(e){var t=e._readableState;t.needReadable=false;if(t.emittedReadable)return;t.emittedReadable=true;if(t.sync)n.nextTick(function(){b(e)});else b(e)}function b(e){e.emit("readable")}function w(e,t){if(!t.readingMore){t.readingMore=true;n.nextTick(function(){_(e,t)})}}function _(e,t){var n=t.length;while(!t.reading&&!t.flowing&&!t.ended&&t.length0)return}if(t.pipesCount===0){t.flowing=false;if(a.listenerCount(e,"data")>0)S(e);return}t.ranOut=true}function E(){if(this._readableState.ranOut){this._readableState.ranOut=false;k(this)}}u.prototype.unpipe=function(e){var t=this._readableState;if(t.pipesCount===0)return this;if(t.pipesCount===1){if(e&&e!==t.pipes)return this;if(!e)e=t.pipes;t.pipes=null;t.pipesCount=0;this.removeListener("readable",E);t.flowing=false;if(e)e.emit("unpipe",this);return this}if(!e){var n=t.pipes;var r=t.pipesCount;t.pipes=null;t.pipesCount=0;this.removeListener("readable",E);t.flowing=false;for(var i=0;i=r){if(a)s=n.join("");else s=i.concat(n,r);n.length=0}else{if(e0)throw new Error("endReadable called on non-empty stream");if(!t.endEmitted&&t.calledRead){t.ended=true;n.nextTick(function(){if(!t.endEmitted&&t.length===0){t.endEmitted=true;e.readable=false;e.emit("end")}})}}function C(e,t){for(var n=0,r=e.length;n=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;e.copy(this.charBuffer,this.charReceived,0,n);this.charReceived+=n;if(this.charReceived=55296&&r<=56319){this.charLength+=this.surrogateSize;t="";continue}this.charReceived=this.charLength=0;if(e.length===0){return t}break}this.detectIncompleteChar(e);var i=e.length;if(this.charLength){e.copy(this.charBuffer,0,e.length-this.charReceived,i);i-=this.charReceived}t+=e.toString(this.encoding,0,i);var i=t.length-1;var r=t.charCodeAt(i);if(r>=55296&&r<=56319){var a=this.surrogateSize;this.charLength+=a;this.charReceived+=a;this.charBuffer.copy(this.charBuffer,a,0,a);e.copy(this.charBuffer,0,0,a);return t.substring(0,i)}return t};o.prototype.detectIncompleteChar=function(e){var t=e.length>=3?3:e.length;for(;t>0;t--){var n=e[e.length-t];if(t==1&&n>>5==6){this.charLength=2;break}if(t<=2&&n>>4==14){this.charLength=3;break}if(t<=3&&n>>3==30){this.charLength=4;break}}this.charReceived=t};o.prototype.end=function(e){var t="";if(e&&e.length)t=this.write(e);if(this.charReceived){var n=this.charReceived;var r=this.charBuffer;var i=this.encoding;t+=r.slice(0,n).toString(i)}return t};function s(e){return e.toString(this.encoding)}function f(e){this.charReceived=e.length%2;this.charLength=this.charReceived?2:0}function c(e){this.charReceived=e.length%3;this.charLength=this.charReceived?3:0}},{buffer:47}],44:[function(e,t,n){var r=e("stream");n=t.exports=e("./lib/_stream_readable.js");n.Stream=r;n.Readable=n;n.Writable=e("./lib/_stream_writable.js");n.Duplex=e("./lib/_stream_duplex.js");n.Transform=e("./lib/_stream_transform.js");n.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":36,"./lib/_stream_passthrough.js":37,"./lib/_stream_readable.js":38,"./lib/_stream_transform.js":39,"./lib/_stream_writable.js":40,stream:74}],45:[function(e,t,n){},{}],46:[function(e,t,n){arguments[4][45][0].apply(n,arguments)},{dup:45}],47:[function(e,t,n){var r=e("base64-js");var i=e("ieee754");var a=e("is-array");n.Buffer=f;n.SlowBuffer=b;n.INSPECT_MAX_BYTES=50;f.poolSize=8192;var o=1073741823;var s={};f.TYPED_ARRAY_SUPPORT=function(){try{var e=new ArrayBuffer(0);var t=new Uint8Array(e);t.foo=function(){return 42};return t.foo()===42&&typeof t.subarray==="function"&&new Uint8Array(1).subarray(1,1).byteLength===0}catch(n){return false}}();function f(e){if(!(this instanceof f)){if(arguments.length>1)return new f(e,arguments[1]);return new f(e)}this.length=0;this.parent=undefined;if(typeof e==="number"){return c(this,e)}if(typeof e==="string"){return u(this,e,arguments.length>1?arguments[1]:"utf8")}return l(this,e)}function c(e,t){e=g(e,t<0?0:y(t)|0);if(!f.TYPED_ARRAY_SUPPORT){for(var n=0;n>>1;if(n)e.parent=s;return e}function y(e){if(e>=o){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+o.toString(16)+" bytes")}return e|0}function b(e,t){if(!(this instanceof b))return new b(e,t);var n=new f(e,t);delete n.parent;return n}f.isBuffer=function X(e){return!!(e!=null&&e._isBuffer)};f.compare=function Z(e,t){if(!f.isBuffer(e)||!f.isBuffer(t)){throw new TypeError("Arguments must be Buffers")}if(e===t)return 0;var n=e.length;var r=t.length;var i=0;var a=Math.min(n,r);while(i>>1;case"utf8":case"utf-8":return Y(e).length;case"base64":return $(e).length;default:return e.length}}f.byteLength=w;f.prototype.length=undefined;f.prototype.parent=undefined;f.prototype.toString=function te(e,t,n){var r=false;t=t|0;n=n===undefined||n===Infinity?this.length:n|0;if(!e)e="utf8";if(t<0)t=0;if(n>this.length)n=this.length;if(n<=t)return"";while(true){switch(e){case"hex":return L(this,t,n);case"utf8":case"utf-8":return C(this,t,n);case"ascii":return I(this,t,n);case"binary":return j(this,t,n);case"base64":return T(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();r=true}}};f.prototype.equals=function ne(e){if(!f.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(this===e)return true;return f.compare(this,e)===0};f.prototype.inspect=function re(){var e="";var t=n.INSPECT_MAX_BYTES;if(this.length>0){e=this.toString("hex",0,t).match(/.{2}/g).join(" ");if(this.length>t)e+=" ... "}return""};f.prototype.compare=function ie(e){if(!f.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(this===e)return 0;return f.compare(this,e)};f.prototype.indexOf=function ae(e,t){if(t>2147483647)t=2147483647;else if(t<-2147483648)t=-2147483648;t>>=0;if(this.length===0)return-1;if(t>=this.length)return-1;if(t<0)t=Math.max(this.length+t,0);if(typeof e==="string"){if(e.length===0)return-1;return String.prototype.indexOf.call(this,e,t)}if(f.isBuffer(e)){return n(this,e,t)}if(typeof e==="number"){if(f.TYPED_ARRAY_SUPPORT&&Uint8Array.prototype.indexOf==="function"){return Uint8Array.prototype.indexOf.call(this,e,t)}return n(this,[e],t)}function n(e,t,n){var r=-1;for(var i=0;n+ii){r=i}}var a=t.length;if(a%2!==0)throw new Error("Invalid hex string");if(r>a/2){r=a/2}for(var o=0;oa)n=a;if(e.length>0&&(n<0||t<0)||t>this.length){throw new RangeError("attempt to write outside buffer bounds")}if(!r)r="utf8";var o=false;for(;;){switch(r){case"hex":return _(this,e,t,n);case"utf8":case"utf-8":return x(this,e,t,n);case"ascii":return k(this,e,t,n);case"binary":return E(this,e,t,n);case"base64":return S(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase();o=true}}};f.prototype.toJSON=function ce(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function T(e,t,n){if(t===0&&n===e.length){return r.fromByteArray(e)}else{return r.fromByteArray(e.slice(t,n))}}function C(e,t,n){var r="";var i="";n=Math.min(e.length,n);for(var a=t;ar)n=r;var i="";for(var a=t;an){e=n}if(t<0){t+=n;if(t<0)t=0}else if(t>n){t=n}if(tn)throw new RangeError("Trying to access beyond buffer length")}f.prototype.readUIntLE=function le(e,t,n){e=e|0;t=t|0;if(!n)B(e,t,this.length);var r=this[e];var i=1;var a=0;while(++a0&&(i*=256)){r+=this[e+--t]*i}return r};f.prototype.readUInt8=function de(e,t){if(!t)B(e,1,this.length);return this[e]};f.prototype.readUInt16LE=function he(e,t){if(!t)B(e,2,this.length);return this[e]|this[e+1]<<8};f.prototype.readUInt16BE=function me(e,t){ if(!t)B(e,2,this.length);return this[e]<<8|this[e+1]};f.prototype.readUInt32LE=function ve(e,t){if(!t)B(e,4,this.length);return(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};f.prototype.readUInt32BE=function ge(e,t){if(!t)B(e,4,this.length);return this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};f.prototype.readIntLE=function ye(e,t,n){e=e|0;t=t|0;if(!n)B(e,t,this.length);var r=this[e];var i=1;var a=0;while(++a=i)r-=Math.pow(2,8*t);return r};f.prototype.readIntBE=function be(e,t,n){e=e|0;t=t|0;if(!n)B(e,t,this.length);var r=t;var i=1;var a=this[e+--r];while(r>0&&(i*=256)){a+=this[e+--r]*i}i*=128;if(a>=i)a-=Math.pow(2,8*t);return a};f.prototype.readInt8=function we(e,t){if(!t)B(e,1,this.length);if(!(this[e]&128))return this[e];return(255-this[e]+1)*-1};f.prototype.readInt16LE=function _e(e,t){if(!t)B(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};f.prototype.readInt16BE=function xe(e,t){if(!t)B(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};f.prototype.readInt32LE=function ke(e,t){if(!t)B(e,4,this.length);return this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};f.prototype.readInt32BE=function Ee(e,t){if(!t)B(e,4,this.length);return this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};f.prototype.readFloatLE=function Se(e,t){if(!t)B(e,4,this.length);return i.read(this,e,true,23,4)};f.prototype.readFloatBE=function Ae(e,t){if(!t)B(e,4,this.length);return i.read(this,e,false,23,4)};f.prototype.readDoubleLE=function Te(e,t){if(!t)B(e,8,this.length);return i.read(this,e,true,52,8)};f.prototype.readDoubleBE=function Ce(e,t){if(!t)B(e,8,this.length);return i.read(this,e,false,52,8)};function M(e,t,n,r,i,a){if(!f.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||te.length)throw new RangeError("index out of range")}f.prototype.writeUIntLE=function Ie(e,t,n,r){e=+e;t=t|0;n=n|0;if(!r)M(this,e,t,n,Math.pow(2,8*n),0);var i=1;var a=0;this[t]=e&255;while(++a=0&&(a*=256)){this[t+i]=e/a&255}return t+n};f.prototype.writeUInt8=function Le(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,1,255,0);if(!f.TYPED_ARRAY_SUPPORT)e=Math.floor(e);this[t]=e;return t+1};function P(e,t,n,r){if(t<0)t=65535+t+1;for(var i=0,a=Math.min(e.length-n,2);i>>(r?i:1-i)*8}}f.prototype.writeUInt16LE=function Re(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,2,65535,0);if(f.TYPED_ARRAY_SUPPORT){this[t]=e;this[t+1]=e>>>8}else{P(this,e,t,true)}return t+2};f.prototype.writeUInt16BE=function Be(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,2,65535,0);if(f.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e}else{P(this,e,t,false)}return t+2};function O(e,t,n,r){if(t<0)t=4294967295+t+1;for(var i=0,a=Math.min(e.length-n,4);i>>(r?i:3-i)*8&255}}f.prototype.writeUInt32LE=function Me(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,4,4294967295,0);if(f.TYPED_ARRAY_SUPPORT){this[t+3]=e>>>24;this[t+2]=e>>>16;this[t+1]=e>>>8;this[t]=e}else{O(this,e,t,true)}return t+4};f.prototype.writeUInt32BE=function Pe(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,4,4294967295,0);if(f.TYPED_ARRAY_SUPPORT){this[t]=e>>>24;this[t+1]=e>>>16;this[t+2]=e>>>8;this[t+3]=e}else{O(this,e,t,false)}return t+4};f.prototype.writeIntLE=function Oe(e,t,n,r){e=+e;t=t|0;if(!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var a=0;var o=1;var s=e<0?1:0;this[t]=e&255;while(++a>0)-s&255}return t+n};f.prototype.writeIntBE=function Ue(e,t,n,r){e=+e;t=t|0;if(!r){var i=Math.pow(2,8*n-1);M(this,e,t,n,i-1,-i)}var a=n-1;var o=1;var s=e<0?1:0;this[t+a]=e&255;while(--a>=0&&(o*=256)){this[t+a]=(e/o>>0)-s&255}return t+n};f.prototype.writeInt8=function ze(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,1,127,-128);if(!f.TYPED_ARRAY_SUPPORT)e=Math.floor(e);if(e<0)e=255+e+1;this[t]=e;return t+1};f.prototype.writeInt16LE=function He(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,2,32767,-32768);if(f.TYPED_ARRAY_SUPPORT){this[t]=e;this[t+1]=e>>>8}else{P(this,e,t,true)}return t+2};f.prototype.writeInt16BE=function Ne(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,2,32767,-32768);if(f.TYPED_ARRAY_SUPPORT){this[t]=e>>>8;this[t+1]=e}else{P(this,e,t,false)}return t+2};f.prototype.writeInt32LE=function qe(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,4,2147483647,-2147483648);if(f.TYPED_ARRAY_SUPPORT){this[t]=e;this[t+1]=e>>>8;this[t+2]=e>>>16;this[t+3]=e>>>24}else{O(this,e,t,true)}return t+4};f.prototype.writeInt32BE=function De(e,t,n){e=+e;t=t|0;if(!n)M(this,e,t,4,2147483647,-2147483648);if(e<0)e=4294967295+e+1;if(f.TYPED_ARRAY_SUPPORT){this[t]=e>>>24;this[t+1]=e>>>16;this[t+2]=e>>>8;this[t+3]=e}else{O(this,e,t,false)}return t+4};function U(e,t,n,r,i,a){if(t>i||te.length)throw new RangeError("index out of range");if(n<0)throw new RangeError("index out of range")}function z(e,t,n,r,a){if(!a){U(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38)}i.write(e,t,n,r,23,4);return n+4}f.prototype.writeFloatLE=function We(e,t,n){return z(this,e,t,true,n)};f.prototype.writeFloatBE=function Fe(e,t,n){return z(this,e,t,false,n)};function H(e,t,n,r,a){if(!a){U(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308)}i.write(e,t,n,r,52,8);return n+8}f.prototype.writeDoubleLE=function Ye(e,t,n){return H(this,e,t,true,n)};f.prototype.writeDoubleBE=function Je(e,t,n){return H(this,e,t,false,n)};f.prototype.copy=function Ge(e,t,n,r){if(!n)n=0;if(!r&&r!==0)r=this.length;if(t>=e.length)t=e.length;if(!t)t=0;if(r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");if(r>this.length)r=this.length;if(e.length-t=this.length)throw new RangeError("start out of bounds");if(n<0||n>this.length)throw new RangeError("end out of bounds");var r;if(typeof e==="number"){for(r=t;r55295&&n<57344){if(i){if(n<56320){if((t-=3)>-1)a.push(239,191,189);i=n;continue}else{n=i-55296<<10|n-56320|65536;i=null}}else{if(n>56319){if((t-=3)>-1)a.push(239,191,189);continue}else if(o+1===r){if((t-=3)>-1)a.push(239,191,189);continue}else{i=n;continue}}}else if(i){if((t-=3)>-1)a.push(239,191,189);i=null}if(n<128){if((t-=1)<0)break;a.push(n)}else if(n<2048){if((t-=2)<0)break;a.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;a.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<2097152){if((t-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else{throw new Error("Invalid code point")}}return a}function J(e){var t=[];for(var n=0;n>8;i=n%256;a.push(i);a.push(r)}return a}function $(e){return r.toByteArray(D(e))}function V(e,t,n,r){for(var i=0;i=t.length||i>=e.length)break;t[i+n]=e[i]}return i}function K(e){try{return decodeURIComponent(e)}catch(t){return String.fromCharCode(65533)}}},{"base64-js":48,ieee754:49,"is-array":50}],48:[function(e,t,n){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";(function(e){"use strict";var t=typeof Uint8Array!=="undefined"?Uint8Array:Array;var n="+".charCodeAt(0);var i="/".charCodeAt(0);var a="0".charCodeAt(0);var o="a".charCodeAt(0);var s="A".charCodeAt(0);var f="-".charCodeAt(0);var c="_".charCodeAt(0);function u(e){var t=e.charCodeAt(0);if(t===n||t===f)return 62;if(t===i||t===c)return 63;if(t0){throw new Error("Invalid string. Length must be a multiple of 4")}var f=e.length;o="="===e.charAt(f-2)?2:"="===e.charAt(f-1)?1:0;s=new t(e.length*3/4-o);i=o>0?e.length-4:e.length;var c=0;function l(e){s[c++]=e}for(n=0,r=0;n>16);l((a&65280)>>8);l(a&255)}if(o===2){a=u(e.charAt(n))<<2|u(e.charAt(n+1))>>4;l(a&255)}else if(o===1){a=u(e.charAt(n))<<10|u(e.charAt(n+1))<<4|u(e.charAt(n+2))>>2;l(a>>8&255);l(a&255)}return s}function p(e){var t,n=e.length%3,i="",a,o;function s(e){return r.charAt(e)}function f(e){return s(e>>18&63)+s(e>>12&63)+s(e>>6&63)+s(e&63)}for(t=0,o=e.length-n;t>2);i+=s(a<<4&63);i+="==";break;case 2:a=(e[e.length-2]<<8)+e[e.length-1];i+=s(a>>10);i+=s(a>>4&63);i+=s(a<<2&63);i+="=";break}return i}e.toByteArray=l;e.fromByteArray=p})(typeof n==="undefined"?this.base64js={}:n)},{}],49:[function(e,t,n){n.read=function(e,t,n,r,i){var a,o,s=i*8-r-1,f=(1<>1,u=-7,l=n?i-1:0,p=n?-1:1,d=e[t+l];l+=p;a=d&(1<<-u)-1;d>>=-u;u+=s;for(;u>0;a=a*256+e[t+l],l+=p,u-=8){}o=a&(1<<-u)-1;a>>=-u;u+=r;for(;u>0;o=o*256+e[t+l],l+=p,u-=8){}if(a===0){a=1-c}else if(a===f){return o?NaN:(d?-1:1)*Infinity}else{o=o+Math.pow(2,r);a=a-c}return(d?-1:1)*o*Math.pow(2,a-r)};n.write=function(e,t,n,r,i,a){var o,s,f,c=a*8-i-1,u=(1<>1,p=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:a-1,h=r?1:-1,m=t<0||t===0&&1/t<0?1:0;t=Math.abs(t);if(isNaN(t)||t===Infinity){s=isNaN(t)?1:0;o=u}else{o=Math.floor(Math.log(t)/Math.LN2);if(t*(f=Math.pow(2,-o))<1){o--;f*=2}if(o+l>=1){t+=p/f}else{t+=p*Math.pow(2,1-l)}if(t*f>=2){o++;f/=2}if(o+l>=u){s=0;o=u}else if(o+l>=1){s=(t*f-1)*Math.pow(2,i);o=o+l}else{s=t*Math.pow(2,l-1)*Math.pow(2,i);o=0}}for(;i>=8;e[n+d]=s&255,d+=h,s/=256,i-=8){}o=o<0;e[n+d]=o&255,d+=h,o/=256,c-=8){}e[n+d-h]|=m*128}},{}],50:[function(e,t,n){var r=Array.isArray;var i=Object.prototype.toString;t.exports=r||function(e){return!!e&&"[object Array]"==i.call(e)}},{}],51:[function(e,t,n){function r(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}t.exports=r;r.EventEmitter=r;r.prototype._events=undefined;r.prototype._maxListeners=undefined;r.defaultMaxListeners=10;r.prototype.setMaxListeners=function(e){if(!a(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");this._maxListeners=e;return this};r.prototype.emit=function(e){var t,n,r,a,f,c;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||o(this._events.error)&&!this._events.error.length){t=arguments[1];if(t instanceof Error){throw t}throw TypeError('Uncaught, unspecified "error" event.')}}n=this._events[e];if(s(n))return false;if(i(n)){switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:r=arguments.length;a=new Array(r-1);for(f=1;f0&&this._events[e].length>n){this._events[e].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[e].length);if(typeof console.trace==="function"){console.trace()}}}return this};r.prototype.on=r.prototype.addListener;r.prototype.once=function(e,t){if(!i(t))throw TypeError("listener must be a function");var n=false;function r(){this.removeListener(e,r);if(!n){n=true;t.apply(this,arguments)}}r.listener=t;this.on(e,r);return this};r.prototype.removeListener=function(e,t){var n,r,a,s;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;n=this._events[e];a=n.length;r=-1;if(n===t||i(n.listener)&&n.listener===t){delete this._events[e];if(this._events.removeListener)this.emit("removeListener",e,t)}else if(o(n)){for(s=a;s-->0;){if(n[s]===t||n[s].listener&&n[s].listener===t){r=s;break}}if(r<0)return this;if(n.length===1){n.length=0;delete this._events[e]}else{n.splice(r,1)}if(this._events.removeListener)this.emit("removeListener",e,t)}return this};r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[e])delete this._events[e];return this}if(arguments.length===0){for(t in this._events){if(t==="removeListener")continue;this.removeAllListeners(t)}this.removeAllListeners("removeListener");this._events={};return this}n=this._events[e];if(i(n)){this.removeListener(e,n)}else{while(n.length)this.removeListener(e,n[n.length-1])}delete this._events[e];return this};r.prototype.listeners=function(e){var t;if(!this._events||!this._events[e])t=[];else if(i(this._events[e]))t=[this._events[e]];else t=this._events[e].slice();return t};r.listenerCount=function(e,t){var n;if(!e._events||!e._events[t])n=0;else if(i(e._events[t]))n=1;else n=e._events[t].length;return n};function i(e){return typeof e==="function"}function a(e){return typeof e==="number"}function o(e){return typeof e==="object"&&e!==null}function s(e){return e===void 0}},{}],52:[function(e,t,n){var r=t.exports;var i=e("events").EventEmitter;var a=e("./lib/request");var o=e("url");r.request=function(e,t){if(typeof e==="string"){e=o.parse(e)}if(!e)e={};if(!e.host&&!e.port){e.port=parseInt(window.location.port,10)}if(!e.host&&e.hostname){e.host=e.hostname}if(!e.protocol){if(e.scheme){e.protocol=e.scheme+":"}else{e.protocol=window.location.protocol}}if(!e.host){e.host=window.location.hostname||window.location.host}if(/:/.test(e.host)){if(!e.port){e.port=e.host.split(":")[1]}e.host=e.host.split(":")[0]}if(!e.port)e.port=e.protocol=="https:"?443:80;var n=new a(new s,e);if(t)n.on("response",t);return n};r.get=function(e,t){e.method="GET";var n=r.request(e,t);n.end();return n};r.Agent=function(){};r.Agent.defaultMaxSockets=4;var s=function(){if(typeof window==="undefined"){throw new Error("no window object present")}else if(window.XMLHttpRequest){return window.XMLHttpRequest}else if(window.ActiveXObject){var e=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];for(var t=0;tthis.offset){this.emit("data",t.slice(this.offset));this.offset=t.length}};var f=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}},{stream:74,util:78}],55:[function(e,t,n){(function(){var e=typeof n!="undefined"?n:this;var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function r(e){this.message=e}r.prototype=new Error;r.prototype.name="InvalidCharacterError";e.btoa||(e.btoa=function(e){for(var n,i,a=0,o=t,s="";e.charAt(a|0)||(o="=",a%1);s+=o.charAt(63&n>>8-a%1*8)){i=e.charCodeAt(a+=3/4);if(i>255){throw new r("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.")}n=n<<8|i}return s});e.atob||(e.atob=function(e){e=e.replace(/=+$/,"");if(e.length%4==1){throw new r("'atob' failed: The string to be decoded is not correctly encoded.")}for(var n=0,i,a,o=0,s="";a=e.charAt(o++);~a&&(i=n%4?i*64+a:a,n++%4)?s+=String.fromCharCode(255&i>>(-2*n&6)):0){a=t.indexOf(a)}return s})})()},{}],56:[function(e,t,n){arguments[4][42][0].apply(n,arguments)},{dup:42}],57:[function(e,t,n){(function(e){function t(e,t){var n=0;for(var r=e.length-1;r>=0;r--){var i=e[r];if(i==="."){e.splice(r,1)}else if(i===".."){e.splice(r,1);n++}else if(n){e.splice(r,1);n--}}if(t){for(;n--;n){e.unshift("..")}}return e}var r=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var i=function(e){return r.exec(e).slice(1)};n.resolve=function(){var n="",r=false;for(var i=arguments.length-1;i>=-1&&!r;i--){var o=i>=0?arguments[i]:e.cwd();if(typeof o!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!o){continue}n=o+"/"+n;r=o.charAt(0)==="/"}n=t(a(n.split("/"),function(e){return!!e}),!r).join("/");return(r?"/":"")+n||"."};n.normalize=function(e){var r=n.isAbsolute(e),i=o(e,-1)==="/";e=t(a(e.split("/"),function(e){return!!e}),!r).join("/");if(!e&&!r){e="."}if(e&&i){e+="/"}return(r?"/":"")+e};n.isAbsolute=function(e){return e.charAt(0)==="/"};n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(a(e,function(e,t){if(typeof e!=="string"){throw new TypeError("Arguments to path.join must be strings")}return e}).join("/"))};n.relative=function(e,t){e=n.resolve(e).substr(1);t=n.resolve(t).substr(1);function r(e){var t=0;for(;t=0;n--){if(e[n]!=="")break}if(t>n)return[];return e.slice(t,n-t+1)}var i=r(e.split("/"));var a=r(t.split("/"));var o=Math.min(i.length,a.length);var s=o;for(var f=0;f1){for(var n=1;n= 0x80 (not a basic code point)","invalid-input":"Invalid input"},x=u-l,k=Math.floor,E=String.fromCharCode,S;function A(e){throw RangeError(_[e])}function T(e,t){var n=e.length;var r=[];while(n--){r[n]=t(e[n])}return r}function C(e,t){var n=e.split("@");var r="";if(n.length>1){r=n[0]+"@";e=n[1]}e=e.replace(w,".");var i=e.split(".");var a=T(i,t).join(".");return r+a}function I(e){var t=[],n=0,r=e.length,i,a;while(n=55296&&i<=56319&&n65535){e-=65536;t+=E(e>>>10&1023|55296);e=56320|e&1023}t+=E(e);return t}).join("")}function L(e){if(e-48<10){return e-22}if(e-65<26){return e-65}if(e-97<26){return e-97}return u}function R(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function B(e,t,n){var r=0;e=n?k(e/h):e>>1;e+=k(e/t);for(;e>x*p>>1;r+=u){e=k(e/x)}return k(r+(x+1)*e/(e+d))}function M(e){var t=[],n=e.length,r,i=0,a=v,o=m,s,f,d,h,y,b,w,_,x;s=e.lastIndexOf(g);if(s<0){s=0}for(f=0;f=128){A("not-basic")}t.push(e.charCodeAt(f))}for(d=s>0?s+1:0;d=n){A("invalid-input")}w=L(e.charCodeAt(d++));if(w>=u||w>k((c-i)/y)){A("overflow")}i+=w*y;_=b<=o?l:b>=o+p?p:b-o;if(w<_){break}x=u-_;if(y>k(c/x)){A("overflow")}y*=x}r=t.length+1;o=B(i-h,r,h==0);if(k(i/r)>c-a){A("overflow")}a+=k(i/r);i%=r;t.splice(i++,0,a)}return j(t)}function P(e){var t,n,r,i,a,o,s,f,d,h,y,b=[],w,_,x,S;e=I(e);w=e.length;t=v;n=0;a=m;for(o=0;o=t&&yk((c-n)/_)){A("overflow")}n+=(s-t)*_;t=s;for(o=0;oc){A("overflow")}if(y==t){for(f=n,d=u;;d+=u){h=d<=a?l:d>=a+p?p:d-a;if(f0&&c>f){c=f}for(var u=0;u=0){d=l.substr(0,p);h=l.substr(p+1)}else{d=l;h=""}m=decodeURIComponent(d);v=decodeURIComponent(h);if(!r(o,m)){o[m]=v}else if(i(o[m])){o[m].push(v)}else{o[m]=[o[m],v]}}return o};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"}},{}],61:[function(e,t,n){"use strict";var r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,n,s){t=t||"&";n=n||"=";if(e===null){e=undefined}if(typeof e==="object"){return a(o(e),function(o){var s=encodeURIComponent(r(o))+n;if(i(e[o])){return a(e[o],function(e){return s+encodeURIComponent(r(e))}).join(t)}else{return s+encodeURIComponent(r(e[o]))}}).join(t)}if(!s)return"";return encodeURIComponent(r(s))+n+encodeURIComponent(r(e))};var i=Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"; };function a(e,t){if(e.map)return e.map(t);var n=[];for(var r=0;r0){if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var o=new Error("stream.unshift() after end event");e.emit("error",o)}else{if(t.decoder&&!i&&!r)n=t.decoder.write(n);if(!i)t.reading=false;if(t.flowing&&t.length===0&&!t.sync){e.emit("data",n);e.read(0)}else{t.length+=t.objectMode?1:n.length;if(i)t.buffer.unshift(n);else t.buffer.push(n);if(t.needReadable)b(e)}_(e,t)}}else if(!i){t.reading=false}return d(t)}function d(e){return!e.ended&&(e.needReadable||e.length=h){e=h}else{e--;for(var t=1;t<32;t<<=1)e|=e>>t;e++}return e}function v(e,t){if(t.length===0&&t.ended)return 0;if(t.objectMode)return e===0?0:1;if(isNaN(e)||s.isNull(e)){if(t.flowing&&t.buffer.length)return t.buffer[0].length;else return t.length}if(e<=0)return 0;if(e>t.highWaterMark)t.highWaterMark=m(e);if(e>t.length){if(!t.ended){t.needReadable=true;return 0}else return t.length}return e}l.prototype.read=function(e){c("read",e);var t=this._readableState;var n=e;if(!s.isNumber(e)||e>0)t.emittedReadable=false;if(e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended)){c("read: emitReadable",t.length,t.ended);if(t.length===0&&t.ended)C(this);else b(this);return null}e=v(e,t);if(e===0&&t.ended){if(t.length===0)C(this);return null}var r=t.needReadable;c("need readable",r);if(t.length===0||t.length-e0)i=T(e,t);else i=null;if(s.isNull(i)){t.needReadable=true;e=0}t.length-=e;if(t.length===0&&!t.ended)t.needReadable=true;if(n!==e&&t.ended&&t.length===0)C(this);if(!s.isNull(i))this.emit("data",i);return i};function g(e,t){var n=null;if(!s.isBuffer(t)&&!s.isString(t)&&!s.isNullOrUndefined(t)&&!e.objectMode){n=new TypeError("Invalid non-string/buffer chunk")}return n}function y(e,t){if(t.decoder&&!t.ended){var n=t.decoder.end();if(n&&n.length){t.buffer.push(n);t.length+=t.objectMode?1:n.length}}t.ended=true;b(e)}function b(e){var t=e._readableState;t.needReadable=false;if(!t.emittedReadable){c("emitReadable",t.flowing);t.emittedReadable=true;if(t.sync)n.nextTick(function(){w(e)});else w(e)}}function w(e){c("emit readable");e.emit("readable");A(e)}function _(e,t){if(!t.readingMore){t.readingMore=true;n.nextTick(function(){x(e,t)})}}function x(e,t){var n=t.length;while(!t.reading&&!t.flowing&&!t.ended&&t.length=r){if(a)s=n.join("");else s=i.concat(n,r);n.length=0}else{if(e0)throw new Error("endReadable called on non-empty stream");if(!t.endEmitted){t.ended=true;n.nextTick(function(){if(!t.endEmitted&&t.length===0){t.endEmitted=true;e.readable=false;e.emit("end")}})}}function I(e,t){for(var n=0,r=e.length;n1){var n=[];for(var r=0;r",'"',"`"," ","\r","\n"," "],f=["{","}","|","\\","^","`"].concat(s),c=["'"].concat(f),u=["%","/","?",";","#"].concat(c),l=["/","?","#"],p=255,d=/^[a-z0-9A-Z_-]{0,63}$/,h=/^([a-z0-9A-Z_-]{0,63})(.*)$/,m={javascript:true,"javascript:":true},v={javascript:true,"javascript:":true},g={http:true,https:true,ftp:true,gopher:true,file:true,"http:":true,"https:":true,"ftp:":true,"gopher:":true,"file:":true},y=e("querystring");function b(e,t,n){if(e&&E(e)&&e instanceof i)return e;var r=new i;r.parse(e,t,n);return r}i.prototype.parse=function(e,t,n){if(!k(e)){throw new TypeError("Parameter 'url' must be a string, not "+typeof e)}var i=e;i=i.trim();var o=a.exec(i);if(o){o=o[0];var s=o.toLowerCase();this.protocol=s;i=i.substr(o.length)}if(n||o||i.match(/^\/\/[^@\/]+@[^@\/]+/)){var f=i.substr(0,2)==="//";if(f&&!(o&&v[o])){i=i.substr(2);this.slashes=true}}if(!v[o]&&(f||o&&!g[o])){var b=-1;for(var w=0;w127){I+="x"}else{I+=C[j]}}if(!I.match(d)){var R=A.slice(0,w);var B=A.slice(w+1);var M=C.match(h);if(M){R.push(M[1]);B.unshift(M[2])}if(B.length){i="/"+B.join(".")+i}this.hostname=R.join(".");break}}}}if(this.hostname.length>p){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!S){var P=this.hostname.split(".");var O=[];for(var w=0;w0?n.host.split("@"):false;if(d){n.auth=d.shift();n.host=n.hostname=d.shift()}}n.search=e.search;n.query=e.query;if(!S(n.pathname)||!S(n.search)){n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")}n.href=n.format();return n}if(!l.length){n.pathname=null;if(n.search){n.path="/"+n.search}else{n.path=null}n.href=n.format();return n}var h=l.slice(-1)[0];var m=(n.host||e.host)&&(h==="."||h==="..")||h==="";var y=0;for(var b=l.length;b>=0;b--){h=l[b];if(h=="."){l.splice(b,1)}else if(h===".."){l.splice(b,1);y++}else if(y){l.splice(b,1);y--}}if(!c&&!u){for(;y--;y){l.unshift("..")}}if(c&&l[0]!==""&&(!l[0]||l[0].charAt(0)!=="/")){l.unshift("")}if(m&&l.join("/").substr(-1)!=="/"){l.push("")}var w=l[0]===""||l[0]&&l[0].charAt(0)==="/";if(p){n.hostname=n.host=w?"":l.length?l.shift():"";var d=n.host&&n.host.indexOf("@")>0?n.host.split("@"):false;if(d){n.auth=d.shift();n.host=n.hostname=d.shift()}}c=c||n.host&&l.length;if(c&&!w){l.unshift("")}if(!l.length){n.pathname=null;n.path=null}else{n.pathname=l.join("/")}if(!S(n.pathname)||!S(n.search)){n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")}n.auth=e.auth||n.auth;n.slashes=n.slashes||e.slashes;n.href=n.format();return n};i.prototype.parseHost=function(){var e=this.host;var t=o.exec(e);if(t){t=t[0];if(t!==":"){this.port=t.substr(1)}e=e.substr(0,e.length-t.length)}if(e)this.hostname=e};function k(e){return typeof e==="string"}function E(e){return typeof e==="object"&&e!==null}function S(e){return e===null}function A(e){return e==null}},{punycode:59,querystring:62}],77:[function(e,t,n){t.exports=function r(e){return e&&typeof e==="object"&&typeof e.copy==="function"&&typeof e.fill==="function"&&typeof e.readUInt8==="function"}},{}],78:[function(e,t,n){(function(t,r){var i=/%[sdj%]/g;n.format=function(e){if(!x(e)){var t=[];for(var n=0;n=a)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return e}});for(var f=r[n];n=3)r.depth=arguments[2];if(arguments.length>=4)r.colors=arguments[3];if(y(t)){r.showHidden=t}else if(t){n._extend(r,t)}if(E(r.showHidden))r.showHidden=false;if(E(r.depth))r.depth=2;if(E(r.colors))r.colors=false;if(E(r.customInspect))r.customInspect=true;if(r.colors)r.stylize=f;return l(r,e,r.depth)}n.inspect=s;s.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};s.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function f(e,t){var n=s.styles[t];if(n){return"["+s.colors[n][0]+"m"+e+"["+s.colors[n][1]+"m"}else{return e}}function c(e,t){return e}function u(e){var t={};e.forEach(function(e,n){t[e]=true});return t}function l(e,t,r){if(e.customInspect&&t&&I(t.inspect)&&t.inspect!==n.inspect&&!(t.constructor&&t.constructor.prototype===t)){var i=t.inspect(r,e);if(!x(i)){i=l(e,i,r)}return i}var a=p(e,t);if(a){return a}var o=Object.keys(t);var s=u(o);if(e.showHidden){o=Object.getOwnPropertyNames(t)}if(C(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0)){return d(t)}if(o.length===0){if(I(t)){var f=t.name?": "+t.name:"";return e.stylize("[Function"+f+"]","special")}if(S(t)){return e.stylize(RegExp.prototype.toString.call(t),"regexp")}if(T(t)){return e.stylize(Date.prototype.toString.call(t),"date")}if(C(t)){return d(t)}}var c="",y=false,b=["{","}"];if(g(t)){y=true;b=["[","]"]}if(I(t)){var w=t.name?": "+t.name:"";c=" [Function"+w+"]"}if(S(t)){c=" "+RegExp.prototype.toString.call(t)}if(T(t)){c=" "+Date.prototype.toUTCString.call(t)}if(C(t)){c=" "+d(t)}if(o.length===0&&(!y||t.length==0)){return b[0]+c+b[1]}if(r<0){if(S(t)){return e.stylize(RegExp.prototype.toString.call(t),"regexp")}else{return e.stylize("[Object]","special")}}e.seen.push(t);var _;if(y){_=h(e,t,r,s,o)}else{_=o.map(function(n){return m(e,t,r,s,n,y)})}e.seen.pop();return v(_,c,b)}function p(e,t){if(E(t))return e.stylize("undefined","undefined");if(x(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}if(_(t))return e.stylize(""+t,"number");if(y(t))return e.stylize(""+t,"boolean");if(b(t))return e.stylize("null","null")}function d(e){return"["+Error.prototype.toString.call(e)+"]"}function h(e,t,n,r,i){var a=[];for(var o=0,s=t.length;o-1){if(a){s=s.split("\n").map(function(e){return" "+e}).join("\n").substr(2)}else{s="\n"+s.split("\n").map(function(e){return" "+e}).join("\n")}}}else{s=e.stylize("[Circular]","special")}}if(E(o)){if(a&&i.match(/^\d+$/)){return s}o=JSON.stringify(""+i);if(o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){o=o.substr(1,o.length-2);o=e.stylize(o,"name")}else{o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");o=e.stylize(o,"string")}}return o+": "+s}function v(e,t,n){var r=0;var i=e.reduce(function(e,t){r++;if(t.indexOf("\n")>=0)r++;return e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(i>60){return n[0]+(t===""?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]}return n[0]+t+" "+e.join(", ")+" "+n[1]}function g(e){return Array.isArray(e)}n.isArray=g;function y(e){return typeof e==="boolean"}n.isBoolean=y;function b(e){return e===null}n.isNull=b;function w(e){return e==null}n.isNullOrUndefined=w;function _(e){return typeof e==="number"; }n.isNumber=_;function x(e){return typeof e==="string"}n.isString=x;function k(e){return typeof e==="symbol"}n.isSymbol=k;function E(e){return e===void 0}n.isUndefined=E;function S(e){return A(e)&&L(e)==="[object RegExp]"}n.isRegExp=S;function A(e){return typeof e==="object"&&e!==null}n.isObject=A;function T(e){return A(e)&&L(e)==="[object Date]"}n.isDate=T;function C(e){return A(e)&&(L(e)==="[object Error]"||e instanceof Error)}n.isError=C;function I(e){return typeof e==="function"}n.isFunction=I;function j(e){return e===null||typeof e==="boolean"||typeof e==="number"||typeof e==="string"||typeof e==="symbol"||typeof e==="undefined"}n.isPrimitive=j;n.isBuffer=e("./support/isBuffer");function L(e){return Object.prototype.toString.call(e)}function R(e){return e<10?"0"+e.toString(10):e.toString(10)}var B=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function M(){var e=new Date;var t=[R(e.getHours()),R(e.getMinutes()),R(e.getSeconds())].join(":");return[e.getDate(),B[e.getMonth()],t].join(" ")}n.log=function(){console.log("%s - %s",M(),n.format.apply(n,arguments))};n.inherits=e("inherits");n._extend=function(e,t){if(!t||!A(t))return e;var n=Object.keys(t);var r=n.length;while(r--){e[n[r]]=t[n[r]]}return e};function P(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":77,_process:58,inherits:125}],79:[function(e,t,n){(function(n,r){t.exports=y;t.exports.announceList=[["udp://tracker.publicbt.com:80"],["udp://tracker.openbittorrent.com:80"],["udp://open.demonii.com:1337"],["udp://tracker.webtorrent.io:80"],["wss://tracker.webtorrent.io"]];t.exports.parseInput=b;var i=e("bencode");var a=e("block-stream2");var o=e("piece-length");var s=e("path");var f=e("dezalgo");var c=e("filestream/read");var u=e("flatten");var l=e("fs");var p=e("is-file");var d=e("multistream");var h=e("once");var m=e("run-parallel");var v=e("simple-sha1");var g=e("stream");function y(e,t,n){if(typeof t==="function"){n=t;t={}}if(!t)t={};b(e,t,function(e,r,i){if(e)return n(e);t.singleFileTorrent=i;S(r,t,n)})}function b(e,t,n){if(typeof t==="function"){n=t;t={}}if(!t)t={};n=f(n);if(Array.isArray(e)&&e.length===0)throw new Error("invalid input type");if(C(e))e=Array.prototype.slice.call(e);if(!Array.isArray(e))e=[e];if(!t.name)t.name=e[0]&&e[0].name;if(!t.name)t.name=typeof e[0]==="string"&&s.basename(e[0]);if(t.name===undefined){throw new Error("missing option 'name' and unable to infer it from input[0].name")}if(e.length===1&&!e[0].name)e[0].name=t.name;var i=e.reduce(function(e,t){return e+Number(typeof t==="string")},0);var a=e.length===1;if(e.length===1&&typeof e[0]==="string"){p(e[0],function(e,t){if(e)return n(e);a=t;o()})}else{o()}function o(){m(e.map(function(e){return function(n){var o={};if(T(e)){o.getStream=j(e);o.length=e.size}else if(r.isBuffer(e)){o.getStream=L(e);o.length=e.length}else if(I(e)){if(!t.pieceLength){throw new Error("must specify `pieceLength` option if input is Stream")}o.getStream=B(e,o);o.length=0}else if(typeof e==="string"){if(typeof l.readdir!=="function"){throw new Error("filesystem paths do not work in the browser")}var f=i>1||a;w(e,f,n);return}else{throw new Error("invalid input type")}if(!e.name)throw new Error("missing requied `name` property on input");o.path=e.name.split(s.sep);n(null,o)}}),function(e,t){if(e)return n(e);t=u(t);n(null,t,a)})}}function w(e,t,n){x(e,_,function(r,i){if(r)return n(r);if(Array.isArray(i))i=u(i);else i=[i];e=s.normalize(e);if(t){e=e.slice(0,e.lastIndexOf(s.sep)+1)}if(e[e.length-1]!==s.sep)e+=s.sep;i.forEach(function(t){t.getStream=R(t.path);t.path=t.path.replace(e,"").split(s.sep)});n(null,i)})}function _(e,t){t=h(t);l.stat(e,function(n,r){if(n)return t(n);var i={length:r.size,path:e};t(null,i)})}function x(e,t,n){l.readdir(e,function(r,i){if(r&&r.code==="ENOTDIR"){t(e,n)}else if(r){n(r)}else{m(i.filter(k).map(function(n){return function(r){x(s.join(e,n),t,r)}}),n)}})}function k(e){return e[0]!=="."}function E(e,t,n){n=h(n);var i=[];var o=0;var s=e.map(function(e){return e.getStream});var f=0;var c=0;var u=false;var l=new d(s);var p=new a(t,{zeroPadding:false});l.on("error",y);l.pipe(p).on("data",m).on("end",g).on("error",y);function m(e){o+=e.length;var t=c;v(e,function(e){i[t]=e;f-=1;w()});f+=1;c+=1}function g(){u=true;w()}function y(e){b();n(e)}function b(){l.removeListener("error",y);p.removeListener("data",m);p.removeListener("end",g);p.removeListener("error",y)}function w(){if(u&&f===0){b();n(null,new r(i.join(""),"hex"),o)}}}function S(e,r,a){var s=r.announceList;if(!s){if(typeof r.announce==="string")s=[[r.announce]];else if(Array.isArray(r.announce)){s=r.announce.map(function(e){return[e]})}}if(!s)s=[];if(n.WEBTORRENT_ANNOUNCE){if(typeof n.WEBTORRENT_ANNOUNCE==="string"){s.push([[n.WEBTORRENT_ANNOUNCE]])}else if(Array.isArray(n.WEBTORRENT_ANNOUNCE)){s=s.concat(n.WEBTORRENT_ANNOUNCE.map(function(e){return[e]}))}}if(s.length===0){s=s.concat(t.exports.announceList)}var f={info:{name:r.name},announce:s[0][0],"announce-list":s,"creation date":Number(r.creationDate)||Date.now(),encoding:"UTF-8"};if(r.comment!==undefined)f.comment=r.comment;if(r.createdBy!==undefined)f["created by"]=r.createdBy;if(r.private!==undefined)f.info.private=Number(r.private);if(r.sslCert!==undefined)f.info["ssl-cert"]=r.sslCert;if(r.urlList!==undefined)f["url-list"]=r.urlList;var c=r.pieceLength||o(e.reduce(A,0));f.info["piece length"]=c;E(e,c,function(t,n,o){if(t)return a(t);f.info.pieces=n;e.forEach(function(e){delete e.getStream});if(r.singleFileTorrent){f.info.length=o}else{f.info.files=e}a(null,i.encode(f))})}function A(e,t){return e+t.length}function T(e){return typeof Blob!=="undefined"&&e instanceof Blob}function C(e){return typeof FileList==="function"&&e instanceof FileList}function I(e){return typeof e==="object"&&typeof e.pipe==="function"}function j(e){return function(){return new c(e)}}function L(e){return function(){var t=new g.PassThrough;t.end(e);return t}}function R(e){return function(){return l.createReadStream(e)}}function B(e,t){return function(){var n=new g.Transform;n._transform=function(e,n,r){t.length+=e.length;this.push(e);r()};e.pipe(n);return n}}}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},e("buffer").Buffer)},{bencode:80,"block-stream2":84,buffer:47,dezalgo:96,"filestream/read":102,flatten:103,fs:45,"is-file":104,multistream:105,once:108,path:57,"piece-length":109,"run-parallel":111,"simple-sha1":115,stream:74}],80:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{"./lib/decode":81,"./lib/encode":83,dup:15}],81:[function(e,t,n){arguments[4][16][0].apply(n,arguments)},{"./dict":82,buffer:47,dup:16}],82:[function(e,t,n){arguments[4][17][0].apply(n,arguments)},{dup:17}],83:[function(e,t,n){arguments[4][18][0].apply(n,arguments)},{buffer:47,dup:18}],84:[function(e,t,n){arguments[4][34][0].apply(n,arguments)},{buffer:47,defined:85,dup:34,inherits:86,"readable-stream":95}],85:[function(e,t,n){arguments[4][35][0].apply(n,arguments)},{dup:35}],86:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],87:[function(e,t,n){arguments[4][36][0].apply(n,arguments)},{"./_stream_readable":89,"./_stream_writable":91,_process:58,"core-util-is":92,dup:36,inherits:86}],88:[function(e,t,n){arguments[4][37][0].apply(n,arguments)},{"./_stream_transform":90,"core-util-is":92,dup:37,inherits:86}],89:[function(e,t,n){arguments[4][38][0].apply(n,arguments)},{_process:58,buffer:47,"core-util-is":92,dup:38,events:51,inherits:86,isarray:93,stream:74,"string_decoder/":94}],90:[function(e,t,n){arguments[4][39][0].apply(n,arguments)},{"./_stream_duplex":87,"core-util-is":92,dup:39,inherits:86}],91:[function(e,t,n){arguments[4][40][0].apply(n,arguments)},{"./_stream_duplex":87,_process:58,buffer:47,"core-util-is":92,dup:40,inherits:86,stream:74}],92:[function(e,t,n){arguments[4][41][0].apply(n,arguments)},{buffer:47,dup:41}],93:[function(e,t,n){arguments[4][42][0].apply(n,arguments)},{dup:42}],94:[function(e,t,n){arguments[4][43][0].apply(n,arguments)},{buffer:47,dup:43}],95:[function(e,t,n){arguments[4][44][0].apply(n,arguments)},{"./lib/_stream_duplex.js":87,"./lib/_stream_passthrough.js":88,"./lib/_stream_readable.js":89,"./lib/_stream_transform.js":90,"./lib/_stream_writable.js":91,dup:44,stream:74}],96:[function(e,t,n){arguments[4][29][0].apply(n,arguments)},{asap:97,dup:29,wrappy:98}],97:[function(e,t,n){arguments[4][30][0].apply(n,arguments)},{_process:58,dup:30}],98:[function(e,t,n){arguments[4][31][0].apply(n,arguments)},{dup:31}],99:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],100:[function(e,t,n){(function(n){var r=e("is-typedarray").strict;t.exports=function(e){var t=n.TYPED_ARRAY_SUPPORT?n._augment:function(e){return new n(e)};if(e instanceof Uint8Array){return t(e)}else if(e instanceof ArrayBuffer){return t(new Uint8Array(e))}else if(r(e)){return t(new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}else{return new n(e)}}}).call(this,e("buffer").Buffer)},{buffer:47,"is-typedarray":101}],101:[function(e,t,n){t.exports=a;a.strict=o;a.loose=s;var r=Object.prototype.toString;var i={"[object Int8Array]":true,"[object Int16Array]":true,"[object Int32Array]":true,"[object Uint8Array]":true,"[object Uint16Array]":true,"[object Uint32Array]":true,"[object Float32Array]":true,"[object Float64Array]":true};function a(e){return o(e)||s(e)}function o(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function s(e){return i[r.call(e)]}},{}],102:[function(e,t,n){var r=e("stream").Readable;var i=e("inherits");var a=/^.*\.(\w+)$/;var o=e("typedarray-to-buffer");function s(e,t){var n=this;if(!(this instanceof s)){return new s(e,t)}t=t||{};r.call(this,t);this._offset=0;this._ready=false;this._file=e;this._size=e.size;this._chunkSize=t.chunkSize||Math.max(this._size/1e3,200*1024);this.reader=new FileReader;this._generateHeaderBlocks(e,t,function(e,t){if(e){return n.emit("error",e)}if(Array.isArray(t)){t.forEach(function(e){n.push(e)})}n._ready=true;n.emit("_ready")})}i(s,r);t.exports=s;s.prototype._generateHeaderBlocks=function(e,t,n){n(null,[])};s.prototype._read=function(){if(!this._ready){this.once("_ready",this._read.bind(this));return}var e=this;var t=this.reader;var n=this._offset;var r=this._offset+this._chunkSize;if(r>this._size)r=this._size;if(n===this._size){this.destroy();this.push(null);return}t.onload=function(){e._offset=r;e.push(o(t.result))};t.onerror=function(){e.emit("error",t.error)};t.readAsArrayBuffer(this._file.slice(n,r))};s.prototype.destroy=function(){this._file=null;if(this.reader){this.reader.onload=null;this.reader.onerror=null;try{this.reader.abort()}catch(e){}}this.reader=null}},{inherits:99,stream:74,"typedarray-to-buffer":100}],103:[function(e,t,n){t.exports=function r(e,t){t=typeof t=="number"?t:Infinity;return n(e,1);function n(e,r){return e.reduce(function(e,i){if(Array.isArray(i)&&r=n){break}n=r;i=t[a]}return i}},{}],111:[function(e,t,n){var r=e("dezalgo");t.exports=function(e,t){if(t)t=r(t);var n,i,a;if(Array.isArray(e)){n=[];i=e.length}else{a=Object.keys(e);n={};i=a.length}function o(e,r,a){n[e]=a;if(--i===0||r){if(t)t(r,n);t=null}}if(!i){if(t)t(null,n);t=null}else if(a){a.forEach(function(t){e[t](o.bind(undefined,t))})}else{e.forEach(function(e,t){e(o.bind(undefined,t))})}}},{dezalgo:112}],112:[function(e,t,n){arguments[4][29][0].apply(n,arguments)},{asap:113,dup:29,wrappy:114}],113:[function(e,t,n){arguments[4][30][0].apply(n,arguments)},{_process:58,dup:30}],114:[function(e,t,n){arguments[4][31][0].apply(n,arguments)},{dup:31}],115:[function(e,t,n){var r=e("rusha");var i=new r;var a=window.crypto||window.msCrypto||{};var o=a.subtle||a.webkitSubtle;var s=i.digest.bind(i);try{o.digest({name:"sha-1"},new Uint8Array).catch(function(){o=false})}catch(f){o=false}function c(e,t){if(!o){setTimeout(t,0,s(e));return}if(typeof e==="string"){e=u(e)}o.digest({name:"sha-1"},e).then(function n(e){t(l(new Uint8Array(e)))},function r(n){t(s(e))})}function u(e){var t=e.length;var n=new Uint8Array(t);for(var r=0;r>>4).toString(16));n.push((i&15).toString(16))}return n.join("")}t.exports=c;t.exports.sync=s},{rusha:116}],116:[function(e,t,n){(function(e){(function(){if(typeof t!=="undefined"){t.exports=a}else if(typeof window!=="undefined"){window.Rusha=a}if(typeof FileReaderSync!=="undefined"){var n=new FileReaderSync,r=new a(4*1024*1024);self.onmessage=function s(e){var t,n=e.data.data;try{t=r.digest(n);self.postMessage({id:e.data.id,hash:t})}catch(i){self.postMessage({id:e.data.id,error:i.name})}}}var i={getDataType:function(t){if(typeof t==="string"){return"string"}if(t instanceof Array){return"array"}if(typeof e!=="undefined"&&e.Buffer&&e.Buffer.isBuffer(t)){return"buffer"}if(t instanceof ArrayBuffer){return"arraybuffer"}if(t.buffer instanceof ArrayBuffer){return"view"}if(t instanceof Blob){return"blob"}throw new Error("Unsupported data type.")}};function a(e){"use strict";var t={fill:0};var r=function(e){for(e+=9;e%64>0;e+=1);return e};var a=function(e,t){for(var n=t>>2;n>2]|=128<<24-(t%4<<3);e[((t>>2)+2&~15)+14]=n>>29;e[((t>>2)+2&~15)+15]=n<<3};var f=function(e,t,n,r,i){var a=this,o,s=i%4,f=r%4,c=r-f;if(c>0){switch(s){case 0:e[i+3|0]=a.charCodeAt(n);case 1:e[i+2|0]=a.charCodeAt(n+1);case 2:e[i+1|0]=a.charCodeAt(n+2);case 3:e[i|0]=a.charCodeAt(n+3)}}for(o=s;o>2]=a.charCodeAt(n+o)<<24|a.charCodeAt(n+o+1)<<16|a.charCodeAt(n+o+2)<<8|a.charCodeAt(n+o+3)}switch(f){case 3:e[i+c+1|0]=a.charCodeAt(n+c+2);case 2:e[i+c+2|0]=a.charCodeAt(n+c+1);case 1:e[i+c+3|0]=a.charCodeAt(n+c)}};var c=function(e,t,n,r,i){var a=this,o,s=i%4,f=r%4,c=r-f;if(c>0){switch(s){case 0:e[i+3|0]=a[n];case 1:e[i+2|0]=a[n+1];case 2:e[i+1|0]=a[n+2];case 3:e[i|0]=a[n+3]}}for(o=4-s;o>2]=a[n+o]<<24|a[n+o+1]<<16|a[n+o+2]<<8|a[n+o+3]}switch(f){case 3:e[i+c+1|0]=a[n+c+2];case 2:e[i+c+2|0]=a[n+c+1];case 1:e[i+c+3|0]=a[n+c]}};var u=function(e,t,r,i,a){var o=this,s,f=a%4,c=i%4,u=i-c;var l=new Uint8Array(n.readAsArrayBuffer(o.slice(r,r+i)));if(u>0){switch(f){case 0:e[a+3|0]=l[0];case 1:e[a+2|0]=l[1];case 2:e[a+1|0]=l[2];case 3:e[a|0]=l[3]}}for(s=4-f;s>2]=l[s]<<24|l[s+1]<<16|l[s+2]<<8|l[s+3]}switch(c){case 3:e[a+u+1|0]=l[u+2];case 2:e[a+u+2|0]=l[u+1];case 1:e[a+u+3|0]=l[u]}};var l=function(e){switch(i.getDataType(e)){case"string":return f.bind(e);case"array":return c.bind(e);case"buffer":return c.bind(e);case"arraybuffer":return c.bind(new Uint8Array(e));case"view":return c.bind(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));case"blob":return u.bind(e)}};var p=function(e,t){switch(i.getDataType(e)){case"string":return e.slice(t);case"array":return e.slice(t);case"buffer":return e.slice(t);case"arraybuffer":return e.slice(t);case"view":return e.buffer.slice(t)}};var d=function(e){var t,n,r="0123456789abcdef",i=[],a=new Uint8Array(e);for(t=0;t>4&15)+r.charAt(n>>0&15)}return i.join("")};var h=function(e){var t;if(e<=65536)return 65536;if(e<16777216){for(t=1;t0){throw new Error("Chunk size must be a multiple of 128 bit")}t.maxChunkLen=e;t.padMaxChunkLen=r(e);t.heap=new ArrayBuffer(h(t.padMaxChunkLen+320+20));t.h32=new Int32Array(t.heap);t.h8=new Int8Array(t.heap);t.core=o({Int32Array:Int32Array,DataView:DataView},{},t.heap);t.buffer=null};m(e||64*1024);var v=function(e,t){var n=new Int32Array(e,t+320,5);n[0]=1732584193;n[1]=-271733879;n[2]=-1732584194;n[3]=271733878;n[4]=-1009589776};var g=function(e,n){var i=r(e);var o=new Int32Array(t.heap,0,i>>2);a(o,e);s(o,e,n);return i};var y=function(e,n,r){l(e)(t.h8,t.h32,n,r,0)};var b=function(e,n,r,i,a){var o=r;if(a){o=g(r,i)}y(e,n,r);t.core.hash(o,t.padMaxChunkLen)};var w=function(e,t){var n=new Int32Array(e,t+320,5);var r=new Int32Array(5);var i=new DataView(r.buffer);i.setInt32(0,n[0],false);i.setInt32(4,n[1],false);i.setInt32(8,n[2],false);i.setInt32(12,n[3],false);i.setInt32(16,n[4],false);return r};var _=this.rawDigest=function(e){var n=e.byteLength||e.length||e.size||0;v(t.heap,t.padMaxChunkLen);var r=0,i=t.maxChunkLen,a;for(r=0;n>r+i;r+=i){b(e,r,i,n,false)}b(e,r,n-r,n,true);return w(t.heap,t.padMaxChunkLen)};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(e){return d(_(e).buffer)}}function o(e,t,n){"use asm";var r=new e.Int32Array(n);function i(e,t){e=e|0;t=t|0;var n=0,i=0,a=0,o=0,s=0,f=0,c=0,u=0,l=0,p=0,d=0,h=0,m=0,v=0;a=r[t+320>>2]|0;s=r[t+324>>2]|0;c=r[t+328>>2]|0;l=r[t+332>>2]|0;d=r[t+336>>2]|0;for(n=0;(n|0)<(e|0);n=n+64|0){o=a;f=s;u=c;p=l;h=d;for(i=0;(i|0)<64;i=i+4|0){v=r[n+i>>2]|0;m=((a<<5|a>>>27)+(s&c|~s&l)|0)+((v+d|0)+1518500249|0)|0;d=l;l=c;c=s<<30|s>>>2;s=a;a=m;r[e+i>>2]=v}for(i=e+64|0;(i|0)<(e+80|0);i=i+4|0){v=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((a<<5|a>>>27)+(s&c|~s&l)|0)+((v+d|0)+1518500249|0)|0;d=l;l=c;c=s<<30|s>>>2;s=a;a=m;r[i>>2]=v}for(i=e+80|0;(i|0)<(e+160|0);i=i+4|0){v=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((a<<5|a>>>27)+(s^c^l)|0)+((v+d|0)+1859775393|0)|0;d=l;l=c;c=s<<30|s>>>2;s=a;a=m;r[i>>2]=v}for(i=e+160|0;(i|0)<(e+240|0);i=i+4|0){v=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((a<<5|a>>>27)+(s&c|s&l|c&l)|0)+((v+d|0)-1894007588|0)|0;d=l;l=c;c=s<<30|s>>>2;s=a;a=m;r[i>>2]=v}for(i=e+240|0;(i|0)<(e+320|0);i=i+4|0){v=(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])<<1|(r[i-12>>2]^r[i-32>>2]^r[i-56>>2]^r[i-64>>2])>>>31;m=((a<<5|a>>>27)+(s^c^l)|0)+((v+d|0)-899497514|0)|0;d=l;l=c;c=s<<30|s>>>2;s=a;a=m;r[i>>2]=v}a=a+o|0;s=s+f|0;c=c+u|0;l=l+p|0;d=d+h|0}r[t+320>>2]=a;r[t+324>>2]=s;r[t+328>>2]=c;r[t+332>>2]=l;r[t+336>>2]=d}return{hash:i}}})()}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],117:[function(e,t,n){n=t.exports=e("./debug");n.log=a;n.formatArgs=i;n.save=o;n.load=s;n.useColors=r;n.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:f();n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"];function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}n.formatters.j=function(e){return JSON.stringify(e)};function i(){var e=arguments;var t=this.useColors;e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff);if(!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var i=0;var a=0;e[0].replace(/%[a-z%]/g,function(e){if("%%"===e)return;i++;if("%c"===e){a=i}});e.splice(a,0,r);return e}function a(){return"object"===typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function o(e){try{if(null==e){n.storage.removeItem("debug")}else{n.storage.debug=e}}catch(t){}}function s(){var e;try{e=n.storage.debug}catch(t){}return e}n.enable(s());function f(){try{return window.localStorage}catch(e){}}},{"./debug":118}],118:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,ms:119}],119:[function(e,t,n){var r=1e3;var i=r*60;var a=i*60;var o=a*24;var s=o*365.25;t.exports=function(e,t){t=t||{};if("string"==typeof e)return f(e);return t.long?u(e):c(e)};function f(e){e=""+e;if(e.length>1e4)return;var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(!t)return;var n=parseFloat(t[1]);var f=(t[2]||"ms").toLowerCase();switch(f){case"years":case"year":case"yrs":case"yr":case"y":return n*s;case"days":case"day":case"d":return n*o;case"hours":case"hour":case"hrs":case"hr":case"h":return n*a;case"minutes":case"minute":case"mins":case"min":case"m":return n*i;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n}}function c(e){if(e>=o)return Math.round(e/o)+"d";if(e>=a)return Math.round(e/a)+"h";if(e>=i)return Math.round(e/i)+"m";if(e>=r)return Math.round(e/r)+"s";return e+"ms"}function u(e){return l(e,o,"day")||l(e,a,"hour")||l(e,i,"minute")||l(e,r,"second")||e+" ms"}function l(e,t,n){if(e=Math.pow(2,e)){return r(e,t)}else return o};r.rack=function(e,t,n){var i=function(i){var o=0;do{if(o++>10){if(n)e+=n;else throw new Error("too many ID collisions, use more bits")}var s=r(e,t)}while(Object.hasOwnProperty.call(a,s));a[s]=i;return s};var a=i.hats={};i.get=function(e){return i.hats[e]};i.set=function(e,t){i.hats[e]=t;return i};i.bits=e||128;i.base=t||16;return i}},{}],125:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],126:[function(e,t,n){(function(n){var r=e("path");var i=e("fs");function a(){this.types=Object.create(null);this.extensions=Object.create(null)}a.prototype.define=function(e){for(var t in e){var r=e[t];for(var i=0;i=0?i.split("&"):[];o.forEach(function(e){var n=e.split("=");if(n.length!==2)return;var r=n[0];var i=n[1];if(r==="dn")i=decodeURIComponent(i).replace(/\+/g," ");if(r==="tr"||r==="xs"||r==="as"||r==="ws"){i=decodeURIComponent(i)}if(r==="kt")i=decodeURIComponent(i).split("+");if(t[r]){if(Array.isArray(t[r])){t[r].push(i)}else{var a=t[r];t[r]=[a,i]}}else{t[r]=i}});var s;if(t.xt){var f=Array.isArray(t.xt)?t.xt:[t.xt];f.forEach(function(e){if(s=e.match(/^urn:btih:(.{40})/)){t.infoHash=new n(s[1],"hex").toString("hex")}else if(s=e.match(/^urn:btih:(.{32})/)){var i=r.decode(s[1]);t.infoHash=new n(i,"binary").toString("hex")}})}if(t.dn)t.name=t.dn;if(t.kt)t.keywords=t.kt;if(typeof t.tr==="string")t.announce=[t.tr];else if(Array.isArray(t.tr))t.announce=t.tr;else t.announce=[];a(t.announce);t.urlList=[];if(typeof t.as==="string"||Array.isArray(t.as)){t.urlList=t.urlList.concat(t.as)}if(typeof t.ws==="string"||Array.isArray(t.ws)){t.urlList=t.urlList.concat(t.ws)}return t}function s(e){e=i(e);if(e.infoHash)e.xt="urn:btih:"+e.infoHash;if(e.name)e.dn=e.name;if(e.keywords)e.kt=e.keywords;if(e.announce)e.tr=e.announce;if(e.urlList){e.ws=e.urlList;delete e.as}var t="magnet:?";Object.keys(e).filter(function(e){return e.length===2}).forEach(function(n,r){var i=Array.isArray(e[n])?e[n]:[e[n]];i.forEach(function(e,i){if((r>0||i>0)&&(n!=="kt"||i===0))t+="&";if(n==="dn")e=encodeURIComponent(e).replace(/%20/g,"+");if(n==="tr"||n==="xs"||n==="as"||n==="ws"){e=encodeURIComponent(e)}if(n==="kt")e=encodeURIComponent(e);if(n==="kt"&&i>0)t+="+"+e;else t+=n+"="+e})});return t}}).call(this,e("buffer").Buffer)},{buffer:47,"thirty-two":137,uniq:139,xtend:140}],137:[function(e,t,n){var r=e("./thirty-two");n.encode=r.encode;n.decode=r.decode},{"./thirty-two":138}],138:[function(e,t,n){(function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";var r=[255,255,26,27,28,29,30,31,255,255,255,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255,255];function i(e){var t=Math.floor(e.length/5);return e.length%5==0?t:t+1}n.encode=function(n){var r=0;var a=0;var o=0;var s=0;var f=new e(i(n)*8);if(!e.isBuffer(n)){n=new e(n)}while(r3){s=c&255>>o;o=(o+5)%8;s=s<>8-o;r++}else{s=c>>8-(o+5)&31;o=(o+5)%8;if(o==0)r++}f[a]=t.charCodeAt(s);a++}for(r=a;r>>n;s[o]=a;o++;a=255&i<<8-n}}else{throw new Error("Invalid input - it is not base32 encoded string")}}return s.slice(0,o)}}).call(this,e("buffer").Buffer)},{buffer:47}],139:[function(e,t,n){"use strict";function r(e,t){var n=1,r=e.length,i=e[0],a=e[0];for(var o=1;o0?[e["url-list"]]:[]}t.urlList=(e["url-list"]||[]).map(function(e){return e.toString()});var s=e.info.files||[e.info];t.files=s.map(function(e,n){var r=[].concat(e.name||t.name,e.path||[]).map(function(e){return e.toString()});return{path:i.join.apply(null,[i.sep].concat(r)).slice(1), name:r[r.length-1],length:e.length,offset:s.slice(0,n).reduce(c,0)}});t.length=s.reduce(c,0);var f=t.files[t.files.length-1];t.pieceLength=e.info["piece length"];t.lastPieceLength=(f.offset+f.length)%t.pieceLength||t.pieceLength;t.pieces=u(e.info.pieces);return t}function f(e){var t={info:e.info};t["announce-list"]=e.announce.map(function(e){if(!t.announce)t.announce=e;e=new n(e,"utf8");return[e]});if(e.created){t["creation date"]=e.created.getTime()/1e3|0}return r.encode(t)}function c(e,t){return e+t.length}function u(e){var t=[];for(var n=0;n0;return u(i,o,s,function(e){if(!n)n=e;if(e)r.forEach(l);if(o)return;r.forEach(l);t(n)})});return e.reduce(p)};t.exports=d},{"end-of-stream":123,fs:45,once:131}],150:[function(e,t,n){t.exports=function(e,t){var n=true;var r=t.indexOf("=");if(-1==r)return-2;var i=t.slice(r+1).split(",").map(function(t){var t=t.split("-"),r=parseInt(t[0],10),i=parseInt(t[1],10);if(isNaN(r)){r=e-i;i=e-1}else if(isNaN(i)){i=e-1}if(i>e-1)i=e-1;if(isNaN(r)||isNaN(i)||r>i||r<0)n=false;return{start:r,end:i}});i.type=t.slice(0,r);return n?i:-1}},{}],151:[function(e,t,n){t.exports=i;t.exports.filter=a;var r=e("events").EventEmitter;function i(e,t,n){if(!Array.isArray(n))n=[n];var r=[];n.forEach(function(n){var i=function(){var e=[].slice.call(arguments);e.unshift(n);t.emit.apply(t,e)};r.push(i);e.on(n,i)});return function i(){n.forEach(function(t,n){e.removeListener(t,r[n])})}}function a(e,t){var n=new r;i(e,n,t);return n}},{events:51}],152:[function(e,t,n){arguments[4][111][0].apply(n,arguments)},{dezalgo:153,dup:111}],153:[function(e,t,n){arguments[4][29][0].apply(n,arguments)},{asap:154,dup:29,wrappy:155}],154:[function(e,t,n){arguments[4][30][0].apply(n,arguments)},{_process:58,dup:30}],155:[function(e,t,n){arguments[4][31][0].apply(n,arguments)},{dup:31}],156:[function(e,t,n){arguments[4][115][0].apply(n,arguments)},{dup:115,rusha:157}],157:[function(e,t,n){arguments[4][116][0].apply(n,arguments)},{dup:116}],158:[function(e,t,n){arguments[4][24][0].apply(n,arguments)},{dup:24}],159:[function(e,t,n){(function(n){t.exports=u;var r=e("debug")("torrent-discovery");var i=e("bittorrent-dht/client");var a=e("events").EventEmitter;var o=e("xtend/mutable");var s=e("inherits");var f=e("re-emitter");var c=e("bittorrent-tracker/client");s(u,a);function u(e){var t=this;if(!(t instanceof u))return new u(e);a.call(t);o(t,{announce:[],dht:typeof i==="function",rtcConfig:null,peerId:null,port:0,tracker:true,wrtc:null},e);t._externalDHT=typeof t.dht==="object";t._performedDHTLookup=false;if(!t.peerId)throw new Error("peerId required");if(!n.browser&&!t.port)throw new Error("port required");if(t.dht)t._createDHT(t.dhtPort)}u.prototype.setTorrent=function(e){var t=this;if(t.torrent)return;if(e&&e.infoHash){t.torrent=e;t.infoHash=e.infoHash}else{if(t.infoHash)return;t.infoHash=e}r("setTorrent %s",t.infoHash);if(t.tracker&&t.tracker!==true){t.tracker.torrentLength=e.length}else{t._createTracker()}if(t.dht){if(t.dht.ready)t._dhtLookupAndAnnounce();else t.dht.on("ready",t._dhtLookupAndAnnounce.bind(t))}};u.prototype.stop=function(e){var t=this;if(t.tracker){if(t.tracker.stop)t.tracker.stop();if(t.tracker.destroy)t.tracker.destroy()}if(!t._externalDHT&&t.dht&&t.dht.destroy)t.dht.destroy(e);else n.nextTick(function(){e(null)})};u.prototype._createDHT=function(e){var t=this;if(!t._externalDHT)t.dht=new i;f(t.dht,t,["error","warning"]);t.dht.on("peer",function(e,n){if(n===t.infoHash)t.emit("peer",e)});if(!t._externalDHT)t.dht.listen(e)};u.prototype._createTracker=function(){var e=this;if(!e.tracker)return;var t=e.torrent||{infoHash:e.infoHash,announce:e.announce};var n={rtcConfig:e.rtcConfig,wrtc:e.wrtc};e.tracker=new c(e.peerId,e.port,t,n);f(e.tracker,e,["peer","warning","error"]);e.tracker.start()};u.prototype._dhtLookupAndAnnounce=function(){var e=this;if(e._performedDHTLookup)return;e._performedDHTLookup=true;r("dht lookup");e.dht.lookup(e.infoHash,function(t){if(t||!e.port)return;r("dht announce");e.dht.announce(e.infoHash,e.port,function(){r("dht announce complete");e.emit("dhtAnnounce")})})}}).call(this,e("_process"))},{_process:58,"bittorrent-dht/client":46,"bittorrent-tracker/client":160,debug:191,events:51,inherits:194,"re-emitter":195,"xtend/mutable":196}],160:[function(e,t,n){(function(n,r){t.exports=d;var i=e("debug")("bittorrent-tracker");var a=e("events").EventEmitter;var o=e("inherits");var s=e("once");var f=e("url");var c=e("./lib/common");var u=e("./lib/http-tracker");var l=e("./lib/udp-tracker");var p=e("./lib/websocket-tracker");o(d,a);function d(e,t,o,s){var h=this;if(!(h instanceof d))return new d(e,t,o,s);a.call(h);if(!s)s={};h._peerId=r.isBuffer(e)?e:new r(e,"hex");h._peerIdHex=h._peerId.toString("hex");h._peerIdBinary=h._peerId.toString("binary");h._infoHash=r.isBuffer(o.infoHash)?o.infoHash:new r(o.infoHash,"hex");h._infoHashHex=h._infoHash.toString("hex");h._infoHashBinary=h._infoHash.toString("binary");h._port=t;h.torrentLength=o.length;h._rtcConfig=s.rtcConfig;h._wrtc=s.wrtc;h._numWant=s.numWant||c.DEFAULT_ANNOUNCE_PEERS;h._intervalMs=s.interval||c.DEFAULT_ANNOUNCE_INTERVAL;i("new client %s",h._infoHashHex);var m={interval:h._intervalMs};var v=!!h._wrtc||typeof window!=="undefined";var g=typeof o.announce==="string"?[o.announce]:o.announce==null?[]:o.announce;h._trackers=g.map(function(e){e=e.toString();var t=f.parse(e).protocol;if((t==="http:"||t==="https:")&&typeof u==="function"){return new u(h,e,m)}else if(t==="udp:"&&typeof l==="function"){return new l(h,e,m)}else if((t==="ws:"||t==="wss:")&&v){return new p(h,e,m)}else{n.nextTick(function(){var t=new Error("unsupported tracker protocol for "+e);h.emit("warning",t)})}return null}).filter(Boolean)}d.scrape=function(e,t,n){n=s(n);var i=new r("01234567890123456789");var a=6881;var o={infoHash:Array.isArray(t)?t[0]:t,announce:[e]};var f=new d(i,a,o);f.once("error",n);var c=Array.isArray(t)?t.length:1;var u={};f.on("scrape",function(e){c-=1;u[e.infoHash]=e;if(c===0){f.destroy();var t=Object.keys(u);if(t.length===1){n(null,u[t[0]])}else{n(null,u)}}});t=Array.isArray(t)?t.map(function(e){return new r(e,"hex")}):new r(t,"hex");f.scrape({infoHash:t})};d.prototype.start=function(e){var t=this;i("send `start`");e=t._defaultAnnounceOpts(e);e.event="started";t._announce(e);t._trackers.forEach(function(e){e.setInterval(t._intervalMs)})};d.prototype.stop=function(e){var t=this;i("send `stop`");e=t._defaultAnnounceOpts(e);e.event="stopped";t._announce(e)};d.prototype.complete=function(e){var t=this;i("send `complete`");if(!e)e={};if(e.downloaded==null&&t.torrentLength!=null){e.downloaded=t.torrentLength}e=t._defaultAnnounceOpts(e);e.event="completed";t._announce(e)};d.prototype.update=function(e){var t=this;i("send `update`");e=t._defaultAnnounceOpts(e);if(e.event)delete e.event;t._announce(e)};d.prototype._announce=function(e){var t=this;t._trackers.forEach(function(t){t.announce(e)})};d.prototype.scrape=function(e){var t=this;i("send `scrape`");if(!e)e={};t._trackers.forEach(function(t){t.scrape(e)})};d.prototype.setInterval=function(e){var t=this;i("setInterval");t._intervalMs=e;t._trackers.forEach(function(t){t.setInterval(e)})};d.prototype.destroy=function(){var e=this;i("destroy");e._trackers.forEach(function(e){e.destroy();e.setInterval(0)});e._trackers=[]};d.prototype._defaultAnnounceOpts=function(e){var t=this;if(!e)e={};if(e.numWant==null)e.numWant=t._numWant;if(e.uploaded==null)e.uploaded=0;if(e.downloaded==null)e.downloaded=0;if(e.left==null&&t.torrentLength!=null){e.left=t.torrentLength-e.downloaded}return e}}).call(this,e("_process"),e("buffer").Buffer)},{"./lib/common":162,"./lib/http-tracker":46,"./lib/udp-tracker":46,"./lib/websocket-tracker":163,_process:58,buffer:47,debug:164,events:51,inherits:168,once:170,url:76}],161:[function(e,t,n){(function(t){var r=e("querystring");n.IPV4_RE=/^[\d\.]+$/;n.IPV6_RE=/^[\da-fA-F:]+$/;n.CONNECTION_ID=t.concat([i(1047),i(655366528)]);n.ACTIONS={CONNECT:0,ANNOUNCE:1,SCRAPE:2,ERROR:3};n.EVENTS={update:0,completed:1,started:2,stopped:3};n.EVENT_IDS={0:"update",1:"completed",2:"started",3:"stopped"};n.EVENT_NAMES={update:"update",completed:"complete",started:"start",stopped:"stop"};function i(e){var n=new t(4);n.writeUInt32BE(e,0);return n}n.toUInt32=i;n.querystringParse=function(e){var t=r.unescape;r.unescape=unescape;var n=r.parse(e);r.unescape=t;return n};n.querystringStringify=function(e){var t=r.escape;r.escape=escape;var n=r.stringify(e);n=n.replace(/[\@\*\/\+]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()});r.escape=t;return n}}).call(this,e("buffer").Buffer)},{buffer:47,querystring:62}],162:[function(e,t,n){(function(t){var r=e("xtend/mutable");n.DEFAULT_ANNOUNCE_INTERVAL=30*60*1e3;n.DEFAULT_ANNOUNCE_PEERS=50;n.MAX_ANNOUNCE_PEERS=82;n.binaryToHex=function(e){return new t(e,"binary").toString("hex")};n.hexToBinary=function(e){return new t(e,"hex").toString("binary")};var i=e("./common-node");r(n,i)}).call(this,e("buffer").Buffer)},{"./common-node":161,buffer:47,"xtend/mutable":190}],163:[function(e,t,n){t.exports=d;var r=e("debug")("bittorrent-tracker:websocket-tracker");var i=e("events").EventEmitter;var a=e("hat");var o=e("inherits");var s=e("simple-peer");var f=e("simple-websocket");var c=e("./common");var u={};var l=30*1e3;var p=5*1e3;o(d,i);function d(e,t,n){var a=this;i.call(a);r("new websocket tracker %s",t);a.client=e;a.destroyed=false;a._opts=n;if(t[t.length-1]==="/"){t=t.substring(0,t.length-1)}a._announceUrl=t;a._peers={};a._socket=null;a._intervalMs=a.client._intervalMs;a._interval=null;a._openSocket()}d.prototype.announce=function(e){var t=this;if(t.destroyed)return;if(!t._socket.connected){return t._socket.once("connect",t.announce.bind(t,e))}e.info_hash=t.client._infoHashBinary;e.peer_id=t.client._peerIdBinary;if(e.numWant>10)e.numWant=10;t._generateOffers(e.numWant,function(n){e.offers=n;if(t._trackerId){e.trackerid=t._trackerId}t._send(e)})};d.prototype.scrape=function(e){var t=this;if(t.destroyed)return;t._onSocketError(new Error("scrape not supported "+t._announceUrl))};d.prototype.setInterval=function(e){var t=this;clearInterval(t._interval);t._intervalMs=e;if(e){var n=t.announce.bind(t,t.client._defaultAnnounceOpts());t._interval=setInterval(n,t._intervalMs)}};d.prototype.destroy=function(){var e=this;if(e.destroyed)return;e.destroyed=true;e._socket.removeListener("data",e._onSocketDataBound);e._socket.removeListener("close",e._onSocketCloseBound);e._socket.removeListener("error",e._onSocketErrorBound);e._onSocketErrorBound=null;e._onSocketDataBound=null;e._onSocketCloseBound=null;e._socket.on("error",h);try{e._socket.close()}catch(t){}e._socket=null};d.prototype._openSocket=function(){var e=this;e._onSocketErrorBound=e._onSocketError.bind(e);e._onSocketDataBound=e._onSocketData.bind(e);e._onSocketCloseBound=e._onSocketClose.bind(e);e._socket=u[e._announceUrl];if(!e._socket){e._socket=u[e._announceUrl]=new f(e._announceUrl)}e._socket.on("data",e._onSocketDataBound);e._socket.on("close",e._onSocketCloseBound);e._socket.on("error",e._onSocketErrorBound)};d.prototype._onSocketData=function(e){var t=this;if(t.destroyed)return;if(!(typeof e==="object"&&e!==null)){return t.client.emit("warning",new Error("Invalid tracker response"))}if(e.info_hash!==t.client._infoHashBinary){r("ignoring websocket data from %s for %s (looking for %s: reused socket)",t._announceUrl,c.binaryToHex(e.info_hash),t.client._infoHashHex);return}if(e.peer_id&&e.peer_id===t.client._peerIdBinary){return}r("received %s from %s for %s",JSON.stringify(e),t._announceUrl,t.client._infoHashHex);var n=e["failure reason"];if(n)return t.client.emit("warning",new Error(n));var i=e["warning message"];if(i)t.client.emit("warning",new Error(i));var a=e.interval||e["min interval"];if(a&&!t._opts.interval&&t._intervalMs!==0){t.setInterval(a*1e3)}var o=e["tracker id"];if(o){t._trackerId=o}if(e.complete){t.client.emit("update",{announce:t._announceUrl,complete:e.complete,incomplete:e.incomplete})}var f;if(e.offer&&e.peer_id){f=new s({trickle:false,config:t.client._rtcConfig,wrtc:t.client._wrtc});f.id=c.binaryToHex(e.peer_id);f.once("signal",function(n){var r={info_hash:t.client._infoHashBinary,peer_id:t.client._peerIdBinary,to_peer_id:e.peer_id,answer:n,offer_id:e.offer_id};if(t._trackerId)r.trackerid=t._trackerId;t._send(r)});f.signal(e.offer);t.client.emit("peer",f)}if(e.answer&&e.peer_id){f=t._peers[c.binaryToHex(e.offer_id)];if(f){f.id=c.binaryToHex(e.peer_id);f.signal(e.answer);t.client.emit("peer",f)}else{r("got unexpected answer: "+JSON.stringify(e.answer))}}};d.prototype._onSocketClose=function(){var e=this;if(e.destroyed)return;e.destroy();e._startReconnectTimer()};d.prototype._onSocketError=function(e){var t=this;if(t.destroyed)return;t.destroy();t.client.emit("warning",e);t._startReconnectTimer()};d.prototype._startReconnectTimer=function(){var e=this;var t=Math.floor(Math.random()*l)+p;setTimeout(function(){e.destroyed=false;e._openSocket()},t);r("reconnecting socket in %s ms",t)};d.prototype._send=function(e){var t=this;if(t.destroyed)return;var n=JSON.stringify(e);r("send %s",n);t._socket.send(n)};d.prototype._generateOffers=function(e,t){var n=this;var i=[];r("generating %s offers",e);for(var o=0;or._maxBufferedAmount){r._debug("start backpressure: bufferedAmount %d",r._channel.bufferedAmount);r._cb=n}else{n(null)}}else{r._debug("write before connect");r._chunk=e;r._cb=n}};u.prototype._createOffer=function(){var e=this;if(e.destroyed)return;e._pc.createOffer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,p,e._onError.bind(e));var n=function(){var n=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:n.type,sdp:n.sdp})};if(e.trickle||e._iceComplete)n();else e.once("_iceComplete",n)},e._onError.bind(e),e.offerConstraints)};u.prototype._createAnswer=function(){var e=this;if(e.destroyed)return;e._pc.createAnswer(function(t){if(e.destroyed)return;t.sdp=e.sdpTransform(t.sdp);e._pc.setLocalDescription(t,p,e._onError.bind(e));var n=function(){var n=e._pc.localDescription||t;e._debug("signal");e.emit("signal",{type:n.type,sdp:n.sdp})};if(e.trickle||e._iceComplete)n();else e.once("_iceComplete",n)},e._onError.bind(e),e.answerConstraints)};u.prototype._onIceConnectionStateChange=function(){var e=this;if(e.destroyed)return;var t=e._pc.iceGatheringState;var n=e._pc.iceConnectionState;e._debug("iceConnectionStateChange %s %s",t,n);e.emit("iceConnectionStateChange",t,n);if(n==="connected"||n==="completed"){clearTimeout(e._reconnectTimeout);e._pcReady=true;e._maybeReady()}if(n==="disconnected"){if(e.reconnectTimer){clearTimeout(e._reconnectTimeout);e._reconnectTimeout=setTimeout(function(){e._destroy()},e.reconnectTimer)}else{e._destroy()}}if(n==="closed"){e._destroy()}};u.prototype._maybeReady=function(){var e=this;e._debug("maybeReady pc %s channel %s",e._pcReady,e._channelReady);if(e.connected||e._connecting||!e._pcReady||!e._channelReady)return;e._connecting=true;if(typeof window!=="undefined"&&!!window.mozRTCPeerConnection){e._pc.getStats(null,function(e){var n=[];e.forEach(function(e){n.push(e)});t(n)},e._onError.bind(e))}else{e._pc.getStats(function(e){var n=[];e.result().forEach(function(e){var t={};e.names().forEach(function(n){t[n]=e.stat(n)});t.id=e.id;t.type=e.type;t.timestamp=e.timestamp;n.push(t)});t(n)})}function t(t){t.forEach(function(t){if(t.type==="remotecandidate"){e.remoteAddress=t.ipAddress;e.remoteFamily="IPv4";e.remotePort=Number(t.portNumber);e._debug("connect remote: %s:%s (%s)",e.remoteAddress,e.remotePort,e.remoteFamily)}else if(t.type==="localcandidate"&&t.candidateType==="host"){e.localAddress=t.ipAddress;e.localPort=Number(t.portNumber);e._debug("connect local: %s:%s",e.localAddress,e.localPort)}});e._connecting=false;e.connected=true;if(e._chunk){e.send(e._chunk);e._chunk=null;e._debug('sent chunk from "write before connect"');var n=e._cb;e._cb=null;n(null)}e._interval=setInterval(function(){if(!e._cb||!e._channel||e._channel.bufferedAmount>e._maxBufferedAmount)return;e._debug("ending backpressure: bufferedAmount %d",e._channel.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref();e._debug("connect");e.emit("connect")}};u.prototype._onSignalingStateChange=function(){var e=this;if(e.destroyed)return;e._debug("signalingStateChange %s",e._pc.signalingState);e.emit("signalingStateChange",e._pc.signalingState)};u.prototype._onIceCandidate=function(e){var t=this;if(t.destroyed)return;if(e.candidate&&t.trickle){t.emit("signal",{candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}})}else if(!e.candidate){t._iceComplete=true;t.emit("_iceComplete")}};u.prototype._onChannelMessage=function(e){var t=this;if(t.destroyed)return;var n=e.data;t._debug("read: %d bytes",n.byteLength||n.length);if(n instanceof ArrayBuffer){n=c(new Uint8Array(n));t.push(n)}else{try{n=JSON.parse(n)}catch(r){}t.emit("data",n)}};u.prototype._onChannelOpen=function(){var e=this;if(e.connected||e.destroyed)return;e._debug("on channel open");e._channelReady=true;e._maybeReady()};u.prototype._onChannelClose=function(){var e=this;if(e.destroyed)return;e._debug("on channel close");e._destroy()};u.prototype._onAddStream=function(e){var t=this;if(t.destroyed)return;t._debug("on add stream");t.emit("stream",e.stream)};u.prototype._onError=function(e){var t=this;if(t.destroyed)return;t._debug("error %s",e.message||e);t._destroy(e)};u.prototype._debug=function(){var e=this;var t=[].slice.call(arguments);var n=e.channelName&&e.channelName.substring(0,7);t[0]="["+n+"] "+t[0];r.apply(null,t)};function l(){if(typeof window==="undefined")return null;var e={RTCPeerConnection:window.mozRTCPeerConnection||window.RTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.mozRTCSessionDescription||window.RTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.mozRTCIceCandidate||window.RTCIceCandidate||window.webkitRTCIceCandidate};if(!e.RTCPeerConnection)return null;return e}function p(){}}).call(this,e("buffer").Buffer)},{buffer:47,debug:172,hat:175,inherits:176,"is-typedarray":177,once:179,stream:74,"typedarray-to-buffer":180}],172:[function(e,t,n){arguments[4][117][0].apply(n,arguments)},{"./debug":173,dup:117}],173:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,ms:174}],174:[function(e,t,n){arguments[4][119][0].apply(n,arguments)},{dup:119}],175:[function(e,t,n){arguments[4][124][0].apply(n,arguments)},{dup:124}],176:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],177:[function(e,t,n){t.exports=a;a.strict=o;a.loose=s;var r=Object.prototype.toString;var i={"[object Int8Array]":true,"[object Int16Array]":true,"[object Int32Array]":true,"[object Uint8Array]":true,"[object Uint8ClampedArray]":true,"[object Uint16Array]":true,"[object Uint32Array]":true,"[object Float32Array]":true,"[object Float64Array]":true};function a(e){return o(e)||s(e)}function o(e){return e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array}function s(e){return i[r.call(e)]}},{}],178:[function(e,t,n){arguments[4][31][0].apply(n,arguments)},{dup:31}],179:[function(e,t,n){arguments[4][108][0].apply(n,arguments)},{dup:108,wrappy:178}],180:[function(e,t,n){arguments[4][100][0].apply(n,arguments)},{buffer:47,dup:100,"is-typedarray":181}],181:[function(e,t,n){arguments[4][177][0].apply(n,arguments)},{dup:177}],182:[function(e,t,n){(function(n){t.exports=u;var r=e("debug")("simple-websocket");var i=e("inherits");var a=e("is-typedarray");var o=e("stream");var s=e("typedarray-to-buffer");var f=e("ws");var c=typeof window!=="undefined"?window.WebSocket:f;i(u,o.Duplex);function u(e,t){var n=this;if(!(n instanceof u))return new u(e,t);if(!t)t={};r("new websocket: %s %o",e,t);t.allowHalfOpen=false;if(t.highWaterMark==null)t.highWaterMark=1024*1024;o.Duplex.call(n,t);n.url=e;n.connected=false;n.destroyed=false;n._maxBufferedAmount=t.highWaterMark;n._chunk=null;n._cb=null;n._interval=null;n._ws=new c(n.url);n._ws.binaryType="arraybuffer";n._ws.onopen=n._onOpen.bind(n);n._ws.onmessage=n._onMessage.bind(n);n._ws.onclose=n._onClose.bind(n);n._ws.onerror=n._onError.bind(n);n.on("finish",function(){if(n.connected){setTimeout(function(){n._destroy()},100)}else{n.once("connect",function(){setTimeout(function(){n._destroy()},100)})}})}u.prototype.send=function(e){var t=this;if(!a.strict(e)&&!(e instanceof ArrayBuffer)&&!n.isBuffer(e)&&typeof e!=="string"&&(typeof Blob==="undefined"||!(e instanceof Blob))){e=JSON.stringify(e)}var i=e.length||e.byteLength||e.size;t._ws.send(e);r("write: %d bytes",i)};u.prototype.destroy=function(e){var t=this;t._destroy(null,e)};u.prototype._destroy=function(e,t){var n=this;if(n.destroyed)return;if(t)n.once("close",t);r("destroy (error: %s)",e&&e.message);this.readable=this.writable=false;if(!n._readableState.ended)n.push(null);if(!n._writableState.finished)n.end();n.connected=false;n.destroyed=true;clearInterval(n._interval);n._interval=null;n._chunk=null;n._cb=null;if(n._ws){try{n._ws.close()}catch(e){}n._ws.onopen=null;n._ws.onmessage=null;n._ws.onclose=null;n._ws.onerror=null}n._ws=null;if(e)n.emit("error",e);n.emit("close")};u.prototype._read=function(){};u.prototype._write=function(e,t,n){var i=this;if(i.destroyed)return n(new Error("cannot write after socket is destroyed"));if(i.connected){i.send(e);if(typeof f!=="function"&&i._ws.bufferedAmount>i._maxBufferedAmount){r("start backpressure: bufferedAmount %d",i._ws.bufferedAmount);i._cb=n}else{n(null)}}else{r("write before connect");i._chunk=e;i._cb=n}};u.prototype._onMessage=function(e){var t=this;if(t.destroyed)return;var i=e.data;r("read: %d bytes",i.byteLength||i.length);if(i instanceof ArrayBuffer){i=s(new Uint8Array(i));t.push(i)}else if(n.isBuffer(i)){t.push(i)}else{try{i=JSON.parse(i)}catch(a){}t.emit("data",i)}};u.prototype._onOpen=function(){var e=this;if(e.connected||e.destroyed)return;e.connected=true;if(e._chunk){e.send(e._chunk);e._chunk=null;r('sent chunk from "write before connect"');var t=e._cb;e._cb=null;t(null)}if(typeof f!=="function"){e._interval=setInterval(function(){if(!e._cb||!e._ws||e._ws.bufferedAmount>e._maxBufferedAmount){return}r("ending backpressure: bufferedAmount %d",e._ws.bufferedAmount);var t=e._cb;e._cb=null;t(null)},150);if(e._interval.unref)e._interval.unref()}r("connect");e.emit("connect")};u.prototype._onClose=function(){var e=this;if(e.destroyed)return;r("on close");e._destroy()};u.prototype._onError=function(){var e=this;if(e.destroyed)return;var t=new Error("connection error to "+e.url);r("error: %s",t.message||t);e._destroy(t)}}).call(this,e("buffer").Buffer)},{buffer:47,debug:183,inherits:186,"is-typedarray":187,stream:74,"typedarray-to-buffer":188,ws:46}],183:[function(e,t,n){arguments[4][117][0].apply(n,arguments)},{"./debug":184,dup:117}],184:[function(e,t,n){arguments[4][21][0].apply(n,arguments)},{dup:21,ms:185}],185:[function(e,t,n){arguments[4][119][0].apply(n,arguments)},{dup:119}],186:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],187:[function(e,t,n){arguments[4][177][0].apply(n,arguments)},{dup:177}],188:[function(e,t,n){arguments[4][100][0].apply(n,arguments)},{buffer:47,dup:100,"is-typedarray":189}],189:[function(e,t,n){arguments[4][177][0].apply(n,arguments)},{dup:177}],190:[function(e,t,n){t.exports=r;function r(e){for(var t=1;tf){return this.emit("warning",new Error("Peer gave maliciously large metadata size"))}this._metadataSize=e.metadata_size;this._numPieces=Math.ceil(this._metadataSize/u);this._remainingRejects=this._numPieces*2;if(this._fetching){this._requestPieces()}};t.prototype.onMessage=function(e){var t,n;try{var i=e.toString();var a=i.indexOf("ee")+2;t=r.decode(i.substring(0,a));n=e.slice(a)}catch(o){return}switch(t.msg_type){case 0:this._onRequest(t.piece);break;case 1:this._onData(t.piece,n,t.total_size);break;case 2:this._onReject(t.piece);break}};t.prototype.fetch=function(){if(this._metadataComplete){return}this._fetching=true;if(this._metadataSize){this._requestPieces()}};t.prototype.cancel=function(){this._fetching=false};t.prototype.setMetadata=function(e){if(this._metadataComplete)return true;try{var t=r.decode(e).info;if(t){e=r.encode(t)}}catch(n){}if(this._infoHashHex&&this._infoHashHex!==s.sync(e)){return false}this.cancel();this.metadata=e;this._metadataComplete=true;this._metadataSize=this.metadata.length;this._wire.extendedHandshake.metadata_size=this._metadataSize;this.emit("metadata",r.encode({info:r.decode(this.metadata)}));return true};t.prototype._send=function(e,t){var i=r.encode(e);if(n.isBuffer(t)){i=n.concat([i,t])}this._wire.extended("ut_metadata",i)};t.prototype._request=function(e){this._send({msg_type:0,piece:e})};t.prototype._data=function(e,t,n){var r={msg_type:1,piece:e};if(typeof n==="number"){r.total_size=n}this._send(r,t)};t.prototype._reject=function(e){this._send({msg_type:2,piece:e})};t.prototype._onRequest=function(e){if(!this._metadataComplete){this._reject(e);return}var t=e*u;var n=t+u;if(n>this._metadataSize){n=this._metadataSize}var r=this.metadata.slice(t,n);this._data(e,r,this._metadataSize)};t.prototype._onData=function(e,t,n){if(t.length>u){return}t.copy(this.metadata,e*u);this._bitfield.set(e);this._checkDone()};t.prototype._onReject=function(e){if(this._remainingRejects>0&&this._fetching){this._request(e);this._remainingRejects-=1}else{this.emit("warning",new Error('Peer sent "reject" too much'))}};t.prototype._requestPieces=function(){this.metadata=new n(this._metadataSize);for(var e=0;e0){this._requestPieces()}else{this.emit("warning",new Error("Peer sent invalid metadata"))}};return t}}).call(this,e("buffer").Buffer)},{bencode:199,bitfield:203,buffer:47,events:51,inherits:204,"simple-sha1":205}],199:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{"./lib/decode":200,"./lib/encode":202,dup:15}],200:[function(e,t,n){arguments[4][16][0].apply(n,arguments)},{"./dict":201,buffer:47,dup:16}],201:[function(e,t,n){arguments[4][17][0].apply(n,arguments)},{dup:17}],202:[function(e,t,n){arguments[4][18][0].apply(n,arguments)},{buffer:47,dup:18}],203:[function(e,t,n){arguments[4][10][0].apply(n,arguments)},{buffer:47,dup:10}],204:[function(e,t,n){arguments[4][23][0].apply(n,arguments)},{dup:23}],205:[function(e,t,n){arguments[4][115][0].apply(n,arguments)},{dup:115,rusha:206}],206:[function(e,t,n){arguments[4][116][0].apply(n,arguments)},{dup:116}],207:[function(e,t,n){arguments[4][25][0].apply(n,arguments)},{dup:25}],208:[function(e,t,n){t.exports=function r(e,t,n){if(t===undefined){return function(t,n){return r(e,t,n)}}if(n===undefined)n="0";e-=t.toString().length;if(e>0)return new Array(e+(/\./.test(t)?2:1)).join(n)+t;return t+""}},{}],209:[function(e,t,n){t.exports={name:"webtorrent",description:"Streaming torrent client",version:"0.49.1",author:{name:"Feross Aboukhadijeh",email:"feross@feross.org",url:"http://feross.org/"},bin:{webtorrent:"./bin/cmd.js"},browser:{"./lib/fs-storage":false,"./lib/server":false,"bittorrent-dht/client":false,"load-ip-set":false,ut_pex:false},bugs:{url:"https://github.com/feross/webtorrent/issues"},dependencies:{"addr-to-ip-port":"^1.0.1",bitfield:"^1.0.2","bittorrent-dht":"^3.0.0","bittorrent-swarm":"^5.0.0","block-stream2":"^1.0.0",clivas:"^0.2.0","create-torrent":"^3.4.0",debug:"^2.1.0",dezalgo:"^1.0.1","end-of-stream":"^1.0.0",hat:"0.0.3",inherits:"^2.0.1",inquirer:"^0.8.0","load-ip-set":"^1.0.3",mime:"^1.2.11",minimist:"^1.1.0",mkdirp:"^0.5.0",moment:"^2.8.3",multistream:"^1.4.2","network-address":"^1.0.0",once:"^1.3.1","parse-torrent":"^5.1.0","pretty-bytes":"^2.0.1",pump:"^1.0.0","random-access-file":"^0.3.1","range-parser":"^1.0.2","re-emitter":"^1.0.0",rimraf:"^2.2.5","run-parallel":"^1.0.0","simple-sha1":"^2.0.0",speedometer:"^0.1.2",thunky:"^0.1.0","torrent-discovery":"^3.0.0",uniq:"^1.0.1",ut_metadata:"^2.1.0",ut_pex:"^1.0.1","windows-no-runnable":"0.0.6",xtend:"^4.0.0","zero-fill":"^2.2.0"},devDependencies:{"bittorrent-tracker":"^4.0.0",brfs:"^1.2.0",browserify:"^10.0.0","run-auto":"^1.0.0","simple-get":"^1.0.0",standard:"^4.0.1",tape:"^4.0.0","uglify-js":"^2.4.15",zelda:"^2.0.0",zuul:"^3.0.0"},homepage:"http://webtorrent.io",keywords:["torrent","bittorrent","bittorrent client","streaming","download","webrtc","webrtc data","webtorrent","mad science"],license:"MIT",main:"index.js",optionalDependencies:{"airplay-js":"^0.2.3","chromecast-js":"^0.1.4",nodebmc:"0.0.5"},repository:{type:"git",url:"git://github.com/feross/webtorrent.git"},scripts:{build:"browserify -s WebTorrent -e ./ | uglifyjs -m > webtorrent.min.js","build-debug":"browserify -s WebTorrent -e ./ > webtorrent.debug.js",size:"npm run build && cat webtorrent.min.js | gzip | wc -c",test:"standard && node ./bin/test.js","test-browser":"zuul -- test/basic.js","test-browser-local":"zuul --local -- test/basic.js","test-node":"tape test/*.js"}}},{}]},{},[1])(1)});