https://github.com/beeequeue/binary-util
A utility library for working with binary data.
https://github.com/beeequeue/binary-util
Last synced: about 2 months ago
JSON representation
A utility library for working with binary data.
- Host: GitHub
- URL: https://github.com/beeequeue/binary-util
- Owner: beeequeue
- License: mit
- Created: 2024-08-31T07:12:03.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-01-10T21:59:32.000Z (6 months ago)
- Last Synced: 2025-01-10T22:42:10.554Z (6 months ago)
- Language: TypeScript
- Homepage:
- Size: 111 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# binary-util
[](https://www.npmjs.com/package/binary-util)

A utility library for working with binary data in.
It does not have full support for all types of data, but it does have the ones I needed.
## Usage
A full example of how to use this library can be found in my [RE MSG library](https://github.com/beeequeue/remsg).
Here are some non-exhaustive examples:
### Decoder
```typescript
import { Decoder } from "binary-util"const data = Buffer.from([
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21,
])
const decoder = new Decoder(data)// You can use it to just read data straight from the buffer
decoder.readString({ length: 5 }) // Hello
decoder.readString({ length: 7 }) // ", World"// Utilities
encoder.seek(-1)
encoder.seek(1)
encoder.alignTo(8)// Or you can use it more ergonomically when possible
const decoder2 = new Decoder(Buffer.alloc(2, 2))
const result = {
a: decoder2.readUint8(), // 2
b: decoder2.readUint8(), // 2
}
```### Encoder
```typescript
import { Encoder } from "binary-util"const encoder = new Encoder()
encoder.writeString("Hello, World")
encoder.seek(-1)
encoder.seek(1)
encoder.alignTo(8)
encoder.writeUint8(2)encoder.goto(1)
```