Skip to main content

Simple, dependency-less, cursor-based binary reader for TypeScript.

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (0.2.1)

BinarySeeker / Simple, dependency-less, cursor-based binary reader

BinarySeeker is a simple, dependency-less, cursor-based binary reader for TypeScript.

Installation

Please follow jsr documentation for installation instructions.

# deno
deno add @sevenc-nanashi/binaryseeeker

# npm (one of the below, depending on your package manager)
npx jsr add @sevenc-nanashi/binaryseeker
yarn dlx jsr add @sevenc-nanashi/binaryseeker
pnpm dlx jsr add @sevenc-nanashi/binaryseeker
bunx jsr add @sevenc-nanashi/binaryseeker

Usage

More detailed documentation can be found in: https://jsr.io/@sevenc-nanashi/binaryseeker

import { BinarySeeker } from "@sevenc-nanashi/binaryseeker";

const buffer = new Uint8Array([
  0x01,
  0x02,
  0x03,
  0x04,
  0x05,
  0x06,
  0x07,
  0x08,
  0x09,
  0x0a,
  0x0b,
  0x0c,
  0x0d,
  0x0e,
  0x0f,
]);
const reader = new BinarySeeker(buffer.buffer);

console.log(reader.readUInt8()); // 1
console.log(reader.readUInt16BE()); // 0x0203
console.log(reader.readUInt32LE()); // 0x07060504
console.log(reader.readUInt64BE()); // 0x08090a0b0c0d0e0fn

const textBuffer = new TextEncoder().encode("Hello, World!");
const textReader = new BinarySeeker(textBuffer.buffer);

console.log(textReader.readBytes(4)); // Uint8Array [ 72, 101, 108, 108 ]
console.log(textReader.readChars(4)); // "o, W"
console.log(textReader.readString()); // "orld!"

License

This project is licensed under the MIT License, see LICENSE for more information.

Add Package

deno add @sevenc-nanashi/binaryseeker

Import symbol

import * as mod from "@sevenc-nanashi/binaryseeker";

Add Package

npx jsr add @sevenc-nanashi/binaryseeker

Import symbol

import * as mod from "@sevenc-nanashi/binaryseeker";

Add Package

yarn dlx jsr add @sevenc-nanashi/binaryseeker

Import symbol

import * as mod from "@sevenc-nanashi/binaryseeker";

Add Package

pnpm dlx jsr add @sevenc-nanashi/binaryseeker

Import symbol

import * as mod from "@sevenc-nanashi/binaryseeker";

Add Package

bunx jsr add @sevenc-nanashi/binaryseeker

Import symbol

import * as mod from "@sevenc-nanashi/binaryseeker";