npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

buffer-builder

v0.2.0

Published

Build a buffer without knowing its size beforehand

Downloads

2,191,073

Readme

buffer-builder.js

BufferBuilder accumulates pieces of data into a buffer, appending each onto the end. The data can be Buffers, strings, a repetition of a byte, or any of the types such as UInt32LE or FloatBE that can be written into Buffers.

If you are thinking about using this, you should probably have considered streaming your data instead of putting it into a buffer.

Usage

var BufferBuilder = require('buffer-builder');
var 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
helloWorld.appendBuffer(new Buffer([111, 114, 108, 100]));

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

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

buffer.toString(); // hello world!!!

API

new BufferBuilder([initialCapacity])

Allocate an empty BufferBuilder. If you know approximately what size the Buffer will end up being and are trying to squeeze out more performance, you can set the initial size of the backing buffer.

appendBuffer(source)

Append a buffer. Use slice if you want to append just part of one.

appendString(string, [encoding])

Append a string, encoded by utf8 by default. No trailing 0 is appended.

appendStringZero(string, [encoding])

Append a null-terminated string, encoded by utf8 by default.

appendUInt8(value)

Append 8-bit unsigned integer.

appendUInt16LE(value)

Append 16-bit unsigned integer, little endian. 1 is encoded as 01 00.

appendUInt16BE(value)

Append 16-bit unsigned integer, big endian. 1 is encoded as 00 01.

appendUInt32LE(value)

Append 32-bit unsigned integer, little endian. 1 is encoded as 01 00 00 00.

appendUInt32BE(value)

Append 32-bit unsigned integer, big endian. 1 is encoded as 00 00 00 01.

appendInt8(value)

Append 8-bit signed integer.

appendInt16LE(value)

Append 16-bit signed integer, little endian. 1 is encoded as 01 00.

appendInt16BE(value)

Append 16-bit signed integer, big endian. 1 is encoded as 00 01.

appendInt32LE(value)

Append 32-bit signed integer, little endian. 1 is encoded as 01 00 00 00.

appendInt32BE(value)

Append 32-bit signed integer, big endian. 1 is encoded as 00 00 00 01.

appendFloatLE(value)

Little-endian float. Occupies 4 bytes.

appendFloatBE(value)

Big-endian float. Occupies 4 bytes.

appendDoubleLE(value)

Little-endian double. Occupies 8 bytes.

appendDoubleBE(value)

Big-endian double. Occupies 8 bytes.

appendFill(value, count)

Append count repetitions of value (a byte).

get()

Convert to a buffer. This is a deep copy; modifications to the returned buffer will not affect the BufferBuilder.

copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])

Copy bytes from the BufferBuilder into targetBuffer. targetStart and sourceStart default to 0. sourceEnd defaults to the BufferBuilder's length.

length

Number of bytes appended so far.