it-length-prefixed
Advanced tools
Comparing version 9.0.3 to 9.0.4
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ItLengthPrefixed = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var ItLengthPrefixed=(()=>{var Y=Object.create;var U=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var Z=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),$=(r,t)=>{for(var e in t)U(r,e,{get:t[e],enumerable:!0})},M=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of K(t))!W.call(r,i)&&i!==e&&U(r,i,{get:()=>t[i],enumerable:!(n=J(t,i))||n.enumerable});return r};var z=(r,t,e)=>(e=r!=null?Y(Q(r)):{},M(t||!r||!r.__esModule?U(e,"default",{value:r,enumerable:!0}):e,r)),v=r=>M(U({},"__esModule",{value:!0}),r);var q=Z((_t,X)=>{"use strict";function j(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function at(r,t,e){if(!r||typeof r=="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 j(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),j(new i,e)}}X.exports=at});var ct={};$(ct,{decode:()=>D,encode:()=>V});function A(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function l(r=0){return globalThis.Buffer?.alloc!=null?A(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function w(r=0){return globalThis.Buffer?.allocUnsafe!=null?A(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var tt=Math.pow(2,7),et=Math.pow(2,14),nt=Math.pow(2,21),N=Math.pow(2,28),T=Math.pow(2,35),_=Math.pow(2,42),O=Math.pow(2,49),o=128,c=127;function y(r){if(r<tt)return 1;if(r<et)return 2;if(r<nt)return 3;if(r<N)return 4;if(r<T)return 5;if(r<_)return 6;if(r<O)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rt(r,t,e=0){switch(y(r)){case 8:t[e++]=r&255|o,r/=128;case 7:t[e++]=r&255|o,r/=128;case 6:t[e++]=r&255|o,r/=128;case 5:t[e++]=r&255|o,r/=128;case 4:t[e++]=r&255|o,r>>>=7;case 3:t[e++]=r&255|o,r>>>=7;case 2:t[e++]=r&255|o,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function it(r,t,e=0){switch(y(r)){case 8:t.set(e++,r&255|o),r/=128;case 7:t.set(e++,r&255|o),r/=128;case 6:t.set(e++,r&255|o),r/=128;case 5:t.set(e++,r&255|o),r/=128;case 4:t.set(e++,r&255|o),r>>>=7;case 3:t.set(e++,r&255|o),r>>>=7;case 2:t.set(e++,r&255|o),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function st(r,t){let e=r[t],n=0;if(n+=e&c,e<o||(e=r[t+1],n+=(e&c)<<7,e<o)||(e=r[t+2],n+=(e&c)<<14,e<o)||(e=r[t+3],n+=(e&c)<<21,e<o)||(e=r[t+4],n+=(e&c)*N,e<o)||(e=r[t+5],n+=(e&c)*T,e<o)||(e=r[t+6],n+=(e&c)*_,e<o)||(e=r[t+7],n+=(e&c)*O,e<o))return n;throw new RangeError("Could not decode varint")}function ot(r,t){let e=r.get(t),n=0;if(n+=e&c,e<o||(e=r.get(t+1),n+=(e&c)<<7,e<o)||(e=r.get(t+2),n+=(e&c)<<14,e<o)||(e=r.get(t+3),n+=(e&c)<<21,e<o)||(e=r.get(t+4),n+=(e&c)*N,e<o)||(e=r.get(t+5),n+=(e&c)*T,e<o)||(e=r.get(t+6),n+=(e&c)*_,e<o)||(e=r.get(t+7),n+=(e&c)*O,e<o))return n;throw new RangeError("Could not decode varint")}function I(r,t,e=0){return t==null&&(t=w(y(r))),t instanceof Uint8Array?rt(r,t,e):it(r,t,e)}function S(r,t=0){return r instanceof Uint8Array?st(r,t):ot(r,t)}function R(r,t){t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=w(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return A(e)}function C(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var P=Symbol.for("@achingbrain/uint8arraylist");function H(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function E(r){return!!r?.[P]}var d=class r{constructor(...t){Object.defineProperty(this,P,{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(E(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(E(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=H(this.bufs,t);return e.buf[e.index]}set(t,e){let n=H(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(E(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:i}=this._subList(t,e);return R(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:R(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),s=new r;return s.length=i,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=[],i=0;for(let s=0;s<this.bufs.length;s++){let a=this.bufs[s],u=i,g=u+a.byteLength;if(i=g,t>=g)continue;let f=t>=u&&t<g,b=e>u&&e<=g;if(f&&b){if(t===u&&e===g){n.push(a);break}let h=t-u;n.push(a.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(a);continue}n.push(a.subarray(t-u));continue}if(b){if(e===g){n.push(a);break}n.push(a.subarray(0,e-u));break}n.push(a)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!E(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,a=new Int32Array(s);for(let h=0;h<s;h++)a[h]=-1;for(let h=0;h<i;h++)a[n[h]]=h;let u=a,g=this.byteLength-n.byteLength,f=n.byteLength-1,b;for(let h=e;h<=g;h+=b){b=0;for(let m=f;m>=0;m--){let G=this.get(h+m);if(n[m]!==G){b=Math.max(1,m-u[G]);break}}if(b===0)return h}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=w(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 i=l(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,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 i=l(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,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 i=l(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,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=w(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 i=l(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,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 i=l(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,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 i=l(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,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 i=l(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,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 i=l(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!C(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,s)=>i+s.byteLength,0)),n.length=e,n}};function F(r){return r[Symbol.asyncIterator]!=null}var x=r=>{let t=y(r),e=w(t);return I(r,e),x.bytes=t,e};x.bytes=0;function V(r,t){t=t??{};let e=t.lengthEncoder??x;function*n(i){let s=e(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return F(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}V.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??x;return new d(e(r.byteLength),r)};var p=z(q(),1);var ft=8,ht=1024*1024*4,L;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(L||(L={}));var B=r=>{let t=S(r);return B.bytes=y(t),t};B.bytes=0;function D(r,t){let e=new d,n=L.LENGTH,i=-1,s=t?.lengthDecoder??B,a=t?.maxLengthLength??ft,u=t?.maxDataLength??ht;function*g(){for(;e.byteLength>0;){if(n===L.LENGTH)try{if(i=s(e),i<0)throw(0,p.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>u)throw(0,p.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(i),n=L.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>a)throw(0,p.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===L.DATA){if(e.byteLength<i)break;let f=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(f),yield f,n=L.LENGTH}}}return F(r)?async function*(){for await(let f of r)e.append(f),yield*g();if(e.byteLength>0)throw(0,p.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*g();if(e.byteLength>0)throw(0,p.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}D.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:a}=await r.next(e);if(s===!0)return;a!=null&&(yield a)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return D(n,{...t??{},onLength:s=>{e=s}})};return v(ct);})(); | ||
"use strict";var ItLengthPrefixed=(()=>{var Y=Object.create;var U=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var Z=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),$=(r,t)=>{for(var e in t)U(r,e,{get:t[e],enumerable:!0})},M=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of K(t))!W.call(r,i)&&i!==e&&U(r,i,{get:()=>t[i],enumerable:!(n=J(t,i))||n.enumerable});return r};var z=(r,t,e)=>(e=r!=null?Y(Q(r)):{},M(t||!r||!r.__esModule?U(e,"default",{value:r,enumerable:!0}):e,r)),v=r=>M(U({},"__esModule",{value:!0}),r);var q=Z((_t,j)=>{"use strict";function X(r,t){for(let e in t)Object.defineProperty(r,e,{value:t[e],enumerable:!0,configurable:!0});return r}function at(r,t,e){if(!r||typeof r=="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 X(r,e)}catch{e.message=r.message,e.stack=r.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(r)),X(new i,e)}}j.exports=at});var ut={};$(ut,{decode:()=>D,encode:()=>B});function d(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function l(r=0){return globalThis.Buffer?.alloc!=null?d(globalThis.Buffer.alloc(r)):new Uint8Array(r)}function w(r=0){return globalThis.Buffer?.allocUnsafe!=null?d(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}var tt=Math.pow(2,7),et=Math.pow(2,14),nt=Math.pow(2,21),T=Math.pow(2,28),N=Math.pow(2,35),_=Math.pow(2,42),O=Math.pow(2,49),o=128,u=127;function y(r){if(r<tt)return 1;if(r<et)return 2;if(r<nt)return 3;if(r<T)return 4;if(r<N)return 5;if(r<_)return 6;if(r<O)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rt(r,t,e=0){switch(y(r)){case 8:t[e++]=r&255|o,r/=128;case 7:t[e++]=r&255|o,r/=128;case 6:t[e++]=r&255|o,r/=128;case 5:t[e++]=r&255|o,r/=128;case 4:t[e++]=r&255|o,r>>>=7;case 3:t[e++]=r&255|o,r>>>=7;case 2:t[e++]=r&255|o,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function it(r,t,e=0){switch(y(r)){case 8:t.set(e++,r&255|o),r/=128;case 7:t.set(e++,r&255|o),r/=128;case 6:t.set(e++,r&255|o),r/=128;case 5:t.set(e++,r&255|o),r/=128;case 4:t.set(e++,r&255|o),r>>>=7;case 3:t.set(e++,r&255|o),r>>>=7;case 2:t.set(e++,r&255|o),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function st(r,t){let e=r[t],n=0;if(n+=e&u,e<o||(e=r[t+1],n+=(e&u)<<7,e<o)||(e=r[t+2],n+=(e&u)<<14,e<o)||(e=r[t+3],n+=(e&u)<<21,e<o)||(e=r[t+4],n+=(e&u)*T,e<o)||(e=r[t+5],n+=(e&u)*N,e<o)||(e=r[t+6],n+=(e&u)*_,e<o)||(e=r[t+7],n+=(e&u)*O,e<o))return n;throw new RangeError("Could not decode varint")}function ot(r,t){let e=r.get(t),n=0;if(n+=e&u,e<o||(e=r.get(t+1),n+=(e&u)<<7,e<o)||(e=r.get(t+2),n+=(e&u)<<14,e<o)||(e=r.get(t+3),n+=(e&u)<<21,e<o)||(e=r.get(t+4),n+=(e&u)*T,e<o)||(e=r.get(t+5),n+=(e&u)*N,e<o)||(e=r.get(t+6),n+=(e&u)*_,e<o)||(e=r.get(t+7),n+=(e&u)*O,e<o))return n;throw new RangeError("Could not decode varint")}function I(r,t,e=0){return t==null&&(t=w(y(r))),t instanceof Uint8Array?rt(r,t,e):it(r,t,e)}function S(r,t=0){return r instanceof Uint8Array?st(r,t):ot(r,t)}function R(r,t){if(globalThis.Buffer!=null)return d(globalThis.Buffer.concat(r,t));t==null&&(t=r.reduce((i,s)=>i+s.length,0));let e=w(t),n=0;for(let i of r)e.set(i,n),n+=i.length;return d(e)}function C(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var P=Symbol.for("@achingbrain/uint8arraylist");function H(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let i=e+n.byteLength;if(t<i)return{buf:n,index:t-e};e=i}throw new RangeError("index is out of bounds")}function E(r){return!!r?.[P]}var p=class r{bufs;length;[P]=!0;constructor(...t){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(E(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(E(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=H(this.bufs,t);return e.buf[e.index]}set(t,e){let n=H(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(E(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:i}=this._subList(t,e);return R(n,i)}subarray(t,e){let{bufs:n,length:i}=this._subList(t,e);return n.length===1?n[0]:R(n,i)}sublist(t,e){let{bufs:n,length:i}=this._subList(t,e),s=new r;return s.length=i,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=[],i=0;for(let s=0;s<this.bufs.length;s++){let a=this.bufs[s],c=i,g=c+a.byteLength;if(i=g,t>=g)continue;let f=t>=c&&t<g,b=e>c&&e<=g;if(f&&b){if(t===c&&e===g){n.push(a);break}let h=t-c;n.push(a.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(a);continue}n.push(a.subarray(t-c));continue}if(b){if(e===g){n.push(a);break}n.push(a.subarray(0,e-c));break}n.push(a)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!E(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,a=new Int32Array(s);for(let h=0;h<s;h++)a[h]=-1;for(let h=0;h<i;h++)a[n[h]]=h;let c=a,g=this.byteLength-n.byteLength,f=n.byteLength-1,b;for(let h=e;h<=g;h+=b){b=0;for(let A=f;A>=0;A--){let G=this.get(h+A);if(n[A]!==G){b=Math.max(1,A-c[G]);break}}if(b===0)return h}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=w(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 i=l(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,e,n),this.write(i,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 i=l(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,e,n),this.write(i,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 i=l(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,e,n),this.write(i,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=w(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 i=l(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,e,n),this.write(i,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 i=l(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,e,n),this.write(i,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 i=l(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,e,n),this.write(i,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 i=l(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,e,n),this.write(i,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 i=l(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,e,n),this.write(i,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!C(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((i,s)=>i+s.byteLength,0)),n.length=e,n}};function F(r){return r[Symbol.asyncIterator]!=null}var x=r=>{let t=y(r),e=w(t);return I(r,e),x.bytes=t,e};x.bytes=0;function B(r,t){t=t??{};let e=t.lengthEncoder??x;function*n(i){let s=e(i.byteLength);s instanceof Uint8Array?yield s:yield*s,i instanceof Uint8Array?yield i:yield*i}return F(r)?async function*(){for await(let i of r)yield*n(i)}():function*(){for(let i of r)yield*n(i)}()}B.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??x;return new p(e(r.byteLength),r)};var m=z(q(),1);var ft=8,ht=1024*1024*4,L;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(L||(L={}));var V=r=>{let t=S(r);return V.bytes=y(t),t};V.bytes=0;function D(r,t){let e=new p,n=L.LENGTH,i=-1,s=t?.lengthDecoder??V,a=t?.maxLengthLength??ft,c=t?.maxDataLength??ht;function*g(){for(;e.byteLength>0;){if(n===L.LENGTH)try{if(i=s(e),i<0)throw(0,m.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>c)throw(0,m.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let f=s.bytes;e.consume(f),t?.onLength!=null&&t.onLength(i),n=L.DATA}catch(f){if(f instanceof RangeError){if(e.byteLength>a)throw(0,m.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw f}if(n===L.DATA){if(e.byteLength<i)break;let f=e.sublist(0,i);e.consume(i),t?.onData!=null&&t.onData(f),yield f,n=L.LENGTH}}}return F(r)?async function*(){for await(let f of r)e.append(f),yield*g();if(e.byteLength>0)throw(0,m.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let f of r)e.append(f),yield*g();if(e.byteLength>0)throw(0,m.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}D.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:a}=await r.next(e);if(s===!0)return;a!=null&&(yield a)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return D(n,{...t??{},onLength:s=>{e=s}})};return v(ut);})(); | ||
return ItLengthPrefixed})); |
{ | ||
"fromReader": "https://alanshaw.github.io/it-length-prefixed/functions/decode.decode.fromReader.html", | ||
"./decode:fromReader": "https://alanshaw.github.io/it-length-prefixed/functions/decode.decode.fromReader.html", | ||
"DecoderOptions": "https://alanshaw.github.io/it-length-prefixed/interfaces/decode.DecoderOptions.html", | ||
"./decode:DecoderOptions": "https://alanshaw.github.io/it-length-prefixed/interfaces/decode.DecoderOptions.html", | ||
"ReadResult": "https://alanshaw.github.io/it-length-prefixed/interfaces/decode.ReadResult.html", | ||
"./decode:ReadResult": "https://alanshaw.github.io/it-length-prefixed/interfaces/decode.ReadResult.html", | ||
"ReadState": "https://alanshaw.github.io/it-length-prefixed/interfaces/decode.ReadState.html", | ||
"./decode:ReadState": "https://alanshaw.github.io/it-length-prefixed/interfaces/decode.ReadState.html", | ||
"MAX_DATA_LENGTH": "https://alanshaw.github.io/it-length-prefixed/variables/decode.MAX_DATA_LENGTH.html", | ||
"./decode:MAX_DATA_LENGTH": "https://alanshaw.github.io/it-length-prefixed/variables/decode.MAX_DATA_LENGTH.html", | ||
"MAX_LENGTH_LENGTH": "https://alanshaw.github.io/it-length-prefixed/variables/decode.MAX_LENGTH_LENGTH.html", | ||
"./decode:MAX_LENGTH_LENGTH": "https://alanshaw.github.io/it-length-prefixed/variables/decode.MAX_LENGTH_LENGTH.html", | ||
"decode": "https://alanshaw.github.io/it-length-prefixed/functions/decode.decode-1.html", | ||
"EncoderOptions": "https://alanshaw.github.io/it-length-prefixed/interfaces/encode._internal_.EncoderOptions.html", | ||
"./decode:decode": "https://alanshaw.github.io/it-length-prefixed/functions/decode.decode-1.html", | ||
"single": "https://alanshaw.github.io/it-length-prefixed/functions/encode.encode.single.html", | ||
"./encode:single": "https://alanshaw.github.io/it-length-prefixed/functions/encode.encode.single.html", | ||
"encode": "https://alanshaw.github.io/it-length-prefixed/functions/encode.encode-1.html", | ||
"./encode:encode": "https://alanshaw.github.io/it-length-prefixed/functions/encode.encode-1.html", | ||
"LengthDecoderFunction": "https://alanshaw.github.io/it-length-prefixed/interfaces/index.LengthDecoderFunction.html", | ||
"LengthEncoderFunction": "https://alanshaw.github.io/it-length-prefixed/interfaces/index.LengthEncoderFunction.html" | ||
".:LengthDecoderFunction": "https://alanshaw.github.io/it-length-prefixed/interfaces/index.LengthDecoderFunction.html", | ||
"LengthEncoderFunction": "https://alanshaw.github.io/it-length-prefixed/interfaces/index.LengthEncoderFunction.html", | ||
".:LengthEncoderFunction": "https://alanshaw.github.io/it-length-prefixed/interfaces/index.LengthEncoderFunction.html" | ||
} |
{ | ||
"name": "it-length-prefixed", | ||
"version": "9.0.3", | ||
"version": "9.0.4", | ||
"description": "Streaming length prefixed buffers with async iterables", | ||
@@ -180,3 +180,3 @@ "author": "Alan Shaw", | ||
"uint8arraylist": "^2.0.0", | ||
"uint8arrays": "^4.0.2" | ||
"uint8arrays": "^5.0.1" | ||
}, | ||
@@ -183,0 +183,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49783
519
- Removedmultiformats@12.1.3(transitive)
- Removeduint8arrays@4.0.10(transitive)
Updateduint8arrays@^5.0.1