Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

it-handshake

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-handshake - npm Package Compare versions

Comparing version
2.0.0
to
3.0.0
+13
dist/src/index.d.ts
import { Reader } from 'it-reader';
import type { Duplex, Source } from 'it-stream-types';
import type { Pushable } from 'it-pushable';
export interface Handshake {
reader: Reader;
writer: Pushable<Uint8Array>;
stream: Duplex<Uint8Array>;
rest: () => Source<Uint8Array>;
write: (data: Uint8Array) => void;
read: () => Promise<Uint8Array>;
}
export declare function handshake(stream: Duplex<Uint8Array>): Handshake;
//# sourceMappingURL=index.d.ts.map
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,WAAW,CAAA;AAI1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;IAC5B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;IAC1B,IAAI,EAAE,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;IAC9B,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAA;IACjC,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAA;CAChC;AAGD,wBAAgB,SAAS,CAAE,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAyChE"}
import { reader } from 'it-reader';
import { pushable } from 'it-pushable';
import defer from 'p-defer';
import map from 'it-map';
// Convert a duplex stream into a reader and writer and rest stream
export function handshake(stream) {
const writer = pushable(); // Write bytes on demand to the sink
const source = reader(stream.source); // Read bytes on demand from the source
// Waits for a source to be passed to the rest stream's sink
const sourcePromise = defer();
let sinkErr;
const sinkPromise = stream.sink((async function* () {
yield* writer;
const source = await sourcePromise.promise;
yield* source;
})());
sinkPromise.catch(err => {
sinkErr = err;
});
const rest = {
sink: async (source) => {
if (sinkErr != null) {
return await Promise.reject(sinkErr);
}
sourcePromise.resolve(source);
return await sinkPromise;
},
source: map(source, bl => bl.slice())
};
return {
reader: source,
writer,
stream: rest,
rest: () => writer.end(),
write: writer.push,
read: async () => {
const res = await source.next();
return res.value.slice();
}
};
}
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,MAAM,SAAS,CAAA;AAC3B,OAAO,GAAG,MAAM,QAAQ,CAAA;AAaxB,mEAAmE;AACnE,MAAM,UAAU,SAAS,CAAE,MAA0B;IACnD,MAAM,MAAM,GAAG,QAAQ,EAAc,CAAA,CAAC,oCAAoC;IAC1E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA,CAAC,uCAAuC;IAE5E,4DAA4D;IAC5D,MAAM,aAAa,GAAG,KAAK,EAAsB,CAAA;IACjD,IAAI,OAAc,CAAA;IAElB,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,SAAU,CAAC;QAC/C,KAAM,CAAC,CAAC,MAAM,CAAA;QACd,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAA;QAC1C,KAAM,CAAC,CAAC,MAAM,CAAA;IAChB,CAAC,CAAC,EAAE,CAAC,CAAA;IAEL,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,GAAG,GAAG,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,MAAM,IAAI,GAAuB;QAC/B,IAAI,EAAE,KAAK,EAAC,MAAM,EAAC,EAAE;YACnB,IAAI,OAAO,IAAI,IAAI,EAAE;gBACnB,OAAO,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;aACrC;YAED,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YAC7B,OAAO,MAAM,WAAW,CAAA;QAC1B,CAAC;QACD,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;KACtC,CAAA;IAED,OAAO;QACL,MAAM,EAAE,MAAM;QACd,MAAM;QACN,MAAM,EAAE,IAAI;QACZ,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC,IAAI;QAClB,IAAI,EAAE,KAAK,IAAI,EAAE;YACf,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YAC/B,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAC1B,CAAC;KACF,CAAA;AACH,CAAC"}
This project is dual licensed under MIT and Apache-2.0.
MIT: https://www.opensource.org/licenses/mit
Apache-2.0: https://www.apache.org/licenses/license-2.0
import { Reader, reader } from 'it-reader'
import { pushable } from 'it-pushable'
import defer from 'p-defer'
import map from 'it-map'
import type { Duplex, Source } from 'it-stream-types'
import type { Pushable } from 'it-pushable'
export interface Handshake {
reader: Reader
writer: Pushable<Uint8Array>
stream: Duplex<Uint8Array>
rest: () => Source<Uint8Array>
write: (data: Uint8Array) => void
read: () => Promise<Uint8Array>
}
// Convert a duplex stream into a reader and writer and rest stream
export function handshake (stream: Duplex<Uint8Array>): Handshake {
const writer = pushable<Uint8Array>() // Write bytes on demand to the sink
const source = reader(stream.source) // Read bytes on demand from the source
// Waits for a source to be passed to the rest stream's sink
const sourcePromise = defer<Source<Uint8Array>>()
let sinkErr: Error
const sinkPromise = stream.sink((async function * () {
yield * writer
const source = await sourcePromise.promise
yield * source
})())
sinkPromise.catch(err => {
sinkErr = err
})
const rest: Duplex<Uint8Array> = {
sink: async source => {
if (sinkErr != null) {
return await Promise.reject(sinkErr)
}
sourcePromise.resolve(source)
return await sinkPromise
},
source: map(source, bl => bl.slice())
}
return {
reader: source,
writer,
stream: rest,
rest: () => writer.end(),
write: writer.push,
read: async () => {
const res = await source.next()
return res.value.slice()
}
}
}
+131
-34
{
"name": "it-handshake",
"version": "2.0.0",
"description": "Create handshakes for binary protocols with iterable streams.",
"main": "./src/index.js",
"version": "3.0.0",
"description": "Create handshakes for binary protocols with iterable streams",
"homepage": "https://github.com/jacobheun/it-handshake#readme",
"license": "Apache-2.0 OR MIT",
"repository": {

@@ -10,44 +11,140 @@ "type": "git",

},
"bugs": {
"url": "https://github.com/jacobheun/it-handshake/issues"
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist"
"dist/src",
"!dist/test",
"!**/*.tsbuildinfo"
],
"keywords": [
"async",
"iterable",
"iterator",
"handshake"
],
"exports": {
".": {
"import": "./dist/src/index.js"
}
},
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
"sourceType": "module"
}
},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Trivial Changes"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {
"test": "aegir test -t node -t browser -t webworker",
"test:browser": "aegir test -t browser -t webworker",
"test:node": "aegir test -t node",
"lint": "aegir lint",
"release": "aegir release -t node -t browser",
"release-minor": "aegir release --type minor -t node -t browser",
"release-major": "aegir release --type major -t node -t browser",
"build": "aegir build",
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node"
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
"build": "tsc",
"pretest": "npm run build",
"test": "aegir test -f ./dist/test",
"test:chrome": "npm run test -- -t browser --cov",
"test:chrome-webworker": "npm run test -- -t webworker",
"test:firefox": "npm run test -- -t browser -- --browser firefox",
"test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
"test:node": "npm run test -- -t node --cov",
"test:electron-main": "npm run test -- -t electron-main",
"release": "semantic-release"
},
"pre-push": [
"lint"
],
"author": "Jacob Heun",
"license": "MIT",
"dependencies": {
"it-pushable": "^1.4.0",
"it-reader": "^3.0.0",
"p-defer": "^3.0.0"
"it-map": "^1.0.6",
"it-pushable": "^2.0.1",
"it-reader": "^4.0.2",
"it-stream-types": "^1.0.4",
"p-defer": "^4.0.0"
},
"devDependencies": {
"aegir": "^33.0.0",
"it-pair": "^1.0.0",
"it-pipe": "^1.1.0",
"streaming-iterables": "^5.0.2",
"uint8arrays": "^2.1.4"
"aegir": "^36.1.3",
"it-all": "^1.0.6",
"it-pair": "^2.0.2",
"it-pipe": "^2.0.2",
"uint8arrays": "^3.0.0"
},
"contributors": [
"Jacob Heun <jacobheun@gmail.com>",
"Alex Potsides <alex@achingbrain.net>"
"author": "Jacob Heun",
"keywords": [
"async",
"iterable",
"iterator",
"handshake"
]
}
# it-handshake
[![Build Status](https://travis-ci.org/jacobheun/it-handshake.svg?branch=master)](https://travis-ci.org/jacobheun/it-handshake)
[![Build Status](https://github.com/jacobheun/it-handshake/actions/workflows/js-test-and-release.yml/badge.svg?branch=master)](https://github.com/jacobheun/it-handshake/actions/workflows/js-test-and-release.yml)
[![dependencies Status](https://david-dm.org/jacobheun/it-handshake/status.svg)](https://david-dm.org/jacobheun/it-handshake)

@@ -17,3 +17,3 @@ [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

See [./example.js](./example.js)
See [./example/index.js](./example/index.js)

@@ -20,0 +20,0 @@ ## API

# [2.0.0](https://github.com/jacobheun/it-handshake/compare/v1.0.2...v2.0.0) (2021-04-08)
<a name="1.0.2"></a>
## [1.0.2](https://github.com/jacobheun/it-handshake/compare/v1.0.1...v1.0.2) (2020-08-12)
### Bug Fixes
* unhandled promise rejection when async work done after handshake ([#2](https://github.com/jacobheun/it-handshake/issues/2)) ([61db942](https://github.com/jacobheun/it-handshake/commit/61db942))
<a name="1.0.1"></a>
## [1.0.1](https://github.com/jacobheun/it-handshake/compare/v1.0.0...v1.0.1) (2019-10-30)
<a name="1.0.0"></a>
# 1.0.0 (2019-09-26)
### Features
* initial implementation ([449cb61](https://github.com/jacobheun/it-handshake/commit/449cb61))
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ItHandshake = factory()}(typeof self !== 'undefined' ? self : this, function () {
var ItHandshake=(()=>{var m=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Z=m(M=>{"use strict";M.byteLength=Ct;M.toByteArray=St;M.fromByteArray=Nt;var I=[],g=[],kt=typeof Uint8Array!="undefined"?Uint8Array:Array,P="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var T=0,Mt=P.length;T<Mt;++T)I[T]=P[T],g[P.charCodeAt(T)]=T;g["-".charCodeAt(0)]=62;g["_".charCodeAt(0)]=63;function K(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("=");r===-1&&(r=t);var i=r===t?0:4-r%4;return[r,i]}function Ct(e){var t=K(e),r=t[0],i=t[1];return(r+i)*3/4-i}function Dt(e,t,r){return(t+r)*3/4-r}function St(e){var t,r=K(e),i=r[0],n=r[1],o=new kt(Dt(e,i,n)),u=0,h=n>0?i-4:i,s;for(s=0;s<h;s+=4)t=g[e.charCodeAt(s)]<<18|g[e.charCodeAt(s+1)]<<12|g[e.charCodeAt(s+2)]<<6|g[e.charCodeAt(s+3)],o[u++]=t>>16&255,o[u++]=t>>8&255,o[u++]=t&255;return n===2&&(t=g[e.charCodeAt(s)]<<2|g[e.charCodeAt(s+1)]>>4,o[u++]=t&255),n===1&&(t=g[e.charCodeAt(s)]<<10|g[e.charCodeAt(s+1)]<<4|g[e.charCodeAt(s+2)]>>2,o[u++]=t>>8&255,o[u++]=t&255),o}function Ot(e){return I[e>>18&63]+I[e>>12&63]+I[e>>6&63]+I[e&63]}function Pt(e,t,r){for(var i,n=[],o=t;o<r;o+=3)i=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),n.push(Ot(i));return n.join("")}function Nt(e){for(var t,r=e.length,i=r%3,n=[],o=16383,u=0,h=r-i;u<h;u+=o)n.push(Pt(e,u,u+o>h?h:u+o));return i===1?(t=e[r-1],n.push(I[t>>2]+I[t<<4&63]+"==")):i===2&&(t=(e[r-2]<<8)+e[r-1],n.push(I[t>>10]+I[t>>4&63]+I[t<<2&63]+"=")),n.join("")}});var Q=m($=>{$.read=function(e,t,r,i,n){var o,u,h=n*8-i-1,s=(1<<h)-1,p=s>>1,l=-7,c=r?n-1:0,B=r?-1:1,x=e[t+c];for(c+=B,o=x&(1<<-l)-1,x>>=-l,l+=h;l>0;o=o*256+e[t+c],c+=B,l-=8);for(u=o&(1<<-l)-1,o>>=-l,l+=i;l>0;u=u*256+e[t+c],c+=B,l-=8);if(o===0)o=1-p;else{if(o===s)return u?NaN:(x?-1:1)*Infinity;u=u+Math.pow(2,i),o=o-p}return(x?-1:1)*u*Math.pow(2,o-i)};$.write=function(e,t,r,i,n,o){var u,h,s,p=o*8-n-1,l=(1<<p)-1,c=l>>1,B=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,x=i?0:o-1,a=i?1:-1,A=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===Infinity?(h=isNaN(t)?1:0,u=l):(u=Math.floor(Math.log(t)/Math.LN2),t*(s=Math.pow(2,-u))<1&&(u--,s*=2),u+c>=1?t+=B/s:t+=B*Math.pow(2,1-c),t*s>=2&&(u++,s/=2),u+c>=l?(h=0,u=l):u+c>=1?(h=(t*s-1)*Math.pow(2,n),u=u+c):(h=t*Math.pow(2,c-1)*Math.pow(2,n),u=0));n>=8;e[r+x]=h&255,x+=a,h/=256,n-=8);for(u=u<<n|h,p+=n;p>0;e[r+x]=u&255,x+=a,u/=256,p-=8);e[r+x-a]|=A*128}});var wt=m(L=>{"use strict";var q=Z(),C=Q(),v=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;L.Buffer=f;L.SlowBuffer=$t;L.INSPECT_MAX_BYTES=50;var D=2147483647;L.kMaxLength=D;f.TYPED_ARRAY_SUPPORT=qt();!f.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&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.");function qt(){try{let e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch(e){return!1}}Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(!!f.isBuffer(this))return this.buffer}});Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(!!f.isBuffer(this))return this.byteOffset}});function U(e){if(e>D)throw new RangeError('The value "'+e+'" is invalid for option "size"');let t=new Uint8Array(e);return Object.setPrototypeOf(t,f.prototype),t}function f(e,t,r){if(typeof e=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return j(e)}return tt(e,t,r)}f.poolSize=8192;function tt(e,t,r){if(typeof e=="string")return jt(e,t);if(ArrayBuffer.isView(e))return Wt(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(F(e,ArrayBuffer)||e&&F(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(F(e,SharedArrayBuffer)||e&&F(e.buffer,SharedArrayBuffer)))return W(e,t,r);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=e.valueOf&&e.valueOf();if(i!=null&&i!==e)return f.from(i,t,r);let n=Gt(e);if(n)return n;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return f.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}f.from=function(e,t,r){return tt(e,t,r)};Object.setPrototypeOf(f.prototype,Uint8Array.prototype);Object.setPrototypeOf(f,Uint8Array);function rt(e){if(typeof e!="number")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 Yt(e,t,r){return rt(e),e<=0?U(e):t!==void 0?typeof r=="string"?U(e).fill(t,r):U(e).fill(t):U(e)}f.alloc=function(e,t,r){return Yt(e,t,r)};function j(e){return rt(e),U(e<0?0:G(e)|0)}f.allocUnsafe=function(e){return j(e)};f.allocUnsafeSlow=function(e){return j(e)};function jt(e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!f.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let r=et(e,t)|0,i=U(r),n=i.write(e,t);return n!==r&&(i=i.slice(0,n)),i}function Y(e){let t=e.length<0?0:G(e.length)|0,r=U(t);for(let i=0;i<t;i+=1)r[i]=e[i]&255;return r}function Wt(e){if(F(e,Uint8Array)){let t=new Uint8Array(e);return W(t.buffer,t.byteOffset,t.byteLength)}return Y(e)}function W(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let i;return t===void 0&&r===void 0?i=new Uint8Array(e):r===void 0?i=new Uint8Array(e,t):i=new Uint8Array(e,t,r),Object.setPrototypeOf(i,f.prototype),i}function Gt(e){if(f.isBuffer(e)){let t=G(e.length)|0,r=U(t);return r.length===0||e.copy(r,0,0,t),r}if(e.length!==void 0)return typeof e.length!="number"||z(e.length)?U(0):Y(e);if(e.type==="Buffer"&&Array.isArray(e.data))return Y(e.data)}function G(e){if(e>=D)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+D.toString(16)+" bytes");return e|0}function $t(e){return+e!=e&&(e=0),f.alloc(+e)}f.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==f.prototype};f.compare=function(t,r){if(F(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),F(r,Uint8Array)&&(r=f.from(r,r.offset,r.byteLength)),!f.isBuffer(t)||!f.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;let i=t.length,n=r.length;for(let o=0,u=Math.min(i,n);o<u;++o)if(t[o]!==r[o]){i=t[o],n=r[o];break}return i<n?-1:n<i?1:0};f.isEncoding=function(t){switch(String(t).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}};f.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return f.alloc(0);let i;if(r===void 0)for(r=0,i=0;i<t.length;++i)r+=t[i].length;let n=f.allocUnsafe(r),o=0;for(i=0;i<t.length;++i){let u=t[i];if(F(u,Uint8Array))o+u.length>n.length?(f.isBuffer(u)||(u=f.from(u)),u.copy(n,o)):Uint8Array.prototype.set.call(n,u,o);else if(f.isBuffer(u))u.copy(n,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=u.length}return n};function et(e,t){if(f.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||F(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let r=e.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&r===0)return 0;let n=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return H(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return it(e).length;default:if(n)return i?-1:H(e).length;t=(""+t).toLowerCase(),n=!0}}f.byteLength=et;function Kt(e,t,r){let i=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Xt(this,t,r);case"utf8":case"utf-8":return nt(this,t,r);case"ascii":return Ht(this,t,r);case"latin1":case"binary":return Vt(this,t,r);case"base64":return zt(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Jt(this,t,r);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}f.prototype._isBuffer=!0;function R(e,t,r){let i=e[t];e[t]=e[r],e[r]=i}f.prototype.swap16=function(){let t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<t;r+=2)R(this,r,r+1);return this};f.prototype.swap32=function(){let t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<t;r+=4)R(this,r,r+3),R(this,r+1,r+2);return this};f.prototype.swap64=function(){let t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<t;r+=8)R(this,r,r+7),R(this,r+1,r+6),R(this,r+2,r+5),R(this,r+3,r+4);return this};f.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?nt(this,0,t):Kt.apply(this,arguments)};f.prototype.toLocaleString=f.prototype.toString;f.prototype.equals=function(t){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:f.compare(this,t)===0};f.prototype.inspect=function(){let t="",r=L.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"};v&&(f.prototype[v]=f.prototype.inspect);f.prototype.compare=function(t,r,i,n,o){if(F(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),i===void 0&&(i=t?t.length:0),n===void 0&&(n=0),o===void 0&&(o=this.length),r<0||i>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=i)return 0;if(n>=o)return-1;if(r>=i)return 1;if(r>>>=0,i>>>=0,n>>>=0,o>>>=0,this===t)return 0;let u=o-n,h=i-r,s=Math.min(u,h),p=this.slice(n,o),l=t.slice(r,i);for(let c=0;c<s;++c)if(p[c]!==l[c]){u=p[c],h=l[c];break}return u<h?-1:h<u?1:0};function ut(e,t,r,i,n){if(e.length===0)return-1;if(typeof r=="string"?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,z(r)&&(r=n?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(n)return-1;r=e.length-1}else if(r<0)if(n)r=0;else return-1;if(typeof t=="string"&&(t=f.from(t,i)),f.isBuffer(t))return t.length===0?-1:ot(e,t,r,i,n);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?n?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):ot(e,[t],r,i,n);throw new TypeError("val must be string, number or Buffer")}function ot(e,t,r,i,n){let o=1,u=e.length,h=t.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(e.length<2||t.length<2)return-1;o=2,u/=2,h/=2,r/=2}function s(l,c){return o===1?l[c]:l.readUInt16BE(c*o)}let p;if(n){let l=-1;for(p=r;p<u;p++)if(s(e,p)===s(t,l===-1?0:p-l)){if(l===-1&&(l=p),p-l+1===h)return l*o}else l!==-1&&(p-=p-l),l=-1}else for(r+h>u&&(r=u-h),p=r;p>=0;p--){let l=!0;for(let c=0;c<h;c++)if(s(e,p+c)!==s(t,c)){l=!1;break}if(l)return p}return-1}f.prototype.includes=function(t,r,i){return this.indexOf(t,r,i)!==-1};f.prototype.indexOf=function(t,r,i){return ut(this,t,r,i,!0)};f.prototype.lastIndexOf=function(t,r,i){return ut(this,t,r,i,!1)};function Zt(e,t,r,i){r=Number(r)||0;let n=e.length-r;i?(i=Number(i),i>n&&(i=n)):i=n;let o=t.length;i>o/2&&(i=o/2);let u;for(u=0;u<i;++u){let h=parseInt(t.substr(u*2,2),16);if(z(h))return u;e[r+u]=h}return u}function Qt(e,t,r,i){return O(H(t,e.length-r),e,r,i)}function tr(e,t,r,i){return O(vt(t),e,r,i)}function rr(e,t,r,i){return O(it(t),e,r,i)}function ir(e,t,r,i){return O(er(t,e.length-r),e,r,i)}f.prototype.write=function(t,r,i,n){if(r===void 0)n="utf8",i=this.length,r=0;else if(i===void 0&&typeof r=="string")n=r,i=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(i)?(i=i>>>0,n===void 0&&(n="utf8")):(n=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-r;if((i===void 0||i>o)&&(i=o),t.length>0&&(i<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let u=!1;for(;;)switch(n){case"hex":return Zt(this,t,r,i);case"utf8":case"utf-8":return Qt(this,t,r,i);case"ascii":case"latin1":case"binary":return tr(this,t,r,i);case"base64":return rr(this,t,r,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ir(this,t,r,i);default:if(u)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),u=!0}};f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function zt(e,t,r){return t===0&&r===e.length?q.fromByteArray(e):q.fromByteArray(e.slice(t,r))}function nt(e,t,r){r=Math.min(e.length,r);let i=[],n=t;for(;n<r;){let o=e[n],u=null,h=o>239?4:o>223?3:o>191?2:1;if(n+h<=r){let s,p,l,c;switch(h){case 1:o<128&&(u=o);break;case 2:s=e[n+1],(s&192)==128&&(c=(o&31)<<6|s&63,c>127&&(u=c));break;case 3:s=e[n+1],p=e[n+2],(s&192)==128&&(p&192)==128&&(c=(o&15)<<12|(s&63)<<6|p&63,c>2047&&(c<55296||c>57343)&&(u=c));break;case 4:s=e[n+1],p=e[n+2],l=e[n+3],(s&192)==128&&(p&192)==128&&(l&192)==128&&(c=(o&15)<<18|(s&63)<<12|(p&63)<<6|l&63,c>65535&&c<1114112&&(u=c))}}u===null?(u=65533,h=1):u>65535&&(u-=65536,i.push(u>>>10&1023|55296),u=56320|u&1023),i.push(u),n+=h}return nr(i)}var ft=4096;function nr(e){let t=e.length;if(t<=ft)return String.fromCharCode.apply(String,e);let r="",i=0;for(;i<t;)r+=String.fromCharCode.apply(String,e.slice(i,i+=ft));return r}function Ht(e,t,r){let i="";r=Math.min(e.length,r);for(let n=t;n<r;++n)i+=String.fromCharCode(e[n]&127);return i}function Vt(e,t,r){let i="";r=Math.min(e.length,r);for(let n=t;n<r;++n)i+=String.fromCharCode(e[n]);return i}function Xt(e,t,r){let i=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>i)&&(r=i);let n="";for(let o=t;o<r;++o)n+=or[e[o]];return n}function Jt(e,t,r){let i=e.slice(t,r),n="";for(let o=0;o<i.length-1;o+=2)n+=String.fromCharCode(i[o]+i[o+1]*256);return n}f.prototype.slice=function(t,r){let i=this.length;t=~~t,r=r===void 0?i:~~r,t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),r<0?(r+=i,r<0&&(r=0)):r>i&&(r=i),r<t&&(r=t);let n=this.subarray(t,r);return Object.setPrototypeOf(n,f.prototype),n};function w(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")}f.prototype.readUintLE=f.prototype.readUIntLE=function(t,r,i){t=t>>>0,r=r>>>0,i||w(t,r,this.length);let n=this[t],o=1,u=0;for(;++u<r&&(o*=256);)n+=this[t+u]*o;return n};f.prototype.readUintBE=f.prototype.readUIntBE=function(t,r,i){t=t>>>0,r=r>>>0,i||w(t,r,this.length);let n=this[t+--r],o=1;for(;r>0&&(o*=256);)n+=this[t+--r]*o;return n};f.prototype.readUint8=f.prototype.readUInt8=function(t,r){return t=t>>>0,r||w(t,1,this.length),this[t]};f.prototype.readUint16LE=f.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||w(t,2,this.length),this[t]|this[t+1]<<8};f.prototype.readUint16BE=f.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||w(t,2,this.length),this[t]<<8|this[t+1]};f.prototype.readUint32LE=f.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||w(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};f.prototype.readUint32BE=f.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||w(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};f.prototype.readBigUInt64LE=b(function(t){t=t>>>0,S(t,"offset");let r=this[t],i=this[t+7];(r===void 0||i===void 0)&&k(t,this.length-8);let n=r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,o=this[++t]+this[++t]*2**8+this[++t]*2**16+i*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))});f.prototype.readBigUInt64BE=b(function(t){t=t>>>0,S(t,"offset");let r=this[t],i=this[t+7];(r===void 0||i===void 0)&&k(t,this.length-8);let n=r*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],o=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+i;return(BigInt(n)<<BigInt(32))+BigInt(o)});f.prototype.readIntLE=function(t,r,i){t=t>>>0,r=r>>>0,i||w(t,r,this.length);let n=this[t],o=1,u=0;for(;++u<r&&(o*=256);)n+=this[t+u]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*r)),n};f.prototype.readIntBE=function(t,r,i){t=t>>>0,r=r>>>0,i||w(t,r,this.length);let n=r,o=1,u=this[t+--n];for(;n>0&&(o*=256);)u+=this[t+--n]*o;return o*=128,u>=o&&(u-=Math.pow(2,8*r)),u};f.prototype.readInt8=function(t,r){return t=t>>>0,r||w(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};f.prototype.readInt16LE=function(t,r){t=t>>>0,r||w(t,2,this.length);let i=this[t]|this[t+1]<<8;return i&32768?i|4294901760:i};f.prototype.readInt16BE=function(t,r){t=t>>>0,r||w(t,2,this.length);let i=this[t+1]|this[t]<<8;return i&32768?i|4294901760:i};f.prototype.readInt32LE=function(t,r){return t=t>>>0,r||w(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};f.prototype.readInt32BE=function(t,r){return t=t>>>0,r||w(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};f.prototype.readBigInt64LE=b(function(t){t=t>>>0,S(t,"offset");let r=this[t],i=this[t+7];(r===void 0||i===void 0)&&k(t,this.length-8);let n=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(i<<24);return(BigInt(n)<<BigInt(32))+BigInt(r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});f.prototype.readBigInt64BE=b(function(t){t=t>>>0,S(t,"offset");let r=this[t],i=this[t+7];(r===void 0||i===void 0)&&k(t,this.length-8);let n=(r<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+i)});f.prototype.readFloatLE=function(t,r){return t=t>>>0,r||w(t,4,this.length),C.read(this,t,!0,23,4)};f.prototype.readFloatBE=function(t,r){return t=t>>>0,r||w(t,4,this.length),C.read(this,t,!1,23,4)};f.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||w(t,8,this.length),C.read(this,t,!0,52,8)};f.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||w(t,8,this.length),C.read(this,t,!1,52,8)};function d(e,t,r,i,n,o){if(!f.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||t<o)throw new RangeError('"value" argument is out of bounds');if(r+i>e.length)throw new RangeError("Index out of range")}f.prototype.writeUintLE=f.prototype.writeUIntLE=function(t,r,i,n){if(t=+t,r=r>>>0,i=i>>>0,!n){let h=Math.pow(2,8*i)-1;d(this,t,r,i,h,0)}let o=1,u=0;for(this[r]=t&255;++u<i&&(o*=256);)this[r+u]=t/o&255;return r+i};f.prototype.writeUintBE=f.prototype.writeUIntBE=function(t,r,i,n){if(t=+t,r=r>>>0,i=i>>>0,!n){let h=Math.pow(2,8*i)-1;d(this,t,r,i,h,0)}let o=i-1,u=1;for(this[r+o]=t&255;--o>=0&&(u*=256);)this[r+o]=t/u&255;return r+i};f.prototype.writeUint8=f.prototype.writeUInt8=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,1,255,0),this[r]=t&255,r+1};f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2};f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2};f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4};f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function st(e,t,r,i,n){ht(t,i,n,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o=o>>8,e[r++]=o,o=o>>8,e[r++]=o,o=o>>8,e[r++]=o;let u=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=u,u=u>>8,e[r++]=u,u=u>>8,e[r++]=u,u=u>>8,e[r++]=u,r}function lt(e,t,r,i,n){ht(t,i,n,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o=o>>8,e[r+6]=o,o=o>>8,e[r+5]=o,o=o>>8,e[r+4]=o;let u=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=u,u=u>>8,e[r+2]=u,u=u>>8,e[r+1]=u,u=u>>8,e[r]=u,r+8}f.prototype.writeBigUInt64LE=b(function(t,r=0){return st(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});f.prototype.writeBigUInt64BE=b(function(t,r=0){return lt(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});f.prototype.writeIntLE=function(t,r,i,n){if(t=+t,r=r>>>0,!n){let s=Math.pow(2,8*i-1);d(this,t,r,i,s-1,-s)}let o=0,u=1,h=0;for(this[r]=t&255;++o<i&&(u*=256);)t<0&&h===0&&this[r+o-1]!==0&&(h=1),this[r+o]=(t/u>>0)-h&255;return r+i};f.prototype.writeIntBE=function(t,r,i,n){if(t=+t,r=r>>>0,!n){let s=Math.pow(2,8*i-1);d(this,t,r,i,s-1,-s)}let o=i-1,u=1,h=0;for(this[r+o]=t&255;--o>=0&&(u*=256);)t<0&&h===0&&this[r+o+1]!==0&&(h=1),this[r+o]=(t/u>>0)-h&255;return r+i};f.prototype.writeInt8=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1};f.prototype.writeInt16LE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2};f.prototype.writeInt16BE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2};f.prototype.writeInt32LE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4};f.prototype.writeInt32BE=function(t,r,i){return t=+t,r=r>>>0,i||d(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};f.prototype.writeBigInt64LE=b(function(t,r=0){return st(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});f.prototype.writeBigInt64BE=b(function(t,r=0){return lt(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ct(e,t,r,i,n,o){if(r+i>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function pt(e,t,r,i,n){return t=+t,r=r>>>0,n||ct(e,t,r,4,34028234663852886e22,-34028234663852886e22),C.write(e,t,r,i,23,4),r+4}f.prototype.writeFloatLE=function(t,r,i){return pt(this,t,r,!0,i)};f.prototype.writeFloatBE=function(t,r,i){return pt(this,t,r,!1,i)};function at(e,t,r,i,n){return t=+t,r=r>>>0,n||ct(e,t,r,8,17976931348623157e292,-17976931348623157e292),C.write(e,t,r,i,52,8),r+8}f.prototype.writeDoubleLE=function(t,r,i){return at(this,t,r,!0,i)};f.prototype.writeDoubleBE=function(t,r,i){return at(this,t,r,!1,i)};f.prototype.copy=function(t,r,i,n){if(!f.isBuffer(t))throw new TypeError("argument should be a Buffer");if(i||(i=0),!n&&n!==0&&(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n<i&&(n=i),n===i||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r<n-i&&(n=t.length-r+i);let o=n-i;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,i,n):Uint8Array.prototype.set.call(t,this.subarray(i,n),r),o};f.prototype.fill=function(t,r,i,n){if(typeof t=="string"){if(typeof r=="string"?(n=r,r=0,i=this.length):typeof i=="string"&&(n=i,i=this.length),n!==void 0&&typeof n!="string")throw new TypeError("encoding must be a string");if(typeof n=="string"&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(t.length===1){let u=t.charCodeAt(0);(n==="utf8"&&u<128||n==="latin1")&&(t=u)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<i)throw new RangeError("Out of range index");if(i<=r)return this;r=r>>>0,i=i===void 0?this.length:i>>>0,t||(t=0);let o;if(typeof t=="number")for(o=r;o<i;++o)this[o]=t;else{let u=f.isBuffer(t)?t:f.from(t,n),h=u.length;if(h===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<i-r;++o)this[o+r]=u[o%h]}return this};var N={};function V(e,t,r){N[e]=class extends r{constructor(){super();Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(n){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:n,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}V("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);V("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError);V("ERR_OUT_OF_RANGE",function(e,t,r){let i=`The value of "${e}" is out of range.`,n=r;return Number.isInteger(r)&&Math.abs(r)>2**32?n=yt(String(r)):typeof r=="bigint"&&(n=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(n=yt(n)),n+="n"),i+=` It must be ${t}. Received ${n}`,i},RangeError);function yt(e){let t="",r=e.length,i=e[0]==="-"?1:0;for(;r>=i+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function ur(e,t,r){S(t,"offset"),(e[t]===void 0||e[t+r]===void 0)&&k(t,e.length-(r+1))}function ht(e,t,r,i,n,o){if(e>r||e<t){let u=typeof t=="bigint"?"n":"",h;throw o>3?t===0||t===BigInt(0)?h=`>= 0${u} and < 2${u} ** ${(o+1)*8}${u}`:h=`>= -(2${u} ** ${(o+1)*8-1}${u}) and < 2 ** ${(o+1)*8-1}${u}`:h=`>= ${t}${u} and <= ${r}${u}`,new N.ERR_OUT_OF_RANGE("value",h,e)}ur(i,n,o)}function S(e,t){if(typeof e!="number")throw new N.ERR_INVALID_ARG_TYPE(t,"number",e)}function k(e,t,r){throw Math.floor(e)!==e?(S(e,r),new N.ERR_OUT_OF_RANGE(r||"offset","an integer",e)):t<0?new N.ERR_BUFFER_OUT_OF_BOUNDS:new N.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}var fr=/[^+/0-9A-Za-z-_]/g;function hr(e){if(e=e.split("=")[0],e=e.trim().replace(fr,""),e.length<2)return"";for(;e.length%4!=0;)e=e+"=";return e}function H(e,t){t=t||Infinity;let r,i=e.length,n=null,o=[];for(let u=0;u<i;++u){if(r=e.charCodeAt(u),r>55295&&r<57344){if(!n){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}else if(u+1===i){(t-=3)>-1&&o.push(239,191,189);continue}n=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),n=r;continue}r=(n-55296<<10|r-56320)+65536}else n&&(t-=3)>-1&&o.push(239,191,189);if(n=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return o}function vt(e){let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r)&255);return t}function er(e,t){let r,i,n,o=[];for(let u=0;u<e.length&&!((t-=2)<0);++u)r=e.charCodeAt(u),i=r>>8,n=r%256,o.push(n),o.push(i);return o}function it(e){return q.toByteArray(hr(e))}function O(e,t,r,i){let n;for(n=0;n<i&&!(n+r>=t.length||n>=e.length);++n)t[n+r]=e[n];return n}function F(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function z(e){return e!==e}var or=function(){let e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){let i=r*16;for(let n=0;n<16;++n)t[i+n]=e[r]+e[n]}return t}();function b(e){return typeof BigInt=="undefined"?sr:e}function sr(){throw new Error("BigInt not supported")}});var Bt=m((Er,xt)=>{"use strict";var{Buffer:E}=wt(),dt=Symbol.for("BufferList");function y(e){if(!(this instanceof y))return new y(e);y._init.call(this,e)}y._init=function(t){Object.defineProperty(this,dt,{value:!0}),this._bufs=[],this.length=0,t&&this.append(t)};y.prototype._new=function(t){return new y(t)};y.prototype._offset=function(t){if(t===0)return[0,0];let r=0;for(let i=0;i<this._bufs.length;i++){let n=r+this._bufs[i].length;if(t<n||i===this._bufs.length-1)return[i,t-r];r=n}};y.prototype._reverseOffset=function(e){let t=e[0],r=e[1];for(let i=0;i<t;i++)r+=this._bufs[i].length;return r};y.prototype.get=function(t){if(t>this.length||t<0)return;let r=this._offset(t);return this._bufs[r[0]][r[1]]};y.prototype.slice=function(t,r){return typeof t=="number"&&t<0&&(t+=this.length),typeof r=="number"&&r<0&&(r+=this.length),this.copy(null,0,t,r)};y.prototype.copy=function(t,r,i,n){if((typeof i!="number"||i<0)&&(i=0),(typeof n!="number"||n>this.length)&&(n=this.length),i>=this.length||n<=0)return t||E.alloc(0);let o=!!t,u=this._offset(i),h=n-i,s=h,p=o&&r||0,l=u[1];if(i===0&&n===this.length){if(!o)return this._bufs.length===1?this._bufs[0]:E.concat(this._bufs,this.length);for(let c=0;c<this._bufs.length;c++)this._bufs[c].copy(t,p),p+=this._bufs[c].length;return t}if(s<=this._bufs[u[0]].length-l)return o?this._bufs[u[0]].copy(t,r,l,l+s):this._bufs[u[0]].slice(l,l+s);o||(t=E.allocUnsafe(h));for(let c=u[0];c<this._bufs.length;c++){let B=this._bufs[c].length-l;if(s>B)this._bufs[c].copy(t,p,l),p+=B;else{this._bufs[c].copy(t,p,l,l+s),p+=B;break}s-=B,l&&(l=0)}return t.length>p?t.slice(0,p):t};y.prototype.shallowSlice=function(t,r){if(t=t||0,r=typeof r!="number"?this.length:r,t<0&&(t+=this.length),r<0&&(r+=this.length),t===r)return this._new();let i=this._offset(t),n=this._offset(r),o=this._bufs.slice(i[0],n[0]+1);return n[1]===0?o.pop():o[o.length-1]=o[o.length-1].slice(0,n[1]),i[1]!==0&&(o[0]=o[0].slice(i[1])),this._new(o)};y.prototype.toString=function(t,r,i){return this.slice(r,i).toString(t)};y.prototype.consume=function(t){if(t=Math.trunc(t),Number.isNaN(t)||t<=0)return this;for(;this._bufs.length;)if(t>=this._bufs[0].length)t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift();else{this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}return this};y.prototype.duplicate=function(){let t=this._new();for(let r=0;r<this._bufs.length;r++)t.append(this._bufs[r]);return t};y.prototype.append=function(t){if(t==null)return this;if(t.buffer)this._appendBuffer(E.from(t.buffer,t.byteOffset,t.byteLength));else if(Array.isArray(t))for(let r=0;r<t.length;r++)this.append(t[r]);else if(this._isBufferList(t))for(let r=0;r<t._bufs.length;r++)this.append(t._bufs[r]);else typeof t=="number"&&(t=t.toString()),this._appendBuffer(E.from(t));return this};y.prototype._appendBuffer=function(t){this._bufs.push(t),this.length+=t.length};y.prototype.indexOf=function(e,t,r){if(r===void 0&&typeof t=="string"&&(r=t,t=void 0),typeof e=="function"||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if(typeof e=="number"?e=E.from([e]):typeof e=="string"?e=E.from(e,r):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=E.from(e.buffer,e.byteOffset,e.byteLength):E.isBuffer(e)||(e=E.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let i=this._offset(t),n=i[0],o=i[1];for(;n<this._bufs.length;n++){let u=this._bufs[n];for(;o<u.length;)if(u.length-o>=e.length){let s=u.indexOf(e,o);if(s!==-1)return this._reverseOffset([n,s]);o=u.length-e.length+1}else{let s=this._reverseOffset([n,o]);if(this._match(s,e))return s;o++}o=0}return-1};y.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let r=0;r<t.length;r++)if(this.get(e+r)!==t[r])return!1;return!0};(function(){let e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(let t in e)(function(r){e[r]===null?y.prototype[r]=function(i,n){return this.slice(i,i+n)[r](0,n)}:y.prototype[r]=function(i=0){return this.slice(i,i+e[r])[r](0)}})(t)})();y.prototype._isBufferList=function(t){return t instanceof y||y.isBufferList(t)};y.isBufferList=function(t){return t!=null&&t[dt]};xt.exports=y});var Et=m((mr,gt)=>{var X=Bt();gt.exports=e=>{let t=async function*(){let r=yield,i=new X;for await(let n of e){if(!r){r=yield i.append(n),i=new X;continue}for(i.append(n);i.length>=r;){let o=i.shallowSlice(0,r);if(i.consume(r),r=yield o,!r){i.length&&(r=yield i,i=new X);break}}}if(r)throw Object.assign(new Error(`stream ended before ${r} bytes became available`),{code:"ERR_UNDER_READ",buffer:i})}();return t.next(),t}});var It=m((Fr,mt)=>{mt.exports=class{constructor(t){if(!(t>0)||(t-1&t)!=0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}}});var _t=m((_r,Ft)=>{var At=It();Ft.exports=class{constructor(t){this.hwm=t||16,this.head=new At(this.hwm),this.tail=this.head}push(t){if(!this.head.push(t)){let r=this.head;this.head=r.next=new At(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next){let r=this.tail.next;return this.tail.next=null,this.tail=r,this.tail.shift()}return t}isEmpty(){return this.head.isEmpty()}}});var bt=m((Ur,Ut)=>{var J=_t();Ut.exports=e=>{e=e||{};let t;typeof e=="function"?(t=e,e={}):t=e.onEnd;let r=new J,i,n,o,u=()=>{if(!r.isEmpty()){if(e.writev){let A,_=[];for(;!r.isEmpty();){if(A=r.shift(),A.error)throw A.error;_.push(A.value)}return{done:A.done,value:_}}let a=r.shift();if(a.error)throw a.error;return a}return o?{done:!0}:new Promise((a,A)=>{n=_=>(n=null,_.error?A(_.error):e.writev&&!_.done?a({done:_.done,value:[_.value]}):a(_),i)})},h=a=>n?n(a):(r.push(a),i),s=a=>(r=new J,n?n({error:a}):(r.push({error:a}),i)),p=a=>o?i:h({done:!1,value:a}),l=a=>o?i:(o=!0,a?s(a):h({done:!0})),c=()=>(r=new J,l(),{done:!0}),B=a=>(l(a),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:u,return:c,throw:B,push:p,end:l},!t)return i;let x=i;return i={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(a){return x.throw(a),t&&(t(a),t=null),{done:!0}},return(){return x.return(),t&&(t(),t=null),{done:!0}},push:p,end(a){return x.end(a),t&&(t(a),t=null),i}},i}});var Tt=m((br,Rt)=>{"use strict";var lr=()=>{let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e};Rt.exports=lr});var yr=m((Rr,Lt)=>{"use strict";var cr=Et(),pr=bt(),ar=Tt();Lt.exports=e=>{let t=pr(),r=cr(e.source),i=ar(),n,o=e.sink(async function*(){yield*t,yield*await i.promise}());return o.catch(h=>{n=h}),{reader:r,writer:t,stream:{sink:h=>n?Promise.reject(n):(i.resolve(h),o),source:r},rest:()=>t.end(),write:t.push,read:async()=>(await r.next()).value}}});return yr();})();
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
return ItHandshake}));
'use strict'
const Reader = require('it-reader')
const Writer = require('it-pushable')
const defer = require('p-defer')
// Convert a duplex stream into a reader and writer and rest stream
module.exports = stream => {
const writer = Writer() // Write bytes on demand to the sink
const reader = Reader(stream.source) // Read bytes on demand from the source
// Waits for a source to be passed to the rest stream's sink
const sourcePromise = defer()
let sinkErr
const sinkPromise = stream.sink((async function * () {
yield * writer
const source = await sourcePromise.promise
yield * source
})())
sinkPromise.catch(err => {
sinkErr = err
})
const rest = {
sink: source => {
if (sinkErr) {
return Promise.reject(sinkErr)
}
sourcePromise.resolve(source)
return sinkPromise
},
source: reader
}
return {
reader,
writer,
stream: rest,
rest: () => writer.end(),
write: writer.push,
read: async () => {
return (await reader.next()).value
}
}
}