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

@pocketnode/binarystream

v1.1.5

Published

a package designed to facilitate the reading and writing of binary data.

Downloads

14

Readme

BinaryStream

BinaryStream is an Typescript module designed to facilitate the reading and writing of binary data. This package uses the ArrayBuffer and DataView interfaces, both of which are native to Javascript making it compatible with Node.js and browser environments.

Features

  • Supports both Node.js and browser environments.
  • Provides an easy-to-use API for handling binary data.
  • Methods for reading and writing various data types (integers, floats, strings, etc.).
  • Allows for dynamic buffer creation without worrying about sizing.

Installation

You can install the BinaryStream package via npm.

npm install @pocketnode/binarystream

or

bun install @pocketnode/binarystream

Usage

Importing the Module

// Node.js, Bun, etc.
import BinaryStream from "@pocketnode/binarystream";

// Browser from CDN
import BinaryStream from "https://esm.run/@pocketnode/binarystream@latest/dist/BinaryStream.js";

Creating an Instance

To create a new instance of BinaryStream, you can either provide an existing ArrayBuffer or specify the size of a new buffer:

// Create an empty BinaryStream
const stream = new BinaryStream();

// Create a BinaryStream from an array of bytes
const bytes = BinaryStream.from([0xde, 0xad, 0xbe, 0xef]);
bytes.toString("hex"); // deadbeef

// Create a BinaryStream from a string
const str = BinaryStream.from("\xde\xad\xbe\xef", "binary");
str.toString("hex"); // deadbeef

// Create a BinaryStream from an existing ArrayBuffer
const blob = new Blob(..., {type: "application/octet-stream"});
const streamFromBuffer = BinaryStream.from(await blob.arrayBuffer());

Example

Here is an example demonstrating how to write and read data using BinaryStream:

const stream = new BinaryStream();

// Write data to the stream
stream.writeUInt8(255);
stream.writeInt16(-32768);
stream.writeFloat32(3.14);
stream.writeString("Hello, BinaryStream!");

// Reset the position to the beginning of the stream for reading
stream.flip();

// Read data from the stream
const uint8 = stream.readUInt8();
const int16 = stream.readInt16();
const float32 = stream.readFloat32();
const str = stream.readString();

console.log(uint8); // 255
console.log(int16); // -32768
console.log(float32); // 3.14
console.log(str); // Hello, BinaryStream!
console.log(stream.buffer); // Uint8Array (31) [255, 128, 0, 64, 72, 245, 195, 0, 0, 0, 20, 72, 101, 108, 108, 111, 44, 32, 66, 105, 110, 97, 114, 121, 83, 116, 114, 101, 97, 109, 33]

License

This project is licensed under the GNU GPLv3 License. See the LICENSE file for details.

Contact

For questions or feedback, please open an issue on GitHub.