cborkit
Version:
A modern, extensible CBOR (Concise Binary Object Representation) library for TypeScript and JavaScript.
2 lines (1 loc) • 1.97 kB
JavaScript
import{a as i}from"./chunk-2WDY66DD.js";var b={PosInt:0,NegInt:1,Bytes:2,Text:3,Array:4,Map:5,Tag:6,Special:7};var m="setFloat16"in DataView.prototype&&"getFloat16"in DataView.prototype,s=(r,t)=>r[t],h=(r,t)=>r[t]<<8|r[t+1],c=(r,t)=>(r[t]<<24|r[t+1]<<16|r[t+2]<<8|r[t+3])>>>0,y=(r,t)=>BigInt(r[t])<<56n|BigInt(r[t+1])<<48n|BigInt(r[t+2])<<40n|BigInt(r[t+3])<<32n|BigInt(r[t+4])<<24n|BigInt(r[t+5])<<16n|BigInt(r[t+6])<<8n|BigInt(r[t+7]),w=(r,t)=>new DataView(r.buffer).getFloat16(t),g=(r,t)=>new DataView(r.buffer).getFloat32(t),l=(r,t)=>new DataView(r.buffer).getFloat64(t);var x=(r,t,e)=>{new DataView(r.buffer).setFloat16(t,e)},C=(r,t,e)=>{new DataView(r.buffer).setFloat32(t,e)},U=(r,t,e)=>{new DataView(r.buffer).setFloat64(t,e)};var u=r=>{if(typeof r=="bigint"&&(r=Number(r)),!Number.isSafeInteger(r))throw new Error("value must be a safe integer");if(Number.isNaN(r))throw new Error("value must be a number");return r},A=r=>{try{return u(r)}catch{return r}};var a=class{constructor(t=128){i(this,"chunkSize");i(this,"chunks");i(this,"currentChunk");i(this,"offset");i(this,"totalSize");this.chunkSize=t,this.chunks=[],this.currentChunk=new Uint8Array(this.chunkSize),this.offset=0,this.totalSize=0}push(t){Array.isArray(t)&&(t=new Uint8Array(t));let e=0;for(;e<t.length;){let n=this.chunkSize-this.offset,o=Math.min(n,t.length-e);this.currentChunk.set(t.subarray(e,e+o),this.offset),this.offset+=o,e+=o,this.offset===this.chunkSize&&(this.chunks.push(this.currentChunk),this.currentChunk=new Uint8Array(this.chunkSize),this.offset=0)}this.totalSize+=t.length}clear(){this.chunks.length=0,this.currentChunk=new Uint8Array(this.chunkSize),this.offset=0,this.totalSize=0}toBytes(){let t=new Uint8Array(this.totalSize),e=0;for(let n of this.chunks)t.set(n,e),e+=n.length;return this.offset>0&&t.set(this.currentChunk.subarray(0,this.offset),e),t}};export{b as a,m as b,s as c,h as d,c as e,y as f,w as g,g as h,l as i,x as j,C as k,U as l,u as m,A as n,a as o};