bytebuf
A byte buffer for encoding and decoding binary data in JavaScript. Supports the major web browsers, NodeJS, Deno, and Cloudflare Workers.
Install
npm i bytebuf
Usage
import { ByteBuf } from "bytebuf"
const data = new Uint8Array(1024)
const buffer = new ByteBuf(data.buffer)
buffer.writeInt32(16)
buffer.writeString("Encoding is fun!")
buffer.setInt16(4, 25924, true)
buffer.writeVarInt(49)
console.log(buffer.byteOffset)
buffer.reset()
const byteLength = buffer.readInt32()
console.log(buffer.readString(byteLength))
console.log(buffer.getVarInt(20))