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.
- 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
maxLengthcap - Automatic housekeeping - idle capacity is reclaimed after a configurable interval
insertBytes()/delete()for shifting data in place,fill()for paddingstart()/flush()to build and extract framed messages from a reused buffer- Zero runtime dependencies
npm install flexy-buffer --saveimport { 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 reuseSee the full API documentation for every method, configuration option, error code, and more recipes.
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
>= 16.0