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 🙏

© 2026 – Pkg Stats / Ryan Hefner

stream-tokenizr

v0.3.2

Published

parse and tokenize binary streams with a simple fluent, streaming api

Readme

Stream Tokenizr

Easily parse binary data with a convenient accessible fluent interface, and node streams. Tokenzr is a small Transform stream implementation, that pulls binary data in and pushes out whatever tokens you wish.

Tokenizr more or less implements the same API as Substack's Binary where it made sense, although the internals or simplier and (i think) more straight forward, by making use of the newer streams api. Each tokenizr is a Transform stream instance so check here for that api. The ultimate form and content of the parsed data is up to you.

Using the Tokenizr

var Tokenizr = require('stream-tokenizr')
  , stream = getAReadStream();

var tokenizr = stream.pipe(new Tokenizr({ objectMode: true }));

tokenizr
    .readString(5, 'uft8', 'myString')
    .readUInt16LE('myInt')
    .tap(function(state){
        var obj = {
            'message': state.myString,
            'number': state.myInt
        }
        // we can now push the parsed data out to the world
        // see: http://nodejs.org/api/stream.html#stream_readable_push_chunk_encoding
        this.push(obj)
    })

tokenizr.on('data', function(obj){
    console.log('obj')
})

Building parser streams

You can also inherit stream Tokenizr to help create complex stream parsers. Take a look at the various audio file parsers i've written for some real world examples

parser.js

Here we create a new Parser Stream that inherits from Tokenizr

var Tokenizr = require('stream-tokenizr');

module.exports = Parser

require('util').inherits(Parser, Tokenizr);

function Parser(opts){
    Tokenizr.call(this, opts)

    this
        .readString(5, 'uft8', 'myString')
        .readUInt16LE('myInt')
        .tap(function(state){
             var obj = {
                 'message': state.myString,
                 'number': state.myInt
             }
             // we can now push the parsed data out to the world
             // see: http://nodejs.org/api/stream.html#stream_readable_push_chunk_encoding
             this.push(obj)
             this.push(null)
        })
}

main.js

var Parser = require('./parser')
  , source = getAReadStream();

var parser = new Parser();

source
    .pipe(parser)
    .on('data', function(obj){ // you can also use the new read()
        console.log(obj) // => { message: 'hello', myInt: 5 }
    })

API

.readBuffer(Int bytes, Function|String callback)

reads a buffer of a specified size in bytes.

  1. if you provide a Function for the callback it will be called with the buffer as the first argument, and the state object as the second.

  2. Providing a String as the callback will assign the buffer in the state object under a key of that name

    tokenizr .readBuffer(4, 'first') .readBuffer(5, function(buffer, state){ buffer.length // 5 state.first.length // 4 })