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

packbytes

v1.0.7

Published

Cross-Platform Binary Data Encoder for Node.js and Web Browsers

Readme

Install:

npm i packbytes

Schema:

  • Define the structure of your data with a Schema
  • It will optimize and execute all low-level operations for you
  • Creates a smaller encoding faster and easier than any other schema-based system:
// example schema with all data types:

import { bool, bits, string, array, float, blob, schemas, PackBytes } from 'packbytes';

const schema = {
   a: bool,
   b: bits(1),
   c: bits(7),
   d: bits(25),
   e: string,
   x: string('str1', 'str2'),
   y: array(bits(5)),
   z: array({
      a: float(32),
      b: float(64),
      c: blob,
      d: blob(12),
      e: array(blob),
      f: array(string),
      1: array(string('str1', 'str2')),
      2: array(string('str1', 'str2')).size(3),
      3: array(array(bits(7))),
      4: schemas({ name1: bool, name2: array(bits(3)).size(2) }),
      5: array(schemas({ s1: string, s2: { field1: bool, field2: array(string('str1', 'str2')) } }))
   })
};

Example:

  • This code runs in both Node.js and Web Browser:

Schema:

import { bool, bits, array, PackBytes } from 'packbytes';

const schema = array({
   a: bool,
   b: bits(2),
   c: bits(5)
});

const encoder = new PackBytes(schema);

Encode:

const data = [
   { a: false, b: 0, c: 0 },
   { a: true, b: 1, c: 12 },
   { a: true, b: 3, c: 31 }
];

const buf = encoder.encode(data);

// buf.length == 3, encoded to 3 bytes, 24x smaller than JSON.stringify(data) at 73 bytes

sendOverNetwork(buf);
saveToDisk(buf);

Decode:

const data = encoder.decode(buf);

console.log(data);
// [
//    { a: false, b: 0, c: 0 },
//    { a: true, b: 1, c: 12 },
//    { a: true, b: 3, c: 31 }
// ]

Benchmark:

  • The benchmark encodes data 50x smaller than JSON and is 5x faster, also compare with other encoding methods:

Encoding | time (ns) | bytes --- | --- | --- packBytes | 55 | 1 packBytes_schema | 155 | 1 avsc | 270 | 4 protobuf |250 | 8 msgpack | 1170 | 33 json | 800 | 53

  • Same benchmark with different data set, 25x smaller than JSON and 5x faster:

Encoding | time (ns) | bytes --- | --- | --- packBytes | 60 | 4 packBytes_schema | 210 | 4 avsc | 300 | 9 protobuf | 490 | 17 msgpack | 1450 | 33 json | 1150 | 102

API:

  • Detailed API description and user guide:
// all available exports:
import { bool, bits, string, array, float, blob, schemas, PackBytes } from 'packbytes';

// create a schema using any combination or nesting of schema types:
schema = bool // true or false
schema = bits(x) // x number bits for unsigned integer (max integer = 2**x-1)
schema = string // string of any length
schema = string('str1', 'str2', ..) // any of specific strings, auto-maps to integer
schema = float(x) // 32 or 64 bit floating point number
schema = blob // any length buffer
schema = blob(x) // specific byte size buffer 
schema = array(schema) // array of any schema type
schema = array(schema).size(x) // specific length array
schema = { field1: schema, field2: schema, .. } // object with multiple fields
schema = schemas({ schema1: schema, schema2: schema, .. }) // multiple schemas mapped to 1 schema

// create encoder by providing schema:
// accepts schema object or JSON.stringify(schema) string for easy transfer from server to client:
encoder = new PackBytes(schema)

buf = encoder.encode(data) // encode data
buf = encoder.encode(schema_name, data) // encode data with specific schema from 'schemas' type

data = encoder.decode(buf) // decode, returns orginal data