A set of utility classes for reading and writing binary data in NodeJS.
Go to file
Holly Stubbs dd46ec825b Remove all direct usages of Buffer so that it can be decided based on platform. 2023-10-24 12:44:11 +01:00
.github/workflows Add browser js support 2023-10-24 12:04:32 +01:00
base Remove all direct usages of Buffer so that it can be decided based on platform. 2023-10-24 12:44:11 +01:00
readers Add license header everywhere 2023-10-24 12:04:07 +01:00
tooling Add browser js support 2023-10-24 12:04:32 +01:00
writers Remove all direct usages of Buffer so that it can be decided based on platform. 2023-10-24 12:44:11 +01:00
.gitignore janky tooling to get this working properly 2023-06-22 11:32:40 +01:00
.npmignore npmignore the base folder 2023-10-24 12:15:45 +01:00
LICENSE Update LICENSE 2023-04-28 15:12:09 +01:00
README.md Add npm package link to badge 2023-05-12 15:44:30 +01:00
index.ts Add license header everywhere 2023-10-24 12:04:07 +01:00
package-lock.json Add browser js support 2023-10-24 12:04:32 +01:00
package.json Remove debug messages and bump version for release 2023-10-24 12:23:25 +01:00
tsconfig.json Bump to es2020 2023-10-24 12:04:16 +01:00

README.md

bufferStuff   CodeFactor   Node.js CI   npm

A set of utility classes for reading and writing binary data in NodeJS.

Motivations

I tend to write code a lot that needs to read and write from buffers and this is sometimes in big-endian too, so I decided eventually to make a utility to help me with that which is what you see here. Originally I had two variants of bufferStuff that were for LE and BE respectively but this got difficult to manage so I rewrote it in TypeScript and added support for both reader / writer types.

Usage

You can create an instance of the Reader and Writer classes like this:

// You *must* be expicit with the endianness
const leReader:IReader = createReader(Endian.LE, buffer);
const beReader:IReader = createReader(Endian.BE, buffer);

// Size is optional, will dynamically allocate if left empty or 0
const leWriter:IWriter = createWriter(Endian.LE, <optional: size>);
const beWriter:IWriter = createWriter(Endian.BE, <optional: size>);

I tried to keep it as simple as possible to use, for example if you want to write a (signed) byte you do as follows:

writer.writeByte(<number>);

You can find a list of all of the methods for Writers and Readers in their interface files.

Projects using bufferStuff

If your project uses bufferStuff feel free to make a PR to add it to this list!

tgpholly/mc-beta-server

tgpholly/ultrakillMP_server

Projects similar to bufferStuff

tgpholly/csharp-extensions/BinaryTools - Basically bufferStuff but for C#