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

icbon

v1.0.6-alpha

Published

icbon: Internet Compressed Binary Object Notation

Downloads

4

Readme

icbon Logo

Internet Compressed Binary Object Notation is a compact data interchange binary serialization format developed and designed for Internet Compressed Binary Protocol. This library allows you to reduce the amount of transmitted data and to speed up client-server data transfer, especially with slow internet connection.


Support:

  • Google Chrome 7+
  • Mozilla Firefox 11+
  • Internet Explorer 10+
  • Microsoft Edge 12+
  • Opera 12.1+
  • Apple Safari 5.1+
  • Node.JS 8.10.9+

Installation:

$ npm install icbon

Documentation:

function concat(data: Uint8Array[]): Uint8Array;

Sequentially concatenates each buffer in data array into resulting buffer.

function decode(data: Uint8Array, offset: number = 0): unknown;

Deserializes data buffer to JSON RFC8259 compatible value starting from the specified offset.

function encode(data: unknown): Uint8Array;

Serializes JSON RFC8259 compatible data to resulting buffer.

class Decoder {
  new(data: Uint8Array, offset: number = 0): this;
  any(): unknown;
  number(): number;
  string(): string;
  array(): unknown[];
  hash(): Record<string, unknown>;
}

Deserializes icbon data buffer starting from the specified offset to any JSON RFC8259 compatible type listed in the class interface. Calling each class method shifts offset to the next byte after read buffer segment.

class Encoder {
  new(): this;
  any(data: unknown): Uint8Array;
  null(): Uint8Array;
  boolean(data: boolean): Uint8Array;
  number(data: number): Uint8Array;
  string(data: string): Uint8Array;
  array(data: unknown[]): Uint8Array;
  hash(data: Record<string, unknown>): Uint8Array;
}

Serializes any JSON RFC8259 compatible type listed in the class interface to icbon buffer.

class DecodeError {
  new(message?: string): this;
}

Error type which can be thrown during deserialization process.

class EncodeError {
  new(message?: string): this;
}

Error type which can be thrown during serialization process.


Usage examples:

import { encode } from 'icbon';

const response: Response = await fetch('https://random-data-api.com/api/users/random_user');
const text: string = await response.text();
const object: unknown = await response.json();
const buffer: Uint8Array = encode(object);

console.log(`text json: ${ text.length * 2 } bytes`);
console.log(`serialized icbon: ${ buffer.length } bytes`);
// client
import { encode } from 'icbon';

const response: Response = await fetch('https://random-data-api.com/api/users/random_user');
const data: unknown = await response.json();

fetch(`http://example.com/endpoint`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-icbon-encoded' },
  body: encode(data),
});

// server
import { IncomingMessage, Server, ServerResponse } from 'http';
import { decode } from 'icbon';

const server: Server = new Server();

server.on('request', (request: IncomingMessage, response: ServerResponse): void => {
  const chunks: Buffer[] = [];

  request.on('data', (chunk: Buffer): void => {
    chunks.push(chunk);
  });

  request.on('end', (): void => {
    const buffer: Buffer = Buffer.concat(chunks);
    const decoded: unknown = decode(buffer);

    console.log(decoded);

    response.writeHead(200, { 'Content-Type': 'application/json' });
    response.end(JSON.stringify(decoded));
  });
});

server.listen(8080, '0.0.0.0');
import { concat, Decoder, Encoder } from 'icbon';

// Custom packet serialization
const encoder: Encoder = new Encoder();
const signature: Uint8Array = new Uint8Array([ 0x4C, 0xAA ]);
const status: Uint8Array = encoder.number(200);
const method: Uint8Array = encoder.string('POST');
const headers: Uint8Array = encoder.hash({ 'Random-Header': 'RandomValue' });
const body: Uint8Array = encoder.any([ { foo: 'bar', array: [ 100, 200, false ] } ]);
const packet: Uint8Array = concat([ signature, status, method, headers, body ]);

// Custom packet deserialization
if (packet[0] !== 0x4C || packet[1] !== 0xAA) {
  throw new Error('Wrong signature');
}

const decoder: Decoder = new Decoder(packet, 2);

console.log(`Status: ${ decoder.number() }`);
console.log(`Method: ${ decoder.string() }`);
console.log(`Headers: ${ decoder.hash() }`);
console.log(`Body: ${ decoder.any() }`);

See also: