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

binutils

v0.1.0

Published

A .NET-like BinaryReader and BinaryWriter with endianness support.

Downloads

829

Readme

binutils - .NET like BinaryReader and BinaryWriter for node.js

These utilities provide you with a BinaryReader and BinaryWriter class with functions similar to the corresponding .NET classes. They also allow you to define a specific endianness!

Basic installation and usage

You can install this package either by using npm or by downloading the source from GitHub and requiring it directly.

To install using npm open your terminal (or command line), make sure you're in your application directory and execute the following command:

npm install binutils

You can then start using the package by requiring it from your application as such:

var binutils = require('binutils');

BinaryReader Class

BinaryReader(inputBuffer, endianness, encoding)

  • Initializes a BinaryReader with the specified settings
  • inputBuffer can be a Buffer, a string or an array

ReadUInt8()

  • Reads a 8 bit unsigned integer from the buffer and advances the current position by 1 byte

ReadUInt16()

  • Reads a 16 bit unsigned integer from the buffer and advances the current position by 2 bytes

ReadUInt32()

  • Reads a 32 bit unsigned integer from the buffer and advances the current position by 4 bytes

ReadInt8()

  • Reads a 8 bit signed integer from the buffer and advances the current position by 1 byte

ReadInt16()

  • Reads a 16 bit signed integer from the buffer and advances the current position by 2 bytes

ReadInt32()

  • Reads a 32 bit signed integer from the buffer and advances the current position by 4 bytes

ReadFloat()

  • Reads a float from the buffer and advances the current position by 4 bytes

ReadDouble()

  • Reads a double from the buffer and advances the current position by 8 bytes

ReadBytes(count)

  • Reads the specified number of bytes into a new buffer and advances the current position by that number of bytes

Length [Number]

  • The length of the initially provided data

Position [Number]

  • The current position (index) of the reader

ByteBuffer [Buffer]

  • A buffer containing the remaining data from the original buffer

BinaryWriter Class

BinaryWriter(endianness, encoding)

  • Initializes a BinaryWriter with the specified settings

WriteUInt8(value)

  • Writes a 8 bit unsigned integer to the buffer and advances the current position by 1 byte

WriteUInt16(value)

  • Writes a 16 bit unsigned integer to the buffer and advances the current position by 2 bytes

WriteUInt32(value)

  • Writes a 32 bit unsigned integer to the buffer and advances the current position by 4 bytes

WriteInt8(value)

  • Writes a 8 bit signed integer to the buffer and advances the current position by 1 byte

WriteInt16(value)

  • Writes a 16 bit signed integer to the buffer and advances the current position by 2 bytes

WriteInt32(value)

  • Writes a 32 bit signed integer to the buffer and advances the current position by 4 bytes

WriteFloat(value)

  • Writes a float to the buffer and advances the current position by 4 bytes

WriteDouble(value)

  • Writes a double to the buffer and advances the current position by 8 bytes

WriteBytes(value)

  • Reads the specified number of bytes into a new buffer and advances the current position by that number of bytes
  • value can be a Buffer, a string or an array

Length [Number]

  • The length of the current data buffer

ByteBuffer [Buffer]

  • A buffer containing the data written using the class functions

Example

var binutils = require('./binutils.js');

var buffer = new Buffer([1,  0, 2,  0, 0, 0, 3,  1, 2, 3, 4, 5, 6]);

var reader = new binutils.BinaryReader(buffer);

console.log(reader.ReadUInt8()); // Will print '1'
console.log(reader.ReadUInt16()); // Will print '2'
console.log(reader.ReadUInt32()); // Will print '3'
console.log(reader.ReadBytes(6)); // Will print '<Buffer 01 02 03 04 05 06>'
console.log(reader.Position); // Will print '13'
console.log(reader.Length); // Will print '13'

//

var writer = new binutils.BinaryWriter();

writer.WriteUInt16(65535);
writer.WriteUInt32(0);
writer.WriteInt32(-1);
writer.WriteBytes([5, 4, 3, 2, 1]);

console.log(writer.ByteBuffer); // Will print '<Buffer ff ff 00 00 00 00 ff ff ff ff 05 04 03 02 01>'
console.log(writer.Length); // Will print '15'

TODO

  • Add support for 64-bit integers
  • Add support for strings
  • Add support for booleans