Skip to content

Repository files navigation

flexy-buffer

NPM Version NPM Downloads CI Tests Test Coverage

A flexible, auto-growing binary buffer for Node.js. BufferReader gives you a sequential, typed read cursor over a Buffer; FlexyBuffer extends it with write methods and automatic, page-based capacity management, so you don't have to size a buffer up front or manage reallocation yourself.

Features

  • Typed reads and writes for 8/16/32/64-bit integers (BE/LE), 64-bit BigInt, 32/64-bit floats, raw bytes, and strings
  • Auto-growing capacity in configurable, page-sized chunks, with a byte-exact maxLength cap
  • Automatic housekeeping - idle capacity is reclaimed after a configurable interval
  • insertBytes()/delete() for shifting data in place, fill() for padding
  • start()/flush() to build and extract framed messages from a reused buffer
  • Zero runtime dependencies

Installation

npm install flexy-buffer --save

Quick start

import { FlexyBuffer } from 'flexy-buffer';

const buf = new FlexyBuffer({ pageSize: 4096 });

// Write different types of data
buf.writeUInt32BE(42);
buf.writeString('Hello, World!', 'utf8');
buf.writeBytes(Buffer.from([1, 2, 3, 4]));

// Read data back by repositioning
buf.moveTo(0);
const number = buf.readUInt32BE();
const text = buf.readString(13, 'utf8');

// Build and extract a message, then reuse the buffer
buf.start();
buf.writeUInt32BE(1);
buf.writeString('hi', 'utf8');
const message = buf.flush(); // copy of the bytes written above; buf is reset for reuse

See the full API documentation for every method, configuration option, error code, and more recipes.

Support

You can report bugs and discuss features on the GitHub issues page. When you open an issue please provide the version of Node.js and of flexy-buffer you are using.

Node Compatibility

  • node >= 16.0

License

MIT

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages