https://github.com/electroid/bytebuf
A byte buffer for encoding and decoding binary data in JavaScript.
https://github.com/electroid/bytebuf
Last synced: 10 months ago
JSON representation
A byte buffer for encoding and decoding binary data in JavaScript.
- Host: GitHub
- URL: https://github.com/electroid/bytebuf
- Owner: Electroid
- License: mit
- Created: 2021-02-02T05:40:03.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-10T07:56:27.000Z (over 2 years ago)
- Last Synced: 2025-06-04T23:07:58.490Z (about 1 year ago)
- Language: TypeScript
- Size: 94.7 KB
- Stars: 20
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bytebuf

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