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

binary-buffer-parser

v2.1.1

Published

A binary buffer parser with support for infinite sized files

Downloads

115

Readme

binary-buffer-parser

A binary buffer parser with support for infinite sized files.

Build Status Pupix's Discord

Download

binary-buffer-parser is installable via:

  • GitHub git clone https://github.com/Pupix/binary-buffer-parser.git
  • npm: npm install binary-buffer-parser
  • yarn: yarn add binary-buffer-parser

Quick example

Parsing buffers

const BinaryParser = require('binary-buffer-parser');
const buffer = Buffer.from('Hello world!');
const bufferParser = new BinaryParser(buffer);

console.log(bufferParser.int8()); // 72
console.log(bufferParser.uint32()); // 1869376613
console.log(bufferParser.string(parser.size())) // Hello World!

Parsing files

const BinaryParser = require('binary-buffer-parser');
const fileParser = new BinaryParser();

fileParser.open('/path/to/file');
console.log(fileParser.int8());
console.log(fileParser.uint32());
fileParser.close();

Documentation

Integers methods

int8(length) / byte(length)

Reads an 8 bit signed integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of int8 to read consecutively

uint8(length) / ubyte(length)

Reads an 8 bit unsigned integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of uint8 to read consecutively

int16(length) / short(length)

Reads a 16 bit signed integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of int16 to read consecutively

uint16(length) / ushort(length)

Reads a 16 bit unsigned integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of uint16 to read consecutively

int24(length)

Reads a 24 bit signed integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of int24 to read consecutively

uint24(length)

Reads a 24 bit unsigned integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of uint24 to read consecutively

int32(length) / int(length)

Reads a 32 bit signed integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of int32 to read consecutively

uint32(length) / int(length)

Reads a 32 bit unsigned integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of uint32 to read consecutively

int64(length) / long(length)

Reads a 64 bit signed integer from the buffer / file.

Note: JavaScript does not represent 64 bit integers correctly, so the result will be returned as a string

Arguments

  1. {number} [length = 1] The number of int64 to read consecutively

uint64(length) / ulong(length)

Reads a 64 bit unsigned integer from the buffer / file.

Note: JavaScript does not represent 64 bit integers correctly, so the result will be returned as a string

Arguments

  1. {number} [length = 1] The number of uint64 to read consecutively

Floating points methods

float16(length) / half(length)

Reads a 16 bit floating point number from the buffer / file.

Arguments

  1. {number} [length = 1] The number of float16 to read consecutively

float32(length) / float(length)

Reads a 32 bit floating point number from the buffer / file.

Arguments

  1. {number} [length = 1] The number of float32 to read consecutively

float64(length) / double(length)

Reads a 64 bit signed integer from the buffer / file.

Arguments

  1. {number} [length = 1] The number of float64 to read consecutively

string(length)

Reads an ASCII string from the buffer / file.

Parameters

  1. {number} [length = 1] The length of the string.

string0()

Reads a null terminated ASCII string from the buffer.

wstring(length)

Reads an UTF16 string from the buffer / file.

Parameters

  1. {number} [length = 1] The length of the string.

wstring0()

Reads a null terminated UTF16 string from the buffer.

Bitfield methods

bit8(length)

Reads an unsigned 8 bit integer from the buffer and returns an array with true/false based on the values of each bit.

Arguments

  1. {number} [length = 1] The number of bitfields to read consecutively

bit16()

Reads an unsigned 16 bit integer from the buffer and returns an array with true/false based on the values of each bit.

Arguments

  1. {number} [length = 1] The number of bitfields to read consecutively

bit32()

Reads an unsigned 32 bit integer from the buffer and returns an array with true/false based on the values of each bit.

Arguments

  1. {number} [length = 1] The number of bitfields to read consecutively

File Methods

open(path)

Opens a file from the specified path and parses it.

Parameters

  1. path {string} The path to retrieve the file from.

Closes the previously opened file. Should always be called once you are done parsing to avoid memory leaks.

Helper Methods

bigEndian()

Indicates that all subsequent reads and writes from the buffer / file should use big-endian byte order.

littleEndian()

Indicates that all subsequent reads and writes from the buffer / file should use little-endian byte order.

isBigEndian()

Returns true if the buffer / file is being read in big-endian byte order, or false otherwise.

isLittleEndian()

Returns true if the buffer / file is being read in little-endian byte order, or false otherwise.

size()

Returns the size of the buffer / file in bytes.

path()

Returns the physical disk location of the buffer.

eof()

Returns true if the current read position is at the end of the buffer.

seek(offset)

Sets the current read position to the address offset.

  1. offset {number} The new value of the new offset position.

skip(offset)

Moves the current read position ahead by offset bytes.

  1. offset {number} The number of bytes to skip over.

Returns the current read position of the buffer / file.