GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - pocketnode/binarystream: BinaryStream implementation for Bun, Node.js, and Browser

BranchesTags
Open more actions menu

Latest commit

 

History

35 Commits
35 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.npmignore
.npmignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.ts
build.ts
 
 
bun.lockb
bun.lockb
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

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.write(new TextEncoder().encode("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.readRest();

console.log(uint8); // 255
console.log(int16); // -32768
console.log(float32); // 3.14
console.log(new TextDecoder().decode(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.

About

BinaryStream implementation for Bun, Node.js, and Browser

pocketnode.github.io/binarystream/

Topics

binarybinary-streambufferbunnodetypescriptweb

Resources

Readme
GPL-3.0 license
Activity
Custom properties

Stars

4 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.