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

crypto-binary

v0.1.1

Published

Assemble and disassemble binary messages used in cryptocoin applications

Downloads

17

Readme

Crypto-Binary

Assemble and disassemble binary messages used in cryptocoin applications.

MessageBuilder

Assemble a binary message out of chunks of data. All the methods return the builder itself, so are chainable. General usage is to use the various put* methods and then call raw() to get the output as a Buffer.

var b = new MessageBuilder();
b.putInt8(255).putInt16(0xbeef);
b.put(new Buffer([1,2,3,4,5]));
console.log(b.raw().toString('hex')); // 'ffbeef0102030405'
  • putInt[8,16,32]: Append an integer of the specified bit length to the message
  • put: Append raw data to the message. If a number less than 255 is passed, acts like putInt8, otherwise input is expected to be a Buffer, which is appended to the message
  • putString: Convert a string into ASCII-representation of the characters and append that to the message
  • putVarInt: Convert a number into the Bitcoin variable length integer notation and append it to the message
  • putVarString: Convert a string into the Bitcoin variable length string notation and append it to the message

MessageParser

Given a string of binary data saved in a buffer, walk through it looking for structured data. Each of the methods returns the specified data from the current point in the data, and increments the pointer to the end of the data extracted. The point of this class is to allow you to not have to constantly check "is there enough data in the buffer to complete my next action?" or "did the last action fail?" and defer those checks to the end of parsing, making for cleaner code.

var p = new MessageParser(rawData);
var itemNum = p.readVarInt();
for (var i = 0; i < itemNum; i++) {
  items.push(s.readUInt32LE());
}
if (p.hasFailed) {
  throw new Error('Ran out of data before this point!');
}
  • readUInt8, readUInt[16,32]LE: Match the NodeJS Buffer methods of the same name; read an integer from the current pointer location of of the specified bit-size
  • readVarInt: Grab a number encoded in the Bitcoin variable length integer notation from the data stream
  • readVarString: Grab a string encoded in the Bitcoin variable length string notation from the data stream
  • raw: Grab a number of raw bytes from the data stream and return it as a Buffer.
  • incrPointer, setPointer: Manipulate the current cursor location, either by incrementing it by a certain amount, or setting it to a specific absolute value

The MessageParser object has a hasFailed property, which is set to true if the actions request cannot be completed (pointer goes beyond the length of the buffer, usually). There is also a failedStack property that holds a stack trace from when the first failure occurred (in case you want to diagnose when in the process it failed)