Buffer Builder

0.2.0 · abandoned · verified Sun Apr 19

This package, `buffer-builder`, provides a utility for incrementally constructing a Node.js `Buffer` without prior knowledge of its final size. It offers methods to append strings, existing buffers, and various integer/float types (e.g., `appendUInt32LE`, `appendFloatBE), as well as a byte fill operation. The current stable version is 0.2.0, last published over a decade ago in January 2015. Due to its age, it directly relies on the now-deprecated `new Buffer()` constructor, which poses significant security and usability issues in modern Node.js environments. This package is effectively abandoned, with no active development or updates to address compatibility with contemporary Node.js Buffer APIs (like `Buffer.from`, `Buffer.alloc`). Developers seeking similar functionality should consider actively maintained alternatives or Node.js's built-in `Buffer.concat` with an array of smaller buffers.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing BufferBuilder, appending various data types, and retrieving the final Buffer, updated for modern Node.js Buffer API usage.

import BufferBuilder from 'buffer-builder';
import { Buffer } from 'node:buffer';

const helloWorld = new BufferBuilder();

// Append a string, utf8 encoded by default.
helloWorld.appendString('hello');

// Append any type that Buffer has read and write functions for.
helloWorld.appendUInt16LE(0x7720);

// Append a buffer - using Buffer.from() for modern Node.js compatibility
helloWorld.appendBuffer(Buffer.from([111, 114, 108, 100]));

// Appended a repetition of a byte
helloWorld.appendFill(33, 3);

// Convert to an ordinary buffer
const buffer = helloWorld.get();

console.log(buffer.toString()); // Expected: hello world!!!

view raw JSON →