A byte buffer for encoding and decoding binary data in JavaScript. Supports the major web browsers, NodeJS, Deno, and Cloudflare Workers.
npm i bytebufimport{ByteBuf}from"bytebuf"constdata=newUint8Array(1024)constbuffer=ByteBuf.from(data)buffer.writeInt32(16)buffer.writeString("Encoding is fun!")buffer.setInt16(4,25924,true)buffer.writeVarInt(49)console.log(buffer.byteOffset)// 21buffer.reset()constbyteLength=buffer.readInt32()// 16console.log(buffer.readString(byteLength))// "Decoding is fun!"console.log(buffer.getVarInt(20))// { value: 49, byteLength: 1 }