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-pmb

v0.3.5

Published

Unpack multibyte binary values from buffers and streams. (Maintenance fork of substack's `binary`)

Downloads

9

Readme

binary-pmb

Unpack multibyte binary values from buffers and streams. (Maintenance fork of substack's binary)

You can specify the endianness and signedness of the fields to be unpacked too.

This module is a cleaner and more complete version of bufferlist's binary module that runs on pre-allocated buffers instead of a linked list.

build status

Installation

npm install binary

Examples

See the docs/examples/ directory.

API

var binary = require('binary-pmb')

var b = binary()

Return a new writable stream b that has the chainable methods documented below for buffering binary input.

binary.parse(buf)

Parse a static buffer in one pass. Returns a chainable interface with the methods below plus a vars field to get at the variable stash as the last item in a chain.

In parse mode, methods will set their keys to null if the buffer isn't big enough except buffer() and scan() which read up up to the end of the buffer and stop.

b.vars

See binary.parse.

b.word{8,16,24,32,64}{l,b}{e,u,s}(key)

Parse bytes in the buffer or stream given:

  • number of bits
  • endianness ( l : little, b : big ),
  • signedness ( u and e : unsigned, s : signed )

These functions won't start parsing until all previous parser functions have run and the data is available.

The result of the parse goes into the variable stash at key. If key has dots (.s), it refers to a nested address. If parent container values don't exist they will be created automatically, so for instance you can assign into dst.addr and dst.port and the dst key in the variable stash will be { addr : x, port : y } afterwards.

b.buffer(key, size)

Take size bytes directly off the buffer stream, putting the resulting buffer slice in the variable stash at key.

vars lookup: If size is a string, use the value at vars[size]. The key follows the same dotted address rules as the word functions.

b.str(key, size[, encoding])

Same as .buffer but decode the data as a string. Default encoding is latin1.

b.utf8(key, size)

Same as .buffer but decode the data as a UTF-8 string.

b.skip(dist)

Jump dist bytes ahead. The "vars lookup" feature from .buffer applies to dist.

b.scan(key, buffer)

Search for buffer in the stream and store all the intervening data in the stash at at key, excluding the search buffer. If buffer passed as a string, it will be converted into a Buffer internally.

For example, to read in a line you can just do:

var b = binary()
    .scan('line', new Buffer('\r\n'))
    .tap(function (vars) {
        console.log(vars.line)
    })
;
stream.pipe(b);

b.tap(cb)

The callback cb is provided with the variable stash from all the previous actions once they've all finished.

You can nest additional actions onto this inside the callback.

b.into(key, cb)

Like .tap(), except all nested actions will assign into a key in the vars stash.

b.loop(cb)

Loop, each time calling cb(end, vars) for function end and the variable stash with this set to a new chain for nested parsing. The loop terminates once end is called.

b.flush()

Clear the variable stash entirely.

Known issues

  • The word64 functions will only return approximations since javascript uses IEEE floating point for all number types. Mind the loss of precision.

 

License

MIT