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

@wecandobetter/binary-buffer

v0.1.2

Published

Binary Buffer is a class that allows you to read and write binary data in a buffer.

Downloads

7

Readme

Binary Buffer 💾

Binary Buffer is a versatile TypeScript library that provides tools for creating, manipulating, and serializing binary data buffers. It simplifies the process of working with binary data by offering an intuitive API for defining data structures, serializing data, and managing byte sequences.

Features 🚀

  • ⚙️ Flexible Type System: Define custom data types using a simple and extensible API.
  • 🔄 Serialization and Deserialization: Serialize and deserialize complex data structures with ease.
  • 📚 Easy-to-Use API: Create, read, and manipulate binary data using an intuitive and well-documented API.
  • High Performance: Optimized for speed, making it suitable for performance-critical applications.
  • 📦 Built-in Types: Built-in support for common data types such as integers, floating point numbers, strings, and arrays.

Installation 📦

Note: Binary Buffer is currently in the early stages of development and is not yet ready for production use. Use at your own risk.

Install Binary Buffer using npm:

npm install @wecandobetter/binary-buffer

Usage Example 🌟

import { BufferBuilder } from "@wecandobetter/binary-buffer";
import { string, uint8 } from "@wecandobetter/binary-buffer/dist/types.js";

// Create a BufferBuilder instance
const builder = new BufferBuilder();

// Register the built-in types we want to use
builder.registerType(uint8);
builder.registerType(string);

// Define your data structure using the built-in types
const descriptor = {
  age: "uint8",
  name: "string",
};

// Create a builder function
const build = builder.createBuild(descriptor);

// Build the binary buffer using the builder function
const { buffer, ops, copy } = build({
  age: 42,
  name: "John Doe",
});

// Get the values
ops.age.get(); // 42
ops.name.get(); // "John Doe"

// Set the values
ops.age.set(43);
ops.name.set("Jane Doe");

// Copy the buffer
const copiedBuffer = copy();

See the example and unit tests for more usage examples.

Built-in Types

| Type Key | Description | Byte Length | Range | Notes | | --------- | ---------------------------- | ----------- | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | | uuid | UUID | 16 | | | | uint8 | Unsigned 8-bit integer | 1 | 0 to 255 | | | uint16 | Unsigned 16-bit integer | 2 | 0 to 65535 | | | uint32 | Unsigned 32-bit integer | 4 | 0 to 4294967295 | | | int8 | Signed 8-bit integer | 1 | -128 to 127 | | | int16 | Signed 16-bit integer | 2 | -32768 to 32767 | | | int32 | Signed 32-bit integer | 4 | -2147483648 to 2147483647 | | | float32 | 32-bit floating point number | 4 | 1.401298464324817e-45 to 3.4028234663852886e+38 | | | float64 | 64-bit floating point number | 8 | 5e-324 to 1.7976931348623157e+308 | | | boolean | Boolean value | 1 | true or false | | | string | Unicode string | Variable | Variable | Length prefix (2 bytes) | | T[] | Array of values of type T | Variable | Variable | Length prefix (4 bytes), each value is serialized using the type T, which means that the type T must be registered |

Roadmap 🗺️

  • [ ] Complete unit tests and CI/CD pipeline
  • [ ] Type aliases
  • [ ] Cache deserialized values for performance
  • [ ] Support browser, Deno, and Bun environments
  • [ ] Some kind of benchmarking

Contributing 🤝

Contributions, issues, and feature requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

If you find Binary Buffer helpful, consider starring the repository ⭐ and contributing to its development. Feel free to report issues or submit pull requests to help us make it even better!

License 📜

Binary Buffer is licensed under the MIT License.