Socket
Socket
Sign inDemoInstall

threadedclass

Package Overview
Dependencies
4
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.1 to 1.2.2

8

CHANGELOG.md

@@ -5,2 +5,10 @@ # Changelog

### [1.2.2](https://github.com/nytamin/threadedClass/compare/1.2.1...1.2.2) (2024-04-10)
### Bug Fixes
* don't reply with an error if the child is not available anymore ([981b255](https://github.com/nytamin/threadedClass/commit/981b255c9530465461ac422ca7def1f15d606ca7))
* handle throws in replyError ([c1c9183](https://github.com/nytamin/threadedClass/commit/c1c9183efb5ff57bbde47e2e839b7b05f0bc99eb))
### [1.2.1](https://github.com/nytamin/threadedClass/compare/1.2.0...1.2.1) (2022-12-07)

@@ -7,0 +15,0 @@

2

dist/js/threadedclass-worker.min.js

@@ -1,2 +0,2 @@

!function(){return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){return o(t[s][1][e]||e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}}()({1:[function(e,t,r){(function(t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});const n=e("../shared/lib"),o=e("./worker"),i=(0,n.getWorkerThreads)();function s(e){if(i){if(!i.parentPort)throw Error("WorkerThreads.parentPort not set!");i.parentPort.postMessage(e)}else if(t.send)t.send(e);else{if(!postMessage)throw Error("process.send and postMessage are undefined!");postMessage(e)}}class a extends o.Worker{sendInstanceMessageToParent(e,t,r){const n=Object.assign(Object.assign({},t),{messageType:"instance",cmdId:e.cmdId++,instanceId:e.id});r&&(e.queue[n.cmdId+""]={traceError:new Error("Error when calling callback"),cb:r}),s(n)}sendChildMessageToParent(e,t,r){const n=Object.assign(Object.assign({},t),{messageType:"child",cmdId:e.cmdId++});r&&(e.queue[n.cmdId+""]={traceError:new Error("Error when calling callback"),cb:r}),s(n)}killInstance(e){delete this.instanceHandles[e.id]}}if((0,n.isBrowser)()){const e=new a;onmessage=(t=>{"message"===t.type?e.onMessageFromParent(t.data):console.log("child process: onMessage",t)})}else if(function(){if((0,n.nodeSupportsWorkerThreads)()){const e=(0,n.getWorkerThreads)();if(e&&!e.isMainThread)return!0}return!1}()){if(!i)throw Error("WorkerThreads not available!");{const e=new a;if(console.log=e.log,console.error=e.logError,!i.parentPort)throw Error("WorkerThreads.parentPort not set!");i.parentPort.on("message",t=>{e.onMessageFromParent(t)})}}else{if(!t.send)throw Error("process.send and onmessage are undefined!");{const e=new a;console.log=e.log,console.error=e.logError,t.on("message",t=>{e.onMessageFromParent(t)})}}}).call(this,e("_process"))},{"../shared/lib":3,"./worker":2,_process:9}],2:[function(require,module,exports){(function(process){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Worker=void 0;const isRunning=require("is-running"),lib_1=require("../shared/lib"),sharedApi_1=require("../shared/sharedApi");class Worker{constructor(){this.childHandler={cmdId:0,queue:{}},this.instanceHandles={},this.callbacks={},this.remoteFns={},this.disabledMultithreading=!1,this._parentPid=0,this.log=((...e)=>{this.sendLog(e)}),this.logError=((...e)=>{this.sendLog(["Error",...e])})}onMessageFromParent(e){if("instance"===e.messageType){let t=this.instanceHandles[e.instanceId];if(!t&&e.cmd!==sharedApi_1.Message.To.Instance.CommandType.INIT)return void console.log(`Child process: Unknown instanceId: "${e.instanceId}"`);t||(t={id:e.instanceId,cmdId:0,queue:{},instance:{}});try{this.handleInstanceMessageFromParent(e,t)}catch(r){e.cmdId?this.replyInstanceError(t,e,`Error: ${r.toString()} ${r.stack} thrown in handleInstanceMessageFromParent on instance "${e.instanceId}"`):this.log("Error: "+r.toString(),r.stack)}}else if("child"===e.messageType){let t=this.childHandler;try{this.handleChildMessageFromParent(e,t)}catch(r){e.cmdId?this.replyChildError(t,e,`Error: ${r.toString()} ${r.stack} thrown in handleChildMessageFromParent on child`):this.log("Error: "+r.toString(),r.stack)}}}decodeArgumentsFromParent(e,t){return(0,sharedApi_1.decodeArguments)(()=>e.instance,t,t=>{const r=t.value;return this.remoteFns[r]||(this.remoteFns[r]=((...r)=>{const n=new Error;return new Promise((o,i)=>{const s=t.value;this.sendCallback(e,s,r,(t,r)=>{if(t){const e=(0,lib_1.stripStack)((0,lib_1.getErrorStack)(t),[/[\\/]parent-process[\\/]manager/,/[\\/]eventemitter3[\\/]index/]),r=(n.stack+"").split("\n").slice(2).join("\n");i((0,lib_1.combineErrorStacks)(e,r))}else{const t=r?this.decodeArgumentsFromParent(e,[r]):[r];o(t[0])}})})})),this.remoteFns[r]})}encodeArgumentsToParent(e,t){return(0,sharedApi_1.encodeArguments)(e,this.callbacks,t,this.disabledMultithreading)}replyToInstanceMessage(e,t,r){this.sendInstanceReplyToParent(e,t.cmdId,void 0,r)}replyToChildMessage(e,t,r){this.sendChildReplyToParent(e,t.cmdId,void 0,r)}replyInstanceError(e,t,r){this.sendInstanceReplyToParent(e,t.cmdId,r)}replyChildError(e,t,r){this.sendChildReplyToParent(e,t.cmdId,r)}sendInstanceReplyToParent(e,t,r,n){let o={cmd:sharedApi_1.Message.From.Instance.CommandType.REPLY,replyTo:t,error:r?(r.stack||r).toString():r,reply:n};this.sendInstanceMessageToParent(e,o)}sendChildReplyToParent(e,t,r,n){let o={cmd:sharedApi_1.Message.From.Child.CommandType.REPLY,replyTo:t,error:r?(r.stack||r).toString():r,reply:n};this.sendChildMessageToParent(e,o)}sendLog(e){let t={cmd:sharedApi_1.Message.From.Child.CommandType.LOG,log:e};this.sendChildMessageToParent(this.childHandler,t)}sendCallback(e,t,r,n){let o={cmd:sharedApi_1.Message.From.Instance.CommandType.CALLBACK,callbackId:t,args:r};this.sendInstanceMessageToParent(e,o,n)}getAllProperties(e){let t=[];do{t=t.concat(Object.getOwnPropertyNames(e)),e=Object.getPrototypeOf(e)}while(e);return t}handleInstanceMessageFromParent(m,handle){const instance=handle.instance;if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.INIT){const msg=m;let pModuleClass;this._config=m.config,this._parentPid=m.parentPid,pModuleClass=(0,lib_1.isBrowser)()?new Promise((e,t)=>{let r=new XMLHttpRequest;r.open("GET",msg.modulePath,!0),r.onload=(()=>{r.response?e(r.response):t(Error(`Bad reply from ${msg.modulePath} in instance ${handle.id}`))}),r.send()}).then(bodyString=>{var f=null;let fcn=`\n\t\t\t\t\t\tf = function() {\n\t\t\t\t\t\t\t${bodyString}\n\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\treturn ${msg.exportName}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,moduleClass=eval(fcn)();if(f=f,!moduleClass)throw Error(`${msg.exportName} not found in ${msg.modulePath}`);return moduleClass}):Promise.resolve(require(msg.modulePath)).then(e=>e[msg.exportName]),pModuleClass.then(e=>{if(!e)return Promise.reject("Failed to find class");const t={id:msg.instanceId,cmdId:0,queue:{},instance:null},r=this.decodeArgumentsFromParent(t,msg.args);t.instance=((...t)=>new e(...t)).apply(null,r),this.instanceHandles[t.id]=t;const n=t.instance,o=this.getAllProperties(n),i=[];o.forEach(e=>{if(-1!==["constructor","__defineGetter__","__defineSetter__","hasOwnProperty","__lookupGetter__","__lookupSetter__","isPrototypeOf","propertyIsEnumerable","toString","valueOf","__proto__","toLocaleString"].indexOf(e))return;let t=Object.getOwnPropertyDescriptor(n,e),r=0,o=n.__proto__;for(;!t&&o;)t=Object.getOwnPropertyDescriptor(o,e),r++,o=o.__proto__;t||(t={});let s={inProto:r,enumerable:!!t.enumerable,writable:!!t.writable,get:!!t.get,set:!!t.set,readable:!(t.get||t.get)};"function"==typeof n[e]?i.push({key:e,type:sharedApi_1.InitPropType.FUNCTION,descriptor:s}):i.push({key:e,type:sharedApi_1.InitPropType.VALUE,descriptor:s})}),this.replyToInstanceMessage(t,msg,i)}).catch(e=>{let t=`${(0,lib_1.stripStack)(e.stack||e.toString(),[/onMessageFromParent/,/threadedclass-worker/])}\n executing constructor of instance "${m.instanceId}"`;this.replyInstanceError(handle,msg,t)}),m.config.disableMultithreading||(0,lib_1.nodeSupportsWorkerThreads)()||this.startOrphanMonitoring()}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.PING)this.replyToInstanceMessage(handle,m,null);else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.REPLY){const e=m;let t=handle.queue[e.replyTo+""];if(!t)throw Error(`cmdId "${e.cmdId}" not found in instance ${m.instanceId}!`);e.error?t.cb(e.error):t.cb(null,e.reply),delete handle.queue[e.replyTo+""]}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.FUNCTION){let e=m;const t=this.decodeArgumentsFromParent(handle,e.args);let r;try{r="function"==typeof instance[e.fcn]?instance[e.fcn](...t):instance[e.fcn]}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(t=>{const r=this.encodeArgumentsToParent(instance,[t]);this.replyToInstanceMessage(handle,e,r[0])}).catch(t=>{let r=`${(0,lib_1.stripStack)(t.stack||t.toString(),[/onMessageFromParent/,/threadedclass-worker/])}\n executing function "${e.fcn}" of instance "${m.instanceId}"`;this.replyInstanceError(handle,e,r)})}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.SET){let e=m;const t=this.decodeArgumentsFromParent(handle,[e.value])[0];instance[e.property]=t;const r=this.encodeArgumentsToParent(instance,[t]);this.replyToInstanceMessage(handle,e,r[0])}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.KILL){let e=m;this.killInstance(handle),this.replyToInstanceMessage(handle,e,null)}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.CALLBACK){let e=m,t=this.callbacks[e.callbackId];if(t)try{Promise.resolve(t(...e.args)).then(t=>{const r=this.encodeArgumentsToParent(instance,[t]);this.replyToInstanceMessage(handle,e,r[0])}).catch(t=>{let r=(t.stack||t.toString())+`\n executing callback of instance "${m.instanceId}"`;this.replyInstanceError(handle,e,r)})}catch(t){let r=(t.stack||t.toString())+`\n executing (outer) callback of instance "${m.instanceId}"`;this.replyInstanceError(handle,e,r)}else this.replyInstanceError(handle,e,`Callback "${e.callbackId}" not found on instance "${m.instanceId}"`)}else(0,lib_1.assertNever)(m)}handleChildMessageFromParent(e,t){if(e.cmd===sharedApi_1.Message.To.Child.CommandType.GET_MEM_USAGE){let r=process?process.memoryUsage():window?window.performance.memory:{error:"N/A"};const n=this.encodeArgumentsToParent({},[r])[0];this.replyToChildMessage(t,e,n)}}startOrphanMonitoring(){if(this._config){setInterval(()=>{this._parentPid&&!isRunning(this._parentPid)&&(console.log(`Parent pid ${this._parentPid} missing, exiting process!`),setTimeout(()=>{process.exit(27)},100))},5e3)}}}exports.Worker=Worker}).call(this,require("_process"))},{"../shared/lib":3,"../shared/sharedApi":4,_process:9,"is-running":8}],3:[function(e,t,r){(function(t){"use strict";function n(){return!(t&&t.hasOwnProperty("stdin"))}function o(){try{return e("worker_threads")}catch(e){return null}}Object.defineProperty(r,"__esModule",{value:!0}),r.ArrayMap=r.combineErrorStacks=r.stripStack=r.getErrorStack=r.assertNever=r.getWorkerThreads=r.nodeSupportsWorkerThreads=r.browserSupportsWebWorkers=r.isBrowser=void 0,r.isBrowser=n,r.browserSupportsWebWorkers=function(){return!(!n()||!window.Worker)},r.nodeSupportsWorkerThreads=function(){return!!o()},r.getWorkerThreads=o,r.assertNever=function(e){},r.getErrorStack=function(e){if("object"==typeof e){const t=e.stack;return t||`${e}`}return`${e}`},r.stripStack=function(e,t){if(!e)return e;const r=e.split("\n");let n=-1;for(let e=0;e<r.length;e++){let o=!1;for(const i of t){if(!r[e]||!r[e].match(i)){o=!1;break}-1===n&&(n=e),o=!0,e+=1}if(o)return r.slice(0,n).join("\n")}return e},r.combineErrorStacks=function e(t,...r){if("object"==typeof t){const n=new Error(t.message);return n.stack=e(`${t.stack}`,...r),n}return t+"\n"+r.join("\n")};r.ArrayMap=class extends Map{constructor(){super()}push(e,t){const r=this.get(e);return r?(r.push(t),r.length):(this.set(e,[t]),1)}remove(e,t){let r=!1;const n=this.get(e);if(n){const o=n.indexOf(t);-1!==o&&(n.splice(o,1),r=!0),0===n.length&&this.delete(e)}return r}arraySize(e){var t,r;return null!==(r=null===(t=this.get(e))||void 0===t?void 0:t.length)&&void 0!==r?r:0}get totalSize(){let e=0;for(const t of this.values())e+=t.length;return e}}}).call(this,e("_process"))},{_process:9,worker_threads:void 0}],4:[function(e,t,r){(function(e){"use strict";var t;Object.defineProperty(r,"__esModule",{value:!0}),r.decodeArguments=r.encodeArguments=r.Message=r.InitPropType=r.DEFAULT_AUTO_RESTART_RETRY_DELAY=r.DEFAULT_AUTO_RESTART_RETRY_COUNT=r.DEFAULT_KILL_TIMEOUT=r.DEFAULT_RESTART_TIMEOUT=r.DEFAULT_CHILD_FREEZE_TIME=void 0,r.DEFAULT_CHILD_FREEZE_TIME=1e3,r.DEFAULT_RESTART_TIMEOUT=1e3,r.DEFAULT_KILL_TIMEOUT=1e3,r.DEFAULT_AUTO_RESTART_RETRY_COUNT=1,r.DEFAULT_AUTO_RESTART_RETRY_DELAY=1e3,function(e){e.FUNCTION="function",e.VALUE="value"}(r.InitPropType||(r.InitPropType={})),function(e){let t,r;!function(e){let t,r;!function(e){let t;!function(e){e.INIT="init",e.PING="ping",e.FUNCTION="fcn",e.REPLY="reply",e.SET="set",e.KILL="kill",e.CALLBACK="callback"}(t=e.CommandType||(e.CommandType={}))}(t=e.Instance||(e.Instance={})),function(e){let t;!function(e){e.GET_MEM_USAGE="get_mem_usage",e.REPLY="reply"}(t=e.CommandType||(e.CommandType={}))}(r=e.Child||(e.Child={}))}(t=e.To||(e.To={})),function(e){let t,r;!function(e){let t;!function(e){e.CALLBACK="callback",e.REPLY="reply"}(t=e.CommandType||(e.CommandType={}))}(t=e.Instance||(e.Instance={})),function(e){let t;!function(e){e.LOG="log",e.REPLY="reply",e.CALLBACK="callback"}(t=e.CommandType||(e.CommandType={}))}(r=e.Child||(e.Child={}))}(r=e.From||(e.From={}))}(r.Message||(r.Message={})),function(e){e.STRING="string",e.NUMBER="number",e.UNDEFINED="undefined",e.NULL="null",e.OBJECT="object",e.FUNCTION="function",e.BUFFER="buffer",e.OTHER="other"}(t||(t={}));let n=0;r.encodeArguments=function(r,o,i,s){try{return i.map((i,a)=>{try{if("object"==typeof i&&i===r)return{type:t.OBJECT,value:"self"};if(s){if(i instanceof e)return{type:t.BUFFER,original:i,value:null};if("object"==typeof i)return{type:t.OBJECT,original:i,value:null}}if(i instanceof e)return{type:t.BUFFER,value:i.toString("hex")};if("string"==typeof i)return{type:t.STRING,value:i};if("number"==typeof i)return{type:t.NUMBER,value:i};if("function"==typeof i){for(const e in o)if(o[e]===i)return{type:t.FUNCTION,value:e+""};const e=n++;return o[e+""]=i,{type:t.FUNCTION,value:e+""}}return void 0===i?{type:t.UNDEFINED,value:i}:null===i?{type:t.NULL,value:i}:"object"==typeof i?{type:t.OBJECT,value:i}:{type:t.OTHER,value:i}}catch(e){throw e.stack&&(e.stack+="\nIn encodeArguments, argument "+a),e}})}catch(e){throw e.stack&&(e.stack+="\nThreadedClass, unsupported attribute"),e}},r.decodeArguments=function(r,n,o){return n.map(n=>void 0!==n.original?n.original:n.type===t.STRING?n.value:n.type===t.NUMBER?n.value:n.type===t.BUFFER?e.from(n.value,"hex"):n.type===t.UNDEFINED?n.value:n.type===t.NULL?n.value:n.type===t.FUNCTION?o(n):n.type===t.OBJECT&&"self"===n.value?r():n.value)}}).call(this,e("buffer").Buffer)},{buffer:6}],5:[function(e,t,r){"use strict";r.byteLength=function(e){var t=f(e),r=t[0],n=t[1];return 3*(r+n)/4-n},r.toByteArray=function(e){var t,r,n=f(e),s=n[0],a=n[1],u=new i(function(e,t,r){return 3*(t+r)/4-r}(0,s,a)),c=0,h=a>0?s-4:s;for(r=0;r<h;r+=4)t=o[e.charCodeAt(r)]<<18|o[e.charCodeAt(r+1)]<<12|o[e.charCodeAt(r+2)]<<6|o[e.charCodeAt(r+3)],u[c++]=t>>16&255,u[c++]=t>>8&255,u[c++]=255&t;2===a&&(t=o[e.charCodeAt(r)]<<2|o[e.charCodeAt(r+1)]>>4,u[c++]=255&t);1===a&&(t=o[e.charCodeAt(r)]<<10|o[e.charCodeAt(r+1)]<<4|o[e.charCodeAt(r+2)]>>2,u[c++]=t>>8&255,u[c++]=255&t);return u},r.fromByteArray=function(e){for(var t,r=e.length,o=r%3,i=[],s=0,a=r-o;s<a;s+=16383)i.push(c(e,s,s+16383>a?a:s+16383));1===o?(t=e[r-1],i.push(n[t>>2]+n[t<<4&63]+"==")):2===o&&(t=(e[r-2]<<8)+e[r-1],i.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function f(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function c(e,t,r){for(var o,i,s=[],a=t;a<r;a+=3)o=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],6:[function(e,t,r){(function(t){"use strict";var n=e("base64-js"),o=e("ieee754");r.Buffer=t,r.SlowBuffer=function(e){+e!=e&&(e=0);return t.alloc(+e)},r.INSPECT_MAX_BYTES=50;var i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');var r=new Uint8Array(e);return r.__proto__=t.prototype,r}function t(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,r,n){if("string"==typeof e)return function(e,r){"string"==typeof r&&""!==r||(r="utf8");if(!t.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var n=0|l(e,r),o=s(n),i=o.write(e,r);i!==n&&(o=o.slice(0,i));return o}(e,r);if(ArrayBuffer.isView(e))return c(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(j(e,ArrayBuffer)||e&&j(e.buffer,ArrayBuffer))return function(e,r,n){if(r<0||e.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<r+(n||0))throw new RangeError('"length" is outside of buffer bounds');var o;o=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);return o.__proto__=t.prototype,o}(e,r,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var o=e.valueOf&&e.valueOf();if(null!=o&&o!==e)return t.from(o,r,n);var i=function(e){if(t.isBuffer(e)){var r=0|h(e.length),n=s(r);return 0===n.length?n:(e.copy(n,0,0,r),n)}if(void 0!==e.length)return"number"!=typeof e.length||D(e.length)?s(0):c(e);if("Buffer"===e.type&&Array.isArray(e.data))return c(e.data)}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return t.from(e[Symbol.toPrimitive]("string"),r,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function u(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return u(e),s(e<0?0:0|h(e))}function c(e){for(var t=e.length<0?0:0|h(e.length),r=s(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function h(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function l(e,r){if(t.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||j(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var n=e.length,o=arguments.length>2&&!0===arguments[2];if(!o&&0===n)return 0;for(var i=!1;;)switch(r){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return F(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return N(e).length;default:if(i)return o?-1:F(e).length;r=(""+r).toLowerCase(),i=!0}}function p(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function d(e,r,n,o,i){if(0===e.length)return-1;if("string"==typeof n?(o=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),D(n=+n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof r&&(r=t.from(r,o)),t.isBuffer(r))return 0===r.length?-1:g(e,r,n,o,i);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,r,n):Uint8Array.prototype.lastIndexOf.call(e,r,n):g(e,[r],n,o,i);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){var i,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function f(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){var c=-1;for(i=r;i<a;i++)if(f(e,i)===f(t,-1===c?0:i-c)){if(-1===c&&(c=i),i-c+1===u)return c*s}else-1!==c&&(i-=i-c),c=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){for(var h=!0,l=0;l<u;l++)if(f(e,i+l)!==f(t,l)){h=!1;break}if(h)return i}return-1}function y(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(D(a))return s;e[r+s]=a}return s}function m(e,t,r,n){return x(F(t,e.length-r),e,r,n)}function w(e,t,r,n){return x(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function T(e,t,r,n){return w(e,t,r,n)}function E(e,t,r,n){return x(N(t),e,r,n)}function b(e,t,r,n){return x(function(e,t){for(var r,n,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function v(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function _(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var i,s,a,u,f=e[o],c=null,h=f>239?4:f>223?3:f>191?2:1;if(o+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(i=e[o+1]))&&(u=(31&f)<<6|63&i)>127&&(c=u);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&(u=(15&f)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:i=e[o+1],s=e[o+2],a=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&f)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),o+=h}return function(e){var t=e.length;if(t<=I)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=I));return r}(n)}r.kMaxLength=i,t.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),t.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(t.prototype,"parent",{enumerable:!0,get:function(){if(t.isBuffer(this))return this.buffer}}),Object.defineProperty(t.prototype,"offset",{enumerable:!0,get:function(){if(t.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&t[Symbol.species]===t&&Object.defineProperty(t,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),t.poolSize=8192,t.from=function(e,t,r){return a(e,t,r)},t.prototype.__proto__=Uint8Array.prototype,t.__proto__=Uint8Array,t.alloc=function(e,t,r){return function(e,t,r){return u(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},t.allocUnsafe=function(e){return f(e)},t.allocUnsafeSlow=function(e){return f(e)},t.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==t.prototype},t.compare=function(e,r){if(j(e,Uint8Array)&&(e=t.from(e,e.offset,e.byteLength)),j(r,Uint8Array)&&(r=t.from(r,r.offset,r.byteLength)),!t.isBuffer(e)||!t.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var n=e.length,o=r.length,i=0,s=Math.min(n,o);i<s;++i)if(e[i]!==r[i]){n=e[i],o=r[i];break}return n<o?-1:o<n?1:0},t.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},t.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return t.alloc(0);var n;if(void 0===r)for(r=0,n=0;n<e.length;++n)r+=e[n].length;var o=t.allocUnsafe(r),i=0;for(n=0;n<e.length;++n){var s=e[n];if(j(s,Uint8Array)&&(s=t.from(s)),!t.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(o,i),i+=s.length}return o},t.byteLength=l,t.prototype._isBuffer=!0,t.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)p(this,t,t+1);return this},t.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)p(this,t,t+3),p(this,t+1,t+2);return this},t.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)p(this,t,t+7),p(this,t+1,t+6),p(this,t+2,t+5),p(this,t+3,t+4);return this},t.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?_(this,0,e):function(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return M(this,t,r);case"utf8":case"utf-8":return _(this,t,r);case"ascii":return A(this,t,r);case"latin1":case"binary":return C(this,t,r);case"base64":return v(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}.apply(this,arguments)},t.prototype.toLocaleString=t.prototype.toString,t.prototype.equals=function(e){if(!t.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===t.compare(this,e)},t.prototype.inspect=function(){var e="",t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},t.prototype.compare=function(e,r,n,o,i){if(j(e,Uint8Array)&&(e=t.from(e,e.offset,e.byteLength)),!t.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===r&&(r=0),void 0===n&&(n=e?e.length:0),void 0===o&&(o=0),void 0===i&&(i=this.length),r<0||n>e.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&r>=n)return 0;if(o>=i)return-1;if(r>=n)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(o>>>=0),a=(n>>>=0)-(r>>>=0),u=Math.min(s,a),f=this.slice(o,i),c=e.slice(r,n),h=0;h<u;++h)if(f[h]!==c[h]){s=f[h],a=c[h];break}return s<a?-1:a<s?1:0},t.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},t.prototype.indexOf=function(e,t,r){return d(this,e,t,r,!0)},t.prototype.lastIndexOf=function(e,t,r){return d(this,e,t,r,!1)},t.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return y(this,e,t,r);case"utf8":case"utf-8":return m(this,e,t,r);case"ascii":return w(this,e,t,r);case"latin1":case"binary":return T(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},t.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var I=4096;function A(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function C(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function M(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=t;i<r;++i)o+=O(e[i]);return o}function P(e,t,r){for(var n=e.slice(t,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function k(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function U(e,r,n,o,i,s){if(!t.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<s)throw new RangeError('"value" argument is out of bounds');if(n+o>e.length)throw new RangeError("Index out of range")}function B(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,t,r,n,i){return t=+t,r>>>=0,i||B(e,0,r,4),o.write(e,t,r,n,23,4),r+4}function S(e,t,r,n,i){return t=+t,r>>>=0,i||B(e,0,r,8),o.write(e,t,r,n,52,8),r+8}t.prototype.slice=function(e,r){var n=this.length;(e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<e&&(r=e);var o=this.subarray(e,r);return o.__proto__=t.prototype,o},t.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},t.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},t.prototype.readUInt8=function(e,t){return e>>>=0,t||k(e,1,this.length),this[e]},t.prototype.readUInt16LE=function(e,t){return e>>>=0,t||k(e,2,this.length),this[e]|this[e+1]<<8},t.prototype.readUInt16BE=function(e,t){return e>>>=0,t||k(e,2,this.length),this[e]<<8|this[e+1]},t.prototype.readUInt32LE=function(e,t){return e>>>=0,t||k(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},t.prototype.readUInt32BE=function(e,t){return e>>>=0,t||k(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},t.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},t.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=t,o=1,i=this[e+--n];n>0&&(o*=256);)i+=this[e+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},t.prototype.readInt8=function(e,t){return e>>>=0,t||k(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},t.prototype.readInt16LE=function(e,t){e>>>=0,t||k(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},t.prototype.readInt16BE=function(e,t){e>>>=0,t||k(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},t.prototype.readInt32LE=function(e,t){return e>>>=0,t||k(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},t.prototype.readInt32BE=function(e,t){return e>>>=0,t||k(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},t.prototype.readFloatLE=function(e,t){return e>>>=0,t||k(e,4,this.length),o.read(this,e,!0,23,4)},t.prototype.readFloatBE=function(e,t){return e>>>=0,t||k(e,4,this.length),o.read(this,e,!1,23,4)},t.prototype.readDoubleLE=function(e,t){return e>>>=0,t||k(e,8,this.length),o.read(this,e,!0,52,8)},t.prototype.readDoubleBE=function(e,t){return e>>>=0,t||k(e,8,this.length),o.read(this,e,!1,52,8)},t.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||U(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},t.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||U(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},t.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,255,0),this[t]=255&e,t+1},t.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},t.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},t.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},t.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},t.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);U(this,e,t,r,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},t.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);U(this,e,t,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},t.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},t.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},t.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},t.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},t.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},t.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},t.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},t.prototype.writeDoubleLE=function(e,t,r){return S(this,e,t,!0,r)},t.prototype.writeDoubleBE=function(e,t,r){return S(this,e,t,!1,r)},t.prototype.copy=function(e,r,n,o){if(!t.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),o||0===o||(o=this.length),r>=e.length&&(r=e.length),r||(r=0),o>0&&o<n&&(o=n),o===n)return 0;if(0===e.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-r<o-n&&(o=e.length-r+n);var i=o-n;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(r,n,o);else if(this===e&&n<r&&r<o)for(var s=i-1;s>=0;--s)e[s+r]=this[s+n];else Uint8Array.prototype.set.call(e,this.subarray(n,o),r);return i},t.prototype.fill=function(e,r,n,o){if("string"==typeof e){if("string"==typeof r?(o=r,r=0,n=this.length):"string"==typeof n&&(o=n,n=this.length),void 0!==o&&"string"!=typeof o)throw new TypeError("encoding must be a string");if("string"==typeof o&&!t.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(1===e.length){var i=e.charCodeAt(0);("utf8"===o&&i<128||"latin1"===o)&&(e=i)}}else"number"==typeof e&&(e&=255);if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;var s;if(r>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=r;s<n;++s)this[s]=e;else{var a=t.isBuffer(e)?e:t.from(e,o),u=a.length;if(0===u)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=a[s%u]}return this};var R=/[^+/0-9A-Za-z-_]/g;function O(e){return e<16?"0"+e.toString(16):e.toString(16)}function F(e,t){var r;t=t||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function N(e){return n.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(R,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function x(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function j(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function D(e){return e!=e}}).call(this,e("buffer").Buffer)},{"base64-js":5,buffer:6,ieee754:7}],7:[function(e,t,r){r.read=function(e,t,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,f=u>>1,c=-7,h=r?o-1:0,l=r?-1:1,p=e[t+h];for(h+=l,i=p&(1<<-c)-1,p>>=-c,c+=a;c>0;i=256*i+e[t+h],h+=l,c-=8);for(s=i&(1<<-c)-1,i>>=-c,c+=n;c>0;s=256*s+e[t+h],h+=l,c-=8);if(0===i)i=1-f;else{if(i===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=f}return(p?-1:1)*s*Math.pow(2,i-n)},r.write=function(e,t,r,n,o,i){var s,a,u,f=8*i-o-1,c=(1<<f)-1,h=c>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+h>=1?l/u:l*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=c?(a=0,s=c):s+h>=1?(a=(t*u-1)*Math.pow(2,o),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,o),s=0));o>=8;e[r+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,f+=o;f>0;e[r+p]=255&s,p+=d,s/=256,f-=8);e[r+p-d]|=128*g}},{}],8:[function(e,t,r){(function(e){t.exports=function(r){if(t.exports.stub!==t.exports)return t.exports.stub.apply(this,arguments);try{return e.kill(r,0)}catch(e){return"EPERM"===e.code}},t.exports.stub=t.exports}).call(this,e("_process"))},{_process:9}],9:[function(e,t,r){var n,o,i=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(e){n=s}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(e){o=a}}();var f,c=[],h=!1,l=-1;function p(){h&&f&&(h=!1,f.length?c=f.concat(c):l=-1,c.length&&d())}function d(){if(!h){var e=u(p);h=!0;for(var t=c.length;t;){for(f=c,c=[];++l<t;)f&&f[l].run();l=-1,t=c.length}f=null,h=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function y(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];c.push(new g(e,t)),1!==c.length||h||u(d)},g.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}]},{},[1]);
!function(){return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=r[s]={exports:{}};t[s][0].call(c.exports,function(e){return o(t[s][1][e]||e)},c,c.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}}()({1:[function(e,t,r){(function(t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});const n=e("../shared/lib"),o=e("./worker"),i=(0,n.getWorkerThreads)();function s(e){if(i){if(!i.parentPort)throw Error("WorkerThreads.parentPort not set!");i.parentPort.postMessage(e)}else if(t.send)t.send(e);else{if(!postMessage)throw Error("process.send and postMessage are undefined!");postMessage(e)}}class a extends o.Worker{sendInstanceMessageToParent(e,t,r){const n=Object.assign(Object.assign({},t),{messageType:"instance",cmdId:e.cmdId++,instanceId:e.id});r&&(e.queue[n.cmdId+""]={traceError:new Error("Error when calling callback"),cb:r}),s(n)}sendChildMessageToParent(e,t,r){const n=Object.assign(Object.assign({},t),{messageType:"child",cmdId:e.cmdId++});r&&(e.queue[n.cmdId+""]={traceError:new Error("Error when calling callback"),cb:r}),s(n)}killInstance(e){delete this.instanceHandles[e.id]}}if((0,n.isBrowser)()){const e=new a;onmessage=(t=>{"message"===t.type?e.onMessageFromParent(t.data):console.log("child process: onMessage",t)})}else if(function(){if((0,n.nodeSupportsWorkerThreads)()){const e=(0,n.getWorkerThreads)();if(e&&!e.isMainThread)return!0}return!1}()){if(!i)throw Error("WorkerThreads not available!");{const e=new a;if(console.log=e.log,console.error=e.logError,!i.parentPort)throw Error("WorkerThreads.parentPort not set!");i.parentPort.on("message",t=>{e.onMessageFromParent(t)})}}else{if(!t.send)throw Error("process.send and onmessage are undefined!");{const e=new a;console.log=e.log,console.error=e.logError,t.on("message",t=>{e.onMessageFromParent(t)})}}}).call(this,e("_process"))},{"../shared/lib":3,"./worker":2,_process:9}],2:[function(require,module,exports){(function(process){"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Worker=void 0;const isRunning=require("is-running"),lib_1=require("../shared/lib"),sharedApi_1=require("../shared/sharedApi");class Worker{constructor(){this.childHandler={cmdId:0,queue:{}},this.instanceHandles={},this.callbacks={},this.remoteFns={},this.disabledMultithreading=!1,this._parentPid=0,this.log=((...e)=>{this.sendLog(e)}),this.logError=((...e)=>{this.sendLog(["Error",...e])})}onMessageFromParent(e){if("instance"===e.messageType){let t=this.instanceHandles[e.instanceId];if(!t&&e.cmd!==sharedApi_1.Message.To.Instance.CommandType.INIT)return void console.log(`Child process: Unknown instanceId: "${e.instanceId}"`);t||(t={id:e.instanceId,cmdId:0,queue:{},instance:{}});try{this.handleInstanceMessageFromParent(e,t)}catch(r){e.cmdId?this.replyInstanceError(t,e,`Error: ${r.toString()} ${r.stack} thrown in handleInstanceMessageFromParent on instance "${e.instanceId}"`):this.log("Error: "+r.toString(),r.stack)}}else if("child"===e.messageType){let t=this.childHandler;try{this.handleChildMessageFromParent(e,t)}catch(r){e.cmdId?this.replyChildError(t,e,`Error: ${r.toString()} ${r.stack} thrown in handleChildMessageFromParent on child`):this.log("Error: "+r.toString(),r.stack)}}}decodeArgumentsFromParent(e,t){return(0,sharedApi_1.decodeArguments)(()=>e.instance,t,t=>{const r=t.value;return this.remoteFns[r]||(this.remoteFns[r]=((...r)=>{const n=new Error;return new Promise((o,i)=>{const s=t.value;this.sendCallback(e,s,r,(t,r)=>{if(t){const e=(0,lib_1.stripStack)((0,lib_1.getErrorStack)(t),[/[\\/]parent-process[\\/]manager/,/[\\/]eventemitter3[\\/]index/]),r=(n.stack+"").split("\n").slice(2).join("\n");i((0,lib_1.combineErrorStacks)(e,r))}else{const t=r?this.decodeArgumentsFromParent(e,[r]):[r];o(t[0])}})})})),this.remoteFns[r]})}encodeArgumentsToParent(e,t){return(0,sharedApi_1.encodeArguments)(e,this.callbacks,t,this.disabledMultithreading)}replyToInstanceMessage(e,t,r){this.sendInstanceReplyToParent(e,t.cmdId,void 0,r)}replyToChildMessage(e,t,r){this.sendChildReplyToParent(e,t.cmdId,void 0,r)}replyInstanceError(e,t,r){this.sendInstanceReplyToParent(e,t.cmdId,r)}replyChildError(e,t,r){this.sendChildReplyToParent(e,t.cmdId,r)}sendInstanceReplyToParent(e,t,r,n){let o={cmd:sharedApi_1.Message.From.Instance.CommandType.REPLY,replyTo:t,error:r?(r.stack||r).toString():r,reply:n};this.sendInstanceMessageToParent(e,o)}sendChildReplyToParent(e,t,r,n){let o={cmd:sharedApi_1.Message.From.Child.CommandType.REPLY,replyTo:t,error:r?(r.stack||r).toString():r,reply:n};this.sendChildMessageToParent(e,o)}sendLog(e){let t={cmd:sharedApi_1.Message.From.Child.CommandType.LOG,log:e};this.sendChildMessageToParent(this.childHandler,t)}sendCallback(e,t,r,n){let o={cmd:sharedApi_1.Message.From.Instance.CommandType.CALLBACK,callbackId:t,args:r};this.sendInstanceMessageToParent(e,o,n)}getAllProperties(e){let t=[];do{t=t.concat(Object.getOwnPropertyNames(e)),e=Object.getPrototypeOf(e)}while(e);return t}handleInstanceMessageFromParent(m,handle){const instance=handle.instance;if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.INIT){const msg=m;let pModuleClass;this._config=m.config,this._parentPid=m.parentPid,pModuleClass=(0,lib_1.isBrowser)()?new Promise((e,t)=>{let r=new XMLHttpRequest;r.open("GET",msg.modulePath,!0),r.onload=(()=>{r.response?e(r.response):t(Error(`Bad reply from ${msg.modulePath} in instance ${handle.id}`))}),r.send()}).then(bodyString=>{var f=null;let fcn=`\n\t\t\t\t\t\tf = function() {\n\t\t\t\t\t\t\t${bodyString}\n\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\treturn ${msg.exportName}\n\t\t\t\t\t\t}\n\t\t\t\t\t`,moduleClass=eval(fcn)();if(f=f,!moduleClass)throw Error(`${msg.exportName} not found in ${msg.modulePath}`);return moduleClass}):Promise.resolve(require(msg.modulePath)).then(e=>e[msg.exportName]),pModuleClass.then(e=>{if(!e)return Promise.reject("Failed to find class");const t={id:msg.instanceId,cmdId:0,queue:{},instance:null},r=this.decodeArgumentsFromParent(t,msg.args);t.instance=((...t)=>new e(...t)).apply(null,r),this.instanceHandles[t.id]=t;const n=t.instance,o=this.getAllProperties(n),i=[];o.forEach(e=>{if(-1!==["constructor","__defineGetter__","__defineSetter__","hasOwnProperty","__lookupGetter__","__lookupSetter__","isPrototypeOf","propertyIsEnumerable","toString","valueOf","__proto__","toLocaleString"].indexOf(e))return;let t=Object.getOwnPropertyDescriptor(n,e),r=0,o=n.__proto__;for(;!t&&o;)t=Object.getOwnPropertyDescriptor(o,e),r++,o=o.__proto__;t||(t={});let s={inProto:r,enumerable:!!t.enumerable,writable:!!t.writable,get:!!t.get,set:!!t.set,readable:!(t.get||t.get)};"function"==typeof n[e]?i.push({key:e,type:sharedApi_1.InitPropType.FUNCTION,descriptor:s}):i.push({key:e,type:sharedApi_1.InitPropType.VALUE,descriptor:s})}),this.replyToInstanceMessage(t,msg,i)}).catch(e=>{let t=`${(0,lib_1.stripStack)(e.stack||e.toString(),[/onMessageFromParent/,/threadedclass-worker/])}\n executing constructor of instance "${m.instanceId}"`;this.replyInstanceError(handle,msg,t)}),m.config.disableMultithreading||(0,lib_1.nodeSupportsWorkerThreads)()||this.startOrphanMonitoring()}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.PING)this.replyToInstanceMessage(handle,m,null);else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.REPLY){const e=m;let t=handle.queue[e.replyTo+""];if(!t)throw Error(`cmdId "${e.cmdId}" not found in instance ${m.instanceId}!`);e.error?t.cb(e.error):t.cb(null,e.reply),delete handle.queue[e.replyTo+""]}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.FUNCTION){let e=m;const t=this.decodeArgumentsFromParent(handle,e.args);let r;try{r="function"==typeof instance[e.fcn]?instance[e.fcn](...t):instance[e.fcn]}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(t=>{const r=this.encodeArgumentsToParent(instance,[t]);this.replyToInstanceMessage(handle,e,r[0])}).catch(t=>{let r=`${(0,lib_1.stripStack)(t.stack||t.toString(),[/onMessageFromParent/,/threadedclass-worker/])}\n executing function "${e.fcn}" of instance "${m.instanceId}"`;this.replyInstanceError(handle,e,r)})}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.SET){let e=m;const t=this.decodeArgumentsFromParent(handle,[e.value])[0];instance[e.property]=t;const r=this.encodeArgumentsToParent(instance,[t]);this.replyToInstanceMessage(handle,e,r[0])}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.KILL){let e=m;this.killInstance(handle),this.replyToInstanceMessage(handle,e,null)}else if(m.cmd===sharedApi_1.Message.To.Instance.CommandType.CALLBACK){let e=m,t=this.callbacks[e.callbackId];if(t)try{Promise.resolve(t(...e.args)).then(t=>{const r=this.encodeArgumentsToParent(instance,[t]);this.replyToInstanceMessage(handle,e,r[0])}).catch(t=>{let r=(t.stack||t.toString())+`\n executing callback of instance "${m.instanceId}"`;this.replyInstanceError(handle,e,r)})}catch(t){let r=(t.stack||t.toString())+`\n executing (outer) callback of instance "${m.instanceId}"`;this.replyInstanceError(handle,e,r)}else this.replyInstanceError(handle,e,`Callback "${e.callbackId}" not found on instance "${m.instanceId}"`)}else(0,lib_1.assertNever)(m)}handleChildMessageFromParent(e,t){if(e.cmd===sharedApi_1.Message.To.Child.CommandType.GET_MEM_USAGE){let r=process?process.memoryUsage():window?window.performance.memory:{error:"N/A"};const n=this.encodeArgumentsToParent({},[r])[0];this.replyToChildMessage(t,e,n)}}startOrphanMonitoring(){if(this._config){setInterval(()=>{this._parentPid&&!isRunning(this._parentPid)&&(console.log(`Parent pid ${this._parentPid} missing, exiting process!`),setTimeout(()=>{process.exit(27)},100))},5e3)}}}exports.Worker=Worker}).call(this,require("_process"))},{"../shared/lib":3,"../shared/sharedApi":4,_process:9,"is-running":8}],3:[function(e,t,r){(function(t){"use strict";function n(){return!(t&&t.hasOwnProperty("stdin"))}function o(){try{return e("worker_threads")}catch(e){return null}}Object.defineProperty(r,"__esModule",{value:!0}),r.ArrayMap=r.combineErrorStacks=r.stripStack=r.getErrorStack=r.assertNever=r.getWorkerThreads=r.nodeSupportsWorkerThreads=r.browserSupportsWebWorkers=r.isBrowser=void 0,r.isBrowser=n,r.browserSupportsWebWorkers=function(){return!(!n()||!window.Worker)},r.nodeSupportsWorkerThreads=function(){return!!o()},r.getWorkerThreads=o,r.assertNever=function(e){},r.getErrorStack=function(e){if("object"==typeof e){const t=e.stack;return t||`${e}`}return`${e}`},r.stripStack=function(e,t){if(!e)return e;const r=e.split("\n");let n=-1;for(let e=0;e<r.length;e++){let o=!1;for(const i of t){if(!r[e]||!r[e].match(i)){o=!1;break}-1===n&&(n=e),o=!0,e+=1}if(o)return r.slice(0,n).join("\n")}return e},r.combineErrorStacks=function e(t,...r){if("object"==typeof t){const n=new Error(t.message);return n.stack=e(`${t.stack}`,...r),n}return t+"\n"+r.join("\n")};r.ArrayMap=class extends Map{constructor(){super()}push(e,t){const r=this.get(e);return r?(r.push(t),r.length):(this.set(e,[t]),1)}remove(e,t){let r=!1;const n=this.get(e);if(n){const o=n.indexOf(t);-1!==o&&(n.splice(o,1),r=!0),0===n.length&&this.delete(e)}return r}arraySize(e){var t,r;return null!==(r=null===(t=this.get(e))||void 0===t?void 0:t.length)&&void 0!==r?r:0}get totalSize(){let e=0;for(const t of this.values())e+=t.length;return e}}}).call(this,e("_process"))},{_process:9,worker_threads:void 0}],4:[function(e,t,r){(function(e){"use strict";var t;Object.defineProperty(r,"__esModule",{value:!0}),r.decodeArguments=r.encodeArguments=r.Message=r.InitPropType=r.DEFAULT_AUTO_RESTART_RETRY_DELAY=r.DEFAULT_AUTO_RESTART_RETRY_COUNT=r.DEFAULT_KILL_TIMEOUT=r.DEFAULT_RESTART_TIMEOUT=r.DEFAULT_CHILD_FREEZE_TIME=void 0,r.DEFAULT_CHILD_FREEZE_TIME=1e3,r.DEFAULT_RESTART_TIMEOUT=1e3,r.DEFAULT_KILL_TIMEOUT=1e3,r.DEFAULT_AUTO_RESTART_RETRY_COUNT=1,r.DEFAULT_AUTO_RESTART_RETRY_DELAY=1e3,function(e){e.FUNCTION="function",e.VALUE="value"}(r.InitPropType||(r.InitPropType={})),function(e){let t,r;!function(e){let t,r;!function(e){let t;!function(e){e.INIT="init",e.PING="ping",e.FUNCTION="fcn",e.REPLY="reply",e.SET="set",e.KILL="kill",e.CALLBACK="callback"}(t=e.CommandType||(e.CommandType={}))}(t=e.Instance||(e.Instance={})),function(e){let t;!function(e){e.GET_MEM_USAGE="get_mem_usage",e.REPLY="reply"}(t=e.CommandType||(e.CommandType={}))}(r=e.Child||(e.Child={}))}(t=e.To||(e.To={})),function(e){let t,r;!function(e){let t;!function(e){e.CALLBACK="callback",e.REPLY="reply"}(t=e.CommandType||(e.CommandType={}))}(t=e.Instance||(e.Instance={})),function(e){let t;!function(e){e.LOG="log",e.REPLY="reply"}(t=e.CommandType||(e.CommandType={}))}(r=e.Child||(e.Child={}))}(r=e.From||(e.From={}))}(r.Message||(r.Message={})),function(e){e.STRING="string",e.NUMBER="number",e.UNDEFINED="undefined",e.NULL="null",e.OBJECT="object",e.FUNCTION="function",e.BUFFER="buffer",e.OTHER="other"}(t||(t={}));let n=0;r.encodeArguments=function(r,o,i,s){try{return i.map((i,a)=>{try{if("object"==typeof i&&i===r)return{type:t.OBJECT,value:"self"};if(s){if(i instanceof e)return{type:t.BUFFER,original:i,value:null};if("object"==typeof i)return{type:t.OBJECT,original:i,value:null}}if(i instanceof e)return{type:t.BUFFER,value:i.toString("hex")};if("string"==typeof i)return{type:t.STRING,value:i};if("number"==typeof i)return{type:t.NUMBER,value:i};if("function"==typeof i){for(const e in o)if(o[e]===i)return{type:t.FUNCTION,value:e+""};const e=n++;return o[e+""]=i,{type:t.FUNCTION,value:e+""}}return void 0===i?{type:t.UNDEFINED,value:i}:null===i?{type:t.NULL,value:i}:"object"==typeof i?{type:t.OBJECT,value:i}:{type:t.OTHER,value:i}}catch(e){throw e.stack&&(e.stack+="\nIn encodeArguments, argument "+a),e}})}catch(e){throw e.stack&&(e.stack+="\nThreadedClass, unsupported attribute"),e}},r.decodeArguments=function(r,n,o){return n.map(n=>void 0!==n.original?n.original:n.type===t.STRING?n.value:n.type===t.NUMBER?n.value:n.type===t.BUFFER?e.from(n.value,"hex"):n.type===t.UNDEFINED?n.value:n.type===t.NULL?n.value:n.type===t.FUNCTION?o(n):n.type===t.OBJECT&&"self"===n.value?r():n.value)}}).call(this,e("buffer").Buffer)},{buffer:6}],5:[function(e,t,r){"use strict";r.byteLength=function(e){var t=f(e),r=t[0],n=t[1];return 3*(r+n)/4-n},r.toByteArray=function(e){var t,r,n=f(e),s=n[0],a=n[1],u=new i(function(e,t,r){return 3*(t+r)/4-r}(0,s,a)),c=0,h=a>0?s-4:s;for(r=0;r<h;r+=4)t=o[e.charCodeAt(r)]<<18|o[e.charCodeAt(r+1)]<<12|o[e.charCodeAt(r+2)]<<6|o[e.charCodeAt(r+3)],u[c++]=t>>16&255,u[c++]=t>>8&255,u[c++]=255&t;2===a&&(t=o[e.charCodeAt(r)]<<2|o[e.charCodeAt(r+1)]>>4,u[c++]=255&t);1===a&&(t=o[e.charCodeAt(r)]<<10|o[e.charCodeAt(r+1)]<<4|o[e.charCodeAt(r+2)]>>2,u[c++]=t>>8&255,u[c++]=255&t);return u},r.fromByteArray=function(e){for(var t,r=e.length,o=r%3,i=[],s=0,a=r-o;s<a;s+=16383)i.push(c(e,s,s+16383>a?a:s+16383));1===o?(t=e[r-1],i.push(n[t>>2]+n[t<<4&63]+"==")):2===o&&(t=(e[r-2]<<8)+e[r-1],i.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function f(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function c(e,t,r){for(var o,i,s=[],a=t;a<r;a+=3)o=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],6:[function(e,t,r){(function(t){"use strict";var n=e("base64-js"),o=e("ieee754");r.Buffer=t,r.SlowBuffer=function(e){+e!=e&&(e=0);return t.alloc(+e)},r.INSPECT_MAX_BYTES=50;var i=2147483647;function s(e){if(e>i)throw new RangeError('The value "'+e+'" is invalid for option "size"');var r=new Uint8Array(e);return r.__proto__=t.prototype,r}function t(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return f(e)}return a(e,t,r)}function a(e,r,n){if("string"==typeof e)return function(e,r){"string"==typeof r&&""!==r||(r="utf8");if(!t.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var n=0|l(e,r),o=s(n),i=o.write(e,r);i!==n&&(o=o.slice(0,i));return o}(e,r);if(ArrayBuffer.isView(e))return c(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(j(e,ArrayBuffer)||e&&j(e.buffer,ArrayBuffer))return function(e,r,n){if(r<0||e.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<r+(n||0))throw new RangeError('"length" is outside of buffer bounds');var o;o=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);return o.__proto__=t.prototype,o}(e,r,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var o=e.valueOf&&e.valueOf();if(null!=o&&o!==e)return t.from(o,r,n);var i=function(e){if(t.isBuffer(e)){var r=0|h(e.length),n=s(r);return 0===n.length?n:(e.copy(n,0,0,r),n)}if(void 0!==e.length)return"number"!=typeof e.length||D(e.length)?s(0):c(e);if("Buffer"===e.type&&Array.isArray(e.data))return c(e.data)}(e);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return t.from(e[Symbol.toPrimitive]("string"),r,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function u(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function f(e){return u(e),s(e<0?0:0|h(e))}function c(e){for(var t=e.length<0?0:0|h(e.length),r=s(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function h(e){if(e>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return 0|e}function l(e,r){if(t.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||j(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var n=e.length,o=arguments.length>2&&!0===arguments[2];if(!o&&0===n)return 0;for(var i=!1;;)switch(r){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return F(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return N(e).length;default:if(i)return o?-1:F(e).length;r=(""+r).toLowerCase(),i=!0}}function p(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function d(e,r,n,o,i){if(0===e.length)return-1;if("string"==typeof n?(o=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),D(n=+n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof r&&(r=t.from(r,o)),t.isBuffer(r))return 0===r.length?-1:g(e,r,n,o,i);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,r,n):Uint8Array.prototype.lastIndexOf.call(e,r,n):g(e,[r],n,o,i);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){var i,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function f(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){var c=-1;for(i=r;i<a;i++)if(f(e,i)===f(t,-1===c?0:i-c)){if(-1===c&&(c=i),i-c+1===u)return c*s}else-1!==c&&(i-=i-c),c=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){for(var h=!0,l=0;l<u;l++)if(f(e,i+l)!==f(t,l)){h=!1;break}if(h)return i}return-1}function y(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(D(a))return s;e[r+s]=a}return s}function m(e,t,r,n){return x(F(t,e.length-r),e,r,n)}function w(e,t,r,n){return x(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function T(e,t,r,n){return w(e,t,r,n)}function E(e,t,r,n){return x(N(t),e,r,n)}function b(e,t,r,n){return x(function(e,t){for(var r,n,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function v(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function _(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var i,s,a,u,f=e[o],c=null,h=f>239?4:f>223?3:f>191?2:1;if(o+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(i=e[o+1]))&&(u=(31&f)<<6|63&i)>127&&(c=u);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&(u=(15&f)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(c=u);break;case 4:i=e[o+1],s=e[o+2],a=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&f)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(c=u)}null===c?(c=65533,h=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),o+=h}return function(e){var t=e.length;if(t<=I)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=I));return r}(n)}r.kMaxLength=i,t.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),t.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(t.prototype,"parent",{enumerable:!0,get:function(){if(t.isBuffer(this))return this.buffer}}),Object.defineProperty(t.prototype,"offset",{enumerable:!0,get:function(){if(t.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&t[Symbol.species]===t&&Object.defineProperty(t,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),t.poolSize=8192,t.from=function(e,t,r){return a(e,t,r)},t.prototype.__proto__=Uint8Array.prototype,t.__proto__=Uint8Array,t.alloc=function(e,t,r){return function(e,t,r){return u(e),e<=0?s(e):void 0!==t?"string"==typeof r?s(e).fill(t,r):s(e).fill(t):s(e)}(e,t,r)},t.allocUnsafe=function(e){return f(e)},t.allocUnsafeSlow=function(e){return f(e)},t.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==t.prototype},t.compare=function(e,r){if(j(e,Uint8Array)&&(e=t.from(e,e.offset,e.byteLength)),j(r,Uint8Array)&&(r=t.from(r,r.offset,r.byteLength)),!t.isBuffer(e)||!t.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var n=e.length,o=r.length,i=0,s=Math.min(n,o);i<s;++i)if(e[i]!==r[i]){n=e[i],o=r[i];break}return n<o?-1:o<n?1:0},t.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},t.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return t.alloc(0);var n;if(void 0===r)for(r=0,n=0;n<e.length;++n)r+=e[n].length;var o=t.allocUnsafe(r),i=0;for(n=0;n<e.length;++n){var s=e[n];if(j(s,Uint8Array)&&(s=t.from(s)),!t.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(o,i),i+=s.length}return o},t.byteLength=l,t.prototype._isBuffer=!0,t.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)p(this,t,t+1);return this},t.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)p(this,t,t+3),p(this,t+1,t+2);return this},t.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)p(this,t,t+7),p(this,t+1,t+6),p(this,t+2,t+5),p(this,t+3,t+4);return this},t.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?_(this,0,e):function(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return M(this,t,r);case"utf8":case"utf-8":return _(this,t,r);case"ascii":return A(this,t,r);case"latin1":case"binary":return C(this,t,r);case"base64":return v(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}.apply(this,arguments)},t.prototype.toLocaleString=t.prototype.toString,t.prototype.equals=function(e){if(!t.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===t.compare(this,e)},t.prototype.inspect=function(){var e="",t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},t.prototype.compare=function(e,r,n,o,i){if(j(e,Uint8Array)&&(e=t.from(e,e.offset,e.byteLength)),!t.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===r&&(r=0),void 0===n&&(n=e?e.length:0),void 0===o&&(o=0),void 0===i&&(i=this.length),r<0||n>e.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&r>=n)return 0;if(o>=i)return-1;if(r>=n)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(o>>>=0),a=(n>>>=0)-(r>>>=0),u=Math.min(s,a),f=this.slice(o,i),c=e.slice(r,n),h=0;h<u;++h)if(f[h]!==c[h]){s=f[h],a=c[h];break}return s<a?-1:a<s?1:0},t.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},t.prototype.indexOf=function(e,t,r){return d(this,e,t,r,!0)},t.prototype.lastIndexOf=function(e,t,r){return d(this,e,t,r,!1)},t.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return y(this,e,t,r);case"utf8":case"utf-8":return m(this,e,t,r);case"ascii":return w(this,e,t,r);case"latin1":case"binary":return T(this,e,t,r);case"base64":return E(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},t.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var I=4096;function A(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function C(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function M(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=t;i<r;++i)o+=O(e[i]);return o}function P(e,t,r){for(var n=e.slice(t,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function k(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function U(e,r,n,o,i,s){if(!t.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<s)throw new RangeError('"value" argument is out of bounds');if(n+o>e.length)throw new RangeError("Index out of range")}function B(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,t,r,n,i){return t=+t,r>>>=0,i||B(e,0,r,4),o.write(e,t,r,n,23,4),r+4}function S(e,t,r,n,i){return t=+t,r>>>=0,i||B(e,0,r,8),o.write(e,t,r,n,52,8),r+8}t.prototype.slice=function(e,r){var n=this.length;(e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<e&&(r=e);var o=this.subarray(e,r);return o.__proto__=t.prototype,o},t.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},t.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},t.prototype.readUInt8=function(e,t){return e>>>=0,t||k(e,1,this.length),this[e]},t.prototype.readUInt16LE=function(e,t){return e>>>=0,t||k(e,2,this.length),this[e]|this[e+1]<<8},t.prototype.readUInt16BE=function(e,t){return e>>>=0,t||k(e,2,this.length),this[e]<<8|this[e+1]},t.prototype.readUInt32LE=function(e,t){return e>>>=0,t||k(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},t.prototype.readUInt32BE=function(e,t){return e>>>=0,t||k(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},t.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},t.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||k(e,t,this.length);for(var n=t,o=1,i=this[e+--n];n>0&&(o*=256);)i+=this[e+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},t.prototype.readInt8=function(e,t){return e>>>=0,t||k(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},t.prototype.readInt16LE=function(e,t){e>>>=0,t||k(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},t.prototype.readInt16BE=function(e,t){e>>>=0,t||k(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},t.prototype.readInt32LE=function(e,t){return e>>>=0,t||k(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},t.prototype.readInt32BE=function(e,t){return e>>>=0,t||k(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},t.prototype.readFloatLE=function(e,t){return e>>>=0,t||k(e,4,this.length),o.read(this,e,!0,23,4)},t.prototype.readFloatBE=function(e,t){return e>>>=0,t||k(e,4,this.length),o.read(this,e,!1,23,4)},t.prototype.readDoubleLE=function(e,t){return e>>>=0,t||k(e,8,this.length),o.read(this,e,!0,52,8)},t.prototype.readDoubleBE=function(e,t){return e>>>=0,t||k(e,8,this.length),o.read(this,e,!1,52,8)},t.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||U(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},t.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||U(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},t.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,255,0),this[t]=255&e,t+1},t.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},t.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},t.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},t.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},t.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);U(this,e,t,r,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},t.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);U(this,e,t,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},t.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},t.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},t.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},t.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},t.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||U(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},t.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},t.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},t.prototype.writeDoubleLE=function(e,t,r){return S(this,e,t,!0,r)},t.prototype.writeDoubleBE=function(e,t,r){return S(this,e,t,!1,r)},t.prototype.copy=function(e,r,n,o){if(!t.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),o||0===o||(o=this.length),r>=e.length&&(r=e.length),r||(r=0),o>0&&o<n&&(o=n),o===n)return 0;if(0===e.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-r<o-n&&(o=e.length-r+n);var i=o-n;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(r,n,o);else if(this===e&&n<r&&r<o)for(var s=i-1;s>=0;--s)e[s+r]=this[s+n];else Uint8Array.prototype.set.call(e,this.subarray(n,o),r);return i},t.prototype.fill=function(e,r,n,o){if("string"==typeof e){if("string"==typeof r?(o=r,r=0,n=this.length):"string"==typeof n&&(o=n,n=this.length),void 0!==o&&"string"!=typeof o)throw new TypeError("encoding must be a string");if("string"==typeof o&&!t.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(1===e.length){var i=e.charCodeAt(0);("utf8"===o&&i<128||"latin1"===o)&&(e=i)}}else"number"==typeof e&&(e&=255);if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;var s;if(r>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=r;s<n;++s)this[s]=e;else{var a=t.isBuffer(e)?e:t.from(e,o),u=a.length;if(0===u)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=a[s%u]}return this};var R=/[^+/0-9A-Za-z-_]/g;function O(e){return e<16?"0"+e.toString(16):e.toString(16)}function F(e,t){var r;t=t||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function N(e){return n.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(R,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function x(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function j(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function D(e){return e!=e}}).call(this,e("buffer").Buffer)},{"base64-js":5,buffer:6,ieee754:7}],7:[function(e,t,r){r.read=function(e,t,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,f=u>>1,c=-7,h=r?o-1:0,l=r?-1:1,p=e[t+h];for(h+=l,i=p&(1<<-c)-1,p>>=-c,c+=a;c>0;i=256*i+e[t+h],h+=l,c-=8);for(s=i&(1<<-c)-1,i>>=-c,c+=n;c>0;s=256*s+e[t+h],h+=l,c-=8);if(0===i)i=1-f;else{if(i===u)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=f}return(p?-1:1)*s*Math.pow(2,i-n)},r.write=function(e,t,r,n,o,i){var s,a,u,f=8*i-o-1,c=(1<<f)-1,h=c>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+h>=1?l/u:l*Math.pow(2,1-h))*u>=2&&(s++,u/=2),s+h>=c?(a=0,s=c):s+h>=1?(a=(t*u-1)*Math.pow(2,o),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,o),s=0));o>=8;e[r+p]=255&a,p+=d,a/=256,o-=8);for(s=s<<o|a,f+=o;f>0;e[r+p]=255&s,p+=d,s/=256,f-=8);e[r+p-d]|=128*g}},{}],8:[function(e,t,r){(function(e){t.exports=function(r){if(t.exports.stub!==t.exports)return t.exports.stub.apply(this,arguments);try{return e.kill(r,0)}catch(e){return"EPERM"===e.code}},t.exports.stub=t.exports}).call(this,e("_process"))},{_process:9}],9:[function(e,t,r){var n,o,i=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(e){n=s}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(e){o=a}}();var f,c=[],h=!1,l=-1;function p(){h&&f&&(h=!1,f.length?c=f.concat(c):l=-1,c.length&&d())}function d(){if(!h){var e=u(p);h=!0;for(var t=c.length;t;){for(f=c,c=[];++l<t;)f&&f[l].run();l=-1,t=c.length}f=null,h=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function y(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];c.push(new g(e,t)),1!==c.length||h||u(d)},g.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}]},{},[1]);
//# sourceMappingURL=threadedclass-worker.min.js.map

@@ -169,7 +169,9 @@ /// <reference types="node" />

private _onMessageFromChild;
private _replyErrorToChild;
private _sendReplyToChild;
private _findFreeChild;
private killChild;
private rejectChildMethods;
/** trace to console.error if debugging is enabled */
debugLogError(...args: any[]): void;
/** trace to console.error if debugging is enabled */
debugLog(...args: any[]): void;
/** trace to console.error */

@@ -176,0 +178,0 @@ private consoleError;

@@ -162,4 +162,3 @@ "use strict";

child = newChild;
if (this.debug)
this.consoleLog(`New child: "${newChild.id}"`);
this.debugLog(`New child: "${newChild.id}"`);
}

@@ -189,4 +188,3 @@ return child;

child.instances[instance.id] = instance;
if (this.debug)
this.consoleLog(`Add instance "${instance.id}" to "${child.id}"`);
this.debugLog(`Add instance "${instance.id}" to "${child.id}"`);
return instance;

@@ -334,4 +332,3 @@ }

const child = this._children[id];
if (this.debug)
this.consoleLog(`Killing child "${this.getChildDescriptor(child)}"`);
this.debugLog(`Killing child "${this.getChildDescriptor(child)}"`);
return this.killChild(id, 'killAllChildren');

@@ -717,4 +714,3 @@ })).then(() => {

this._emitProxyEvent(child, 'error', err);
if (this.debug)
this.consoleError('Error when running restartChild()', err);
this.debugLogError('Error when running restartChild()', err);
// Clean up the child:

@@ -733,4 +729,3 @@ this.killChild(child, 'timeout when restarting', true).catch((e) => {

this._emitProxyEvent(child, 'error', err);
if (this.debug)
this.consoleError('Error when running killChild()', err);
this.debugLogError('Error when running killChild()', err);
});

@@ -776,4 +771,3 @@ }

this._emitProxyEvent(child, 'error', err);
if (this.debug)
this.consoleError('Error from child ' + child.id, err);
this.debugLogError('Error from child ' + child.id, err);
});

@@ -786,4 +780,3 @@ child.process.on('message', (message) => {

catch (e) {
if (this.debug)
this.consoleError(`Error in onMessageCallback in child ${child.id}`, message, e);
this.debugLogError(`Error in onMessageCallback in child ${child.id}`, message, e);
throw e;

@@ -799,4 +792,3 @@ }

catch (e) {
if (this.debug)
this.consoleError(`Error in onMessageCallback in instance ${instance.id}`, message, instance, e);
this.debugLogError(`Error in onMessageCallback in instance ${instance.id}`, message, instance, e);
throw e;

@@ -808,4 +800,3 @@ }

this._emitProxyEvent(child, 'error', err);
if (this.debug)
this.consoleError(err);
this.debugLogError(err);
}

@@ -816,4 +807,3 @@ }

this._emitProxyEvent(child, 'error', err);
if (this.debug)
this.consoleError(err);
this.debugLogError(err);
}

@@ -839,37 +829,3 @@ });

}
else if (message.cmd === sharedApi_1.Message.From.Child.CommandType.CALLBACK) {
// Callback function is called by worker
let msg = message;
let callback = child.callbacks[msg.callbackId];
if (callback) {
try {
Promise.resolve(callback(...msg.args))
.then((result) => {
let encodedResult = (0, sharedApi_1.encodeArguments)({}, child.callbacks, [result], !!child.process.isFakeProcess);
this._sendReplyToChild(child, msg.cmdId, undefined, encodedResult[0]);
})
.catch((err) => {
this._replyErrorToChild(child, msg, err);
});
}
catch (err) {
this._replyErrorToChild(child, msg, err);
}
}
else
throw Error(`callback "${msg.callbackId}" not found in child ${child.id}`);
}
}
_replyErrorToChild(child, messageToReplyTo, error) {
this._sendReplyToChild(child, messageToReplyTo.cmdId, error);
}
_sendReplyToChild(child, replyTo, error, reply, cb) {
let msg = {
cmd: sharedApi_1.Message.To.Child.CommandType.REPLY,
replyTo: replyTo,
reply: reply,
error: error ? (error.stack || error).toString() : error
};
this.sendMessageToChild(child, msg, cb);
}
_findFreeChild(threadUsage) {

@@ -906,4 +862,3 @@ let id = Object.keys(this._children).find((id) => {

}
if (this.debug)
this.consoleLog(`Killing child ${child.id} due to: ${reason}`);
this.debugLog(`Killing child ${child.id} due to: ${reason}`);
if (child) {

@@ -965,2 +920,12 @@ if (cleanUp) {

}
/** trace to console.error if debugging is enabled */
debugLogError(...args) {
if (this.debug)
this.consoleError(...args);
}
/** trace to console.error if debugging is enabled */
debugLog(...args) {
if (this.debug)
this.consoleLog(...args);
}
/** trace to console.error */

@@ -967,0 +932,0 @@ consoleError(...args) {

@@ -119,7 +119,17 @@ "use strict";

.catch((err) => {
replyError(instance, msg, err);
try {
replyError(instance, msg, err);
}
catch (e) {
manager_1.ThreadedClassManagerInternal.debugLogError(new Error(`ThreadedClass: Thrown error in callback "${msg.callbackId}": Unable to forward error to child due to: ${e}`));
}
});
}
catch (err) {
replyError(instance, msg, err);
try {
replyError(instance, msg, err);
}
catch (e) {
manager_1.ThreadedClassManagerInternal.debugLogError(new Error(`ThreadedClass: Thrown error in callback "${msg.callbackId}": Unable to forward error to child due to: ${e}`));
}
}

@@ -126,0 +136,0 @@ }

@@ -188,4 +188,3 @@ import { ThreadedClassConfig } from '../api';

LOG = "log",
REPLY = "reply",
CALLBACK = "callback"
REPLY = "reply"
}

@@ -204,10 +203,4 @@ interface LogConstr {

type Reply = ReplyConstr & ChildBase;
interface CallbackConstr {
cmd: CommandType.CALLBACK;
callbackId: string;
args: Array<any>;
}
type Callback = CallbackConstr & ChildBase;
type AnyConstr = ReplyConstr | CallbackConstr | LogConstr;
type Any = Reply | Callback | Log;
type AnyConstr = ReplyConstr | LogConstr;
type Any = Reply | Log;
}

@@ -214,0 +207,0 @@ }

@@ -65,3 +65,2 @@ "use strict";

CommandType["REPLY"] = "reply";
CommandType["CALLBACK"] = "callback";
})(CommandType = Child.CommandType || (Child.CommandType = {}));

@@ -68,0 +67,0 @@ })(Child = From.Child || (From.Child = {}));

{
"name": "threadedclass",
"version": "1.2.1",
"version": "1.2.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc