New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

it-pb-stream

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-pb-stream - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

2

dist/index.min.js
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ItPbStream = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var ItPbStream=(()=>{var K=Object.create;var D=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),nt=(i,t)=>{for(var e in t)D(i,e,{get:t[e],enumerable:!0})},M=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Y(t))!tt.call(i,r)&&r!==e&&D(i,r,{get:()=>t[r],enumerable:!(n=Q(t,r))||n.enumerable});return i};var rt=(i,t,e)=>(e=i!=null?K(Z(i)):{},M(t||!i||!i.__esModule?D(e,"default",{value:i,enumerable:!0}):e,i)),it=i=>M(D({},"__esModule",{value:!0}),i);var $=et((te,X)=>{"use strict";function C(i,t){for(let e in t)Object.defineProperty(i,e,{value:t[e],enumerable:!0,configurable:!0});return i}function wt(i,t,e){if(!i||typeof i=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return C(i,e)}catch{e.message=i.message,e.stack=i.stack;let r=function(){};return r.prototype=Object.create(Object.getPrototypeOf(i)),C(new r,e)}}X.exports=wt});var Lt={};nt(Lt,{pbStream:()=>pt});function A(i){return globalThis.Buffer!=null?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):i}function b(i=0){return globalThis.Buffer?.alloc!=null?A(globalThis.Buffer.alloc(i)):new Uint8Array(i)}function y(i=0){return globalThis.Buffer?.allocUnsafe!=null?A(globalThis.Buffer.allocUnsafe(i)):new Uint8Array(i)}function V(i,t){t==null&&(t=i.reduce((r,s)=>r+s.length,0));let e=y(t),n=0;for(let r of i)e.set(r,n),n+=r.length;return A(e)}function P(i,t){if(i===t)return!0;if(i.byteLength!==t.byteLength)return!1;for(let e=0;e<i.byteLength;e++)if(i[e]!==t[e])return!1;return!0}var S=Symbol.for("@achingbrain/uint8arraylist");function G(i,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of i){let r=e+n.byteLength;if(t<r)return{buf:n,index:t-e};e=r}throw new RangeError("index is out of bounds")}function B(i){return Boolean(i?.[S])}var l=class{constructor(...t){Object.defineProperty(this,S,{value:!0}),this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(B(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(B(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=G(this.bufs,t);return e.buf[e.index]}set(t,e){let n=G(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(B(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:r}=this._subList(t,e);return V(n,r)}subarray(t,e){let{bufs:n,length:r}=this._subList(t,e);return n.length===1?n[0]:V(n,r)}sublist(t,e){let{bufs:n,length:r}=this._subList(t,e),s=new l;return s.length=r,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],r=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],u=r,c=u+o.byteLength;if(r=c,t>=c)continue;let w=t>=u&&t<c,f=e>u&&e<=c;if(w&&f){if(t===u&&e===c){n.push(o);break}let a=t-u;n.push(o.subarray(a,a+(e-t)));break}if(w){if(t===0){n.push(o);continue}n.push(o.subarray(t-u));continue}if(f){if(e===c){n.push(o);break}n.push(o.subarray(0,e-u));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!B(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let r=n.byteLength;if(r===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let a=0;a<s;a++)o[a]=-1;for(let a=0;a<r;a++)o[n[a]]=a;let u=o,c=this.byteLength-n.byteLength,w=n.byteLength-1,f;for(let a=e;a<=c;a+=f){f=0;for(let d=w;d>=0;d--){let N=this.get(a+d);if(n[d]!==N){f=Math.max(1,d-u[N]);break}}if(f===0)return a}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let r=b(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt16(0,e,n),this.write(r,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let r=b(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt32(0,e,n),this.write(r,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let r=b(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigInt64(0,e,n),this.write(r,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let r=b(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint16(0,e,n),this.write(r,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let r=b(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint32(0,e,n),this.write(r,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let r=b(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigUint64(0,e,n),this.write(r,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let r=b(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat32(0,e,n),this.write(r,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let r=b(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat64(0,e,n),this.write(r,t)}equals(t){if(t==null||!(t instanceof l)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!P(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new l;return n.bufs=t,e==null&&(e=t.reduce((r,s)=>r+s.byteLength,0)),n.length=e,n}};function v(i){let t=async function*(){let e=yield,n=new l;for await(let r of i){if(e==null){n.append(r),e=yield n,n=new l;continue}for(n.append(r);n.length>=e;){let s=n.sublist(0,e);if(n.consume(e),e=yield s,e==null){n.length>0&&(e=yield n,n=new l);break}}}if(e!=null)throw Object.assign(new Error(`stream ended before ${e} bytes became available`),{code:"ERR_UNDER_READ",buffer:n})}();return t.next(),t}var T=class{constructor(t){if(!(t>0)||t-1&t)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}},L=class{constructor(t={}){this.hwm=t.splitLimit??16,this.head=new T(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new T(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};function z(i={}){return st(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},i)}function st(i,t){t=t??{};let e=t.onEnd,n=new L,r,s,o,u=async()=>n.isEmpty()?o?{done:!0}:await new Promise((h,q)=>{s=W=>{s=null,n.push(W);try{h(i(n))}catch(J){q(J)}return r}}):i(n),c=h=>s!=null?s(h):(n.push(h),r),w=h=>(n=new L,s!=null?s({error:h}):(n.push({error:h}),r)),f=h=>{if(o)return r;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:h})},a=h=>o?r:(o=!0,h!=null?w(h):c({done:!0})),d=()=>(n=new L,a(),{done:!0}),N=h=>(a(h),{done:!0});if(r={[Symbol.asyncIterator](){return this},next:u,return:d,throw:N,push:f,end:a,get readableLength(){return n.size}},e==null)return r;let E=r;return r={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(h){return E.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(h){return E.end(h),e!=null&&(e(h),e=void 0),r},get readableLength(){return E.readableLength}},r}function _(){let i={};return i.promise=new Promise((t,e)=>{i.resolve=t,i.reject=e}),i}function F(i){let t=z(),e=v(i.source),n=_(),r,s=i.sink(async function*(){yield*t,yield*await n.promise}());return s.catch(u=>{r=u}),{reader:e,writer:t,stream:{sink:async u=>r!=null?await Promise.reject(r):(n.resolve(u),await s),source:e},rest:()=>t.end(),write:t.push,read:async()=>{let u=await e.next();if(u.value!=null)return u.value}}}function k(i){return i instanceof Uint8Array?{get(t){return i[t]},set(t,e){i[t]=e}}:{get(t){return i.get(t)},set(t,e){i.set(t,e)}}}var j=4294967296,g=class{constructor(t=0,e=0){this.hi=t,this.lo=e}toBigInt(t){if(t===!0)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toNumber(t){return Number(this.toBigInt(t))}zzDecode(){let t=-(this.lo&1),e=((this.lo>>>1|this.hi<<31)^t)>>>0,n=(this.hi>>>1^t)>>>0;return new g(n,e)}zzEncode(){let t=this.hi>>31,e=((this.hi<<1|this.lo>>>31)^t)>>>0,n=(this.lo<<1^t)>>>0;return new g(e,n)}toBytes(t,e=0){let n=k(t);for(;this.hi>0;)n.set(e++,this.lo&127|128),this.lo=(this.lo>>>7|this.hi<<25)>>>0,this.hi>>>=7;for(;this.lo>127;)n.set(e++,this.lo&127|128),this.lo=this.lo>>>7;n.set(e++,this.lo)}static fromBigInt(t){if(t===0n)return new g;let e=t<0;e&&(t=-t);let n=Number(t>>32n)|0,r=Number(t-(BigInt(n)<<32n))|0;return e&&(n=~n>>>0,r=~r>>>0,++r>j&&(r=0,++n>j&&(n=0))),new g(n,r)}static fromNumber(t){if(t===0)return new g;let e=t<0;e&&(t=-t);let n=t>>>0,r=(t-n)/4294967296>>>0;return e&&(r=~r>>>0,n=~n>>>0,++n>4294967295&&(n=0,++r>4294967295&&(r=0))),new g(r,n)}static fromBytes(t,e=0){let n=k(t),r=new g,s=0;if(t.length-e>4){for(;s<4;++s)if(r.lo=(r.lo|(n.get(e)&127)<<s*7)>>>0,n.get(e++)<128)return r;if(r.lo=(r.lo|(n.get(e)&127)<<28)>>>0,r.hi=(r.hi|(n.get(e)&127)>>4)>>>0,n.get(e++)<128)return r;s=0}else for(;s<4;++s){if(e>=t.length)throw RangeError(`index out of range: ${e} > ${t.length}`);if(r.lo=(r.lo|(n.get(e)&127)<<s*7)>>>0,n.get(e++)<128)return r}if(t.length-e>4){for(;s<5;++s)if(r.hi=(r.hi|(n.get(e)&127)<<s*7+3)>>>0,n.get(e++)<128)return r}else if(e<t.byteLength)for(;s<5;++s){if(e>=t.length)throw RangeError(`index out of range: ${e} > ${t.length}`);if(r.hi=(r.hi|(n.get(e)&127)<<s*7+3)>>>0,n.get(e++)<128)return r}throw RangeError("invalid varint encoding")}};var ot=Math.pow(2,7),ut=Math.pow(2,14),ht=Math.pow(2,21),at=Math.pow(2,28),ft=Math.pow(2,35),lt=Math.pow(2,42),ct=Math.pow(2,49),gt=Math.pow(2,56),bt=Math.pow(2,63),m={encodingLength(i){return i<ot?1:i<ut?2:i<ht?3:i<at?4:i<ft?5:i<lt?6:i<ct?7:i<gt?8:i<bt?9:10},encode(i,t,e=0){if(Number.MAX_SAFE_INTEGER!=null&&i>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return t==null&&(t=y(m.encodingLength(i))),g.fromNumber(i).toBytes(t,e),t},decode(i,t=0){return g.fromBytes(i,t).toNumber(!0)}};function H(i){return globalThis?.Buffer?.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(i):new Uint8Array(i)}var O=i=>{let t=m.encodingLength(i),e=H(t);return m.encode(i,e),O.bytes=t,e};O.bytes=0;function R(i){i=i??{};let t=i.lengthEncoder??O;return async function*(n){for await(let r of n){let s=t(r.byteLength);s instanceof Uint8Array?yield s:yield*s,r instanceof Uint8Array?yield r:yield*r}}}R.single=(i,t)=>{t=t??{};let e=t.lengthEncoder??O;return new l(e(i.byteLength),i)};var U=rt($(),1),dt=8,yt=1024*1024*4,p;(function(i){i[i.LENGTH=0]="LENGTH",i[i.DATA=1]="DATA"})(p||(p={}));var I=i=>{let t=m.decode(i);return I.bytes=m.encodingLength(t),t};I.bytes=0;function x(i){return async function*(e){let n=new l,r=p.LENGTH,s=-1,o=i?.lengthDecoder??I,u=i?.maxLengthLength??dt,c=i?.maxDataLength??yt;for await(let w of e)for(n.append(w);n.byteLength>0;){if(r===p.LENGTH)try{if(s=o(n),s<0)throw(0,U.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>c)throw(0,U.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=o.bytes;n.consume(f),i?.onLength!=null&&i.onLength(s),r=p.DATA}catch(f){if(f instanceof RangeError){if(n.byteLength>u)throw(0,U.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(r===p.DATA){if(n.byteLength<s)break;let f=n.sublist(0,s);n.consume(s),i?.onData!=null&&i.onData(f),yield f,r=p.LENGTH}}if(n.byteLength>0)throw(0,U.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}}x.fromReader=(i,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:o}=await i.next(e);if(s===!0)return;o!=null&&(yield o)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return x({...t??{},onLength:s=>{e=s}})(n)};function pt(i,t={}){let e=F(i),n=x.fromReader(e.reader,t),r={read:async s=>{let{value:o}=await e.reader.next(s);if(o==null)throw new Error("Value is null");return o},readLP:async()=>{let{value:s}=await n.next();if(s==null)throw new Error("Value is null");return s},readPB:async s=>{let o=await r.readLP();if(o==null)throw new Error("Value is null");let u=o instanceof Uint8Array?o:o.subarray();return s.decode(u)},write:s=>{s instanceof Uint8Array?e.writer.push(s):e.writer.push(s.subarray())},writeLP:s=>{r.write(R.single(s,t))},writePB:(s,o)=>{r.writeLP(o.encode(s))},pb:s=>({read:async()=>await r.readPB(s),write:o=>{r.writePB(o,s)}}),unwrap:()=>(e.rest(),e.stream)};return r}return it(Lt);})();
"use strict";var ItPbStream=(()=>{var K=Object.create;var D=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),nt=(i,t)=>{for(var e in t)D(i,e,{get:t[e],enumerable:!0})},M=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Y(t))!tt.call(i,r)&&r!==e&&D(i,r,{get:()=>t[r],enumerable:!(n=Q(t,r))||n.enumerable});return i};var rt=(i,t,e)=>(e=i!=null?K(Z(i)):{},M(t||!i||!i.__esModule?D(e,"default",{value:i,enumerable:!0}):e,i)),it=i=>M(D({},"__esModule",{value:!0}),i);var $=et((te,X)=>{"use strict";function C(i,t){for(let e in t)Object.defineProperty(i,e,{value:t[e],enumerable:!0,configurable:!0});return i}function wt(i,t,e){if(!i||typeof i=="string")throw new TypeError("Please pass an Error to err-code");e||(e={}),typeof t=="object"&&(e=t,t=""),t&&(e.code=t);try{return C(i,e)}catch{e.message=i.message,e.stack=i.stack;let r=function(){};return r.prototype=Object.create(Object.getPrototypeOf(i)),C(new r,e)}}X.exports=wt});var Lt={};nt(Lt,{pbStream:()=>pt});function A(i){return globalThis.Buffer!=null?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):i}function b(i=0){return globalThis.Buffer?.alloc!=null?A(globalThis.Buffer.alloc(i)):new Uint8Array(i)}function y(i=0){return globalThis.Buffer?.allocUnsafe!=null?A(globalThis.Buffer.allocUnsafe(i)):new Uint8Array(i)}function V(i,t){t==null&&(t=i.reduce((r,s)=>r+s.length,0));let e=y(t),n=0;for(let r of i)e.set(r,n),n+=r.length;return A(e)}function P(i,t){if(i===t)return!0;if(i.byteLength!==t.byteLength)return!1;for(let e=0;e<i.byteLength;e++)if(i[e]!==t[e])return!1;return!0}var S=Symbol.for("@achingbrain/uint8arraylist");function G(i,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of i){let r=e+n.byteLength;if(t<r)return{buf:n,index:t-e};e=r}throw new RangeError("index is out of bounds")}function B(i){return Boolean(i?.[S])}var l=class{constructor(...t){Object.defineProperty(this,S,{value:!0}),this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(B(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(B(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=G(this.bufs,t);return e.buf[e.index]}set(t,e){let n=G(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(B(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:r}=this._subList(t,e);return V(n,r)}subarray(t,e){let{bufs:n,length:r}=this._subList(t,e);return n.length===1?n[0]:V(n,r)}sublist(t,e){let{bufs:n,length:r}=this._subList(t,e),s=new l;return s.length=r,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],r=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],u=r,c=u+o.byteLength;if(r=c,t>=c)continue;let w=t>=u&&t<c,f=e>u&&e<=c;if(w&&f){if(t===u&&e===c){n.push(o);break}let a=t-u;n.push(o.subarray(a,a+(e-t)));break}if(w){if(t===0){n.push(o);continue}n.push(o.subarray(t-u));continue}if(f){if(e===c){n.push(o);break}n.push(o.subarray(0,e-u));break}n.push(o)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!B(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let r=n.byteLength;if(r===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let a=0;a<s;a++)o[a]=-1;for(let a=0;a<r;a++)o[n[a]]=a;let u=o,c=this.byteLength-n.byteLength,w=n.byteLength-1,f;for(let a=e;a<=c;a+=f){f=0;for(let d=w;d>=0;d--){let x=this.get(a+d);if(n[d]!==x){f=Math.max(1,d-u[x]);break}}if(f===0)return a}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let r=b(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt16(0,e,n),this.write(r,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let r=b(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setInt32(0,e,n),this.write(r,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let r=b(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigInt64(0,e,n),this.write(r,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=y(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let r=b(2);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint16(0,e,n),this.write(r,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let r=b(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setUint32(0,e,n),this.write(r,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let r=b(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setBigUint64(0,e,n),this.write(r,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let r=b(4);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat32(0,e,n),this.write(r,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let r=b(8);new DataView(r.buffer,r.byteOffset,r.byteLength).setFloat64(0,e,n),this.write(r,t)}equals(t){if(t==null||!(t instanceof l)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!P(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new l;return n.bufs=t,e==null&&(e=t.reduce((r,s)=>r+s.byteLength,0)),n.length=e,n}};function v(i){let t=async function*(){let e=yield,n=new l;for await(let r of i){if(e==null){n.append(r),e=yield n,n=new l;continue}for(n.append(r);n.length>=e;){let s=n.sublist(0,e);if(n.consume(e),e=yield s,e==null){n.length>0&&(e=yield n,n=new l);break}}}if(e!=null)throw Object.assign(new Error(`stream ended before ${e} bytes became available`),{code:"ERR_UNDER_READ",buffer:n})}();return t.next(),t}var T=class{constructor(t){if(!(t>0)||t-1&t)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}},L=class{constructor(t={}){this.hwm=t.splitLimit??16,this.head=new T(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new T(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};function z(i={}){return st(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},i)}function st(i,t){t=t??{};let e=t.onEnd,n=new L,r,s,o,u=async()=>n.isEmpty()?o?{done:!0}:await new Promise((h,q)=>{s=W=>{s=null,n.push(W);try{h(i(n))}catch(J){q(J)}return r}}):i(n),c=h=>s!=null?s(h):(n.push(h),r),w=h=>(n=new L,s!=null?s({error:h}):(n.push({error:h}),r)),f=h=>{if(o)return r;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:h})},a=h=>o?r:(o=!0,h!=null?w(h):c({done:!0})),d=()=>(n=new L,a(),{done:!0}),x=h=>(a(h),{done:!0});if(r={[Symbol.asyncIterator](){return this},next:u,return:d,throw:x,push:f,end:a,get readableLength(){return n.size}},e==null)return r;let E=r;return r={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(h){return E.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(h){return E.end(h),e!=null&&(e(h),e=void 0),r},get readableLength(){return E.readableLength}},r}function _(){let i={};return i.promise=new Promise((t,e)=>{i.resolve=t,i.reject=e}),i}function F(i){let t=z(),e=v(i.source),n=_(),r,s=i.sink(async function*(){yield*t,yield*await n.promise}());return s.catch(u=>{r=u}),{reader:e,writer:t,stream:{sink:async u=>r!=null?await Promise.reject(r):(n.resolve(u),await s),source:e},rest:()=>t.end(),write:t.push,read:async()=>{let u=await e.next();if(u.value!=null)return u.value}}}function k(i){return i instanceof Uint8Array?{get(t){return i[t]},set(t,e){i[t]=e}}:{get(t){return i.get(t)},set(t,e){i.set(t,e)}}}var j=4294967296,g=class{constructor(t=0,e=0){this.hi=t,this.lo=e}toBigInt(t){if(t===!0)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toNumber(t){return Number(this.toBigInt(t))}zzDecode(){let t=-(this.lo&1),e=((this.lo>>>1|this.hi<<31)^t)>>>0,n=(this.hi>>>1^t)>>>0;return new g(n,e)}zzEncode(){let t=this.hi>>31,e=((this.hi<<1|this.lo>>>31)^t)>>>0,n=(this.lo<<1^t)>>>0;return new g(e,n)}toBytes(t,e=0){let n=k(t);for(;this.hi>0;)n.set(e++,this.lo&127|128),this.lo=(this.lo>>>7|this.hi<<25)>>>0,this.hi>>>=7;for(;this.lo>127;)n.set(e++,this.lo&127|128),this.lo=this.lo>>>7;n.set(e++,this.lo)}static fromBigInt(t){if(t===0n)return new g;let e=t<0;e&&(t=-t);let n=Number(t>>32n)|0,r=Number(t-(BigInt(n)<<32n))|0;return e&&(n=~n>>>0,r=~r>>>0,++r>j&&(r=0,++n>j&&(n=0))),new g(n,r)}static fromNumber(t){if(t===0)return new g;let e=t<0;e&&(t=-t);let n=t>>>0,r=(t-n)/4294967296>>>0;return e&&(r=~r>>>0,n=~n>>>0,++n>4294967295&&(n=0,++r>4294967295&&(r=0))),new g(r,n)}static fromBytes(t,e=0){let n=k(t),r=new g,s=0;if(t.length-e>4){for(;s<4;++s)if(r.lo=(r.lo|(n.get(e)&127)<<s*7)>>>0,n.get(e++)<128)return r;if(r.lo=(r.lo|(n.get(e)&127)<<28)>>>0,r.hi=(r.hi|(n.get(e)&127)>>4)>>>0,n.get(e++)<128)return r;s=0}else for(;s<4;++s){if(e>=t.length)throw RangeError(`index out of range: ${e} > ${t.length}`);if(r.lo=(r.lo|(n.get(e)&127)<<s*7)>>>0,n.get(e++)<128)return r}if(t.length-e>4){for(;s<5;++s)if(r.hi=(r.hi|(n.get(e)&127)<<s*7+3)>>>0,n.get(e++)<128)return r}else if(e<t.byteLength)for(;s<5;++s){if(e>=t.length)throw RangeError(`index out of range: ${e} > ${t.length}`);if(r.hi=(r.hi|(n.get(e)&127)<<s*7+3)>>>0,n.get(e++)<128)return r}throw RangeError("invalid varint encoding")}};var ot=Math.pow(2,7),ut=Math.pow(2,14),ht=Math.pow(2,21),at=Math.pow(2,28),ft=Math.pow(2,35),lt=Math.pow(2,42),ct=Math.pow(2,49),gt=Math.pow(2,56),bt=Math.pow(2,63),m={encodingLength(i){return i<ot?1:i<ut?2:i<ht?3:i<at?4:i<ft?5:i<lt?6:i<ct?7:i<gt?8:i<bt?9:10},encode(i,t,e=0){if(Number.MAX_SAFE_INTEGER!=null&&i>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return t==null&&(t=y(m.encodingLength(i))),g.fromNumber(i).toBytes(t,e),t},decode(i,t=0){return g.fromBytes(i,t).toNumber(!0)}};function H(i){return globalThis?.Buffer?.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(i):new Uint8Array(i)}var O=i=>{let t=m.encodingLength(i),e=H(t);return m.encode(i,e),O.bytes=t,e};O.bytes=0;function R(i){i=i??{};let t=i.lengthEncoder??O;return async function*(n){for await(let r of n){let s=t(r.byteLength);s instanceof Uint8Array?yield s:yield*s,r instanceof Uint8Array?yield r:yield*r}}}R.single=(i,t)=>{t=t??{};let e=t.lengthEncoder??O;return new l(e(i.byteLength),i)};var U=rt($(),1),dt=8,yt=1024*1024*4,p;(function(i){i[i.LENGTH=0]="LENGTH",i[i.DATA=1]="DATA"})(p||(p={}));var I=i=>{let t=m.decode(i);return I.bytes=m.encodingLength(t),t};I.bytes=0;function N(i){return async function*(e){let n=new l,r=p.LENGTH,s=-1,o=i?.lengthDecoder??I,u=i?.maxLengthLength??dt,c=i?.maxDataLength??yt;for await(let w of e)for(n.append(w);n.byteLength>0;){if(r===p.LENGTH)try{if(s=o(n),s<0)throw(0,U.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>c)throw(0,U.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=o.bytes;n.consume(f),i?.onLength!=null&&i.onLength(s),r=p.DATA}catch(f){if(f instanceof RangeError){if(n.byteLength>u)throw(0,U.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(r===p.DATA){if(n.byteLength<s)break;let f=n.sublist(0,s);n.consume(s),i?.onData!=null&&i.onData(f),yield f,r=p.LENGTH}}if(n.byteLength>0)throw(0,U.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}}N.fromReader=(i,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:o}=await i.next(e);if(s===!0)return;o!=null&&(yield o)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return N({...t??{},onLength:s=>{e=s}})(n)};function pt(i,t={}){let e=F(i),n=N.fromReader(e.reader,t),r={read:async s=>{let{value:o}=await e.reader.next(s);if(o==null)throw new Error("Value is null");return o},readLP:async()=>{let{value:s}=await n.next();if(s==null)throw new Error("Value is null");return s},readPB:async s=>{let o=await r.readLP();if(o==null)throw new Error("Value is null");let u=o instanceof Uint8Array?o:o.subarray();return s.decode(u)},write:s=>{s instanceof Uint8Array?e.writer.push(s):e.writer.push(s.subarray())},writeLP:s=>{r.write(R.single(s,t))},writePB:(s,o)=>{r.writeLP(o.encode(s))},pb:s=>({read:async()=>await r.readPB(s),write:o=>{r.writePB(o,s)}}),unwrap:()=>(e.rest(),i.source=e.stream.source,i.sink=e.stream.sink,i)};return r}return it(Lt);})();
return ItPbStream}));

@@ -41,3 +41,3 @@ /**

*/
export interface ProtobufStream<TSink> {
export interface ProtobufStream<Stream extends Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> = Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>> {
/**

@@ -84,3 +84,3 @@ * Read a set number of bytes from the stream

*/
unwrap: () => Duplex<Uint8ArrayList, TSink>;
unwrap: () => Stream;
}

@@ -95,3 +95,4 @@ export interface Opts {

}
export declare function pbStream<TSink extends Uint8Array | Uint8ArrayList>(duplex: Duplex<Uint8ArrayList | Uint8Array, TSink>, opts?: {}): ProtobufStream<TSink>;
export declare function pbStream<Stream extends Duplex<Uint8ArrayList, Uint8Array | Uint8ArrayList>>(duplex: Stream, opts?: Partial<Opts>): ProtobufStream<Stream>;
export declare function pbStream<Stream extends Duplex<Uint8ArrayList, Uint8Array | Uint8ArrayList>>(duplex: Duplex<Uint8Array>, opts?: Partial<Opts>): ProtobufStream<Stream>;
//# sourceMappingURL=index.d.ts.map

@@ -59,7 +59,5 @@ /**

if (data instanceof Uint8Array) {
// @ts-expect-error writer should always accept pushing Uint8Arrays
shake.writer.push(data);
}
else {
// @ts-expect-error writer should always accept pushing Uint8Arrays
shake.writer.push(data.subarray());

@@ -85,3 +83,5 @@ }

shake.rest();
return shake.stream;
duplex.source = shake.stream.source;
duplex.sink = shake.stream.sink;
return duplex;
}

@@ -88,0 +88,0 @@ };

{
"name": "it-pb-stream",
"version": "3.0.0",
"version": "3.0.1",
"description": "A convenience-wrapper around protocol-buffers and lp-messages functions",

@@ -5,0 +5,0 @@ "author": "Alex Potsides <alex@achingbrain.net>",

@@ -46,3 +46,3 @@ /**

*/
export interface ProtobufStream <TSink> {
export interface ProtobufStream <Stream extends Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> = Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>> {
/**

@@ -86,3 +86,3 @@ * Read a set number of bytes from the stream

*/
unwrap: () => Duplex<Uint8ArrayList, TSink>
unwrap: () => Stream
}

@@ -102,4 +102,6 @@

export function pbStream <TSink extends Uint8Array | Uint8ArrayList> (duplex: Duplex<Uint8ArrayList | Uint8Array, TSink>, opts = {}): ProtobufStream<TSink> {
const shake = handshake(duplex)
export function pbStream <Stream extends Duplex<Uint8ArrayList, Uint8Array | Uint8ArrayList>> (duplex: Stream, opts?: Partial<Opts>): ProtobufStream<Stream>
export function pbStream <Stream extends Duplex<Uint8ArrayList, Uint8Array | Uint8ArrayList>> (duplex: Duplex<Uint8Array>, opts?: Partial<Opts>): ProtobufStream<Stream>
export function pbStream (duplex: any, opts = {}): ProtobufStream<any> {
const shake = handshake<Uint8Array>(duplex)
const lpReader = lp.decode.fromReader(

@@ -110,3 +112,3 @@ shake.reader,

const W: ProtobufStream<TSink> = {
const W: ProtobufStream<any> = {
read: async (bytes) => {

@@ -149,6 +151,4 @@ // just read

if (data instanceof Uint8Array) {
// @ts-expect-error writer should always accept pushing Uint8Arrays
shake.writer.push(data)
} else {
// @ts-expect-error writer should always accept pushing Uint8Arrays
shake.writer.push(data.subarray())

@@ -174,3 +174,7 @@ }

shake.rest()
return shake.stream
duplex.source = shake.stream.source
duplex.sink = shake.stream.sink
return duplex
}

@@ -177,0 +181,0 @@ }

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc