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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@haathie/simple-ringbuf.js

v0.0.2

Published

Simple ring buffer implementation

Readme

simple-ringbuf.js

A small, single-threaded typed-array ring buffer for JavaScript.

This project is a simplified fork of ringbuf.js by Paul Adenot. The original project provides a wait-free, thread-safe SharedArrayBuffer ring buffer and related Web Audio utilities. This fork intentionally removes that scope.

simple-ringbuf.js is not thread-safe. It uses ArrayBuffer, not SharedArrayBuffer, and is intended for single-threaded FIFO buffering.

Install

npm install simple-ringbuf.js

Usage

import { RingBuffer } from "simple-ringbuf.js";

const ringBuffer = new RingBuffer({
	type: Uint32Array,
	buffer: RingBuffer.getStorageForCapacity(4, Uint32Array),
});

const written = ringBuffer.push(new Uint32Array([1, 2, 3]));

const output = new Uint32Array(3);
const read = ringBuffer.pop(output);

console.log(written); // 3
console.log(read); // 3
console.log([...output]); // [1, 2, 3]

API

RingBuffer.getStorageForCapacity(capacity, type)

Allocates an ArrayBuffer large enough for capacity usable elements of the given typed-array constructor.

The implementation reserves one extra slot internally so it can distinguish a full buffer from an empty buffer.

new RingBuffer({ type, buffer })

Creates a ring buffer over an existing ArrayBuffer.

type must be one of the standard typed-array constructors, such as Uint8Array, Uint32Array, Float32Array, or Float64Array.

push(elements, length?, offset?)

Writes elements into the ring buffer and returns the number of elements written.

If there is not enough room, only the available space is written. length limits how many elements are read from elements; offset chooses the starting index in elements.

pop(elements, length?, offset?)

Reads elements from the ring buffer into elements and returns the number of elements read.

If there is not enough data, only the available data is read. length limits how many elements are written; offset chooses the starting index in elements.

State

  • capacity() returns the usable capacity.
  • availableRead returns the number of elements available to read.
  • availableWrite returns the number of elements available to write.
  • isEmpty is true when no elements are available to read.
  • isFull is true when no elements are available to write.
  • clear() marks the buffer empty without clearing the underlying storage.

Scope

This package is useful when you need a compact FIFO queue over typed arrays in one JavaScript thread.

It is not a replacement for the original ringbuf.js if you need:

  • communication between workers or AudioWorklets;
  • SharedArrayBuffer support;
  • wait-free producer/consumer behavior across threads;
  • Web Audio helper utilities.

Use the original ringbuf.js for those cases.

Development

npm test
npm run build
npm run lint
npm run format

License

This project is licensed under the Mozilla Public License 2.0.

This project is a fork of ringbuf.js by Paul Adenot. Modifications in this fork are also distributed under the Mozilla Public License 2.0.