New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

minibit

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minibit

Fast and efficient binary serialization.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
0
Created
Source

minibit

Compression and decompression of data described by JSON Schema.

npm install minibit

MiniBit allows you to reuse validation JSON Schema to compress data to a smaller size than JSON serialization.

Typically, you can compress data to as little as 30% the size of arbitrary serialization such as JSON stringification and message pack.

This is achieved by:

  • Prioritizing minimal bit information over byte alignment.
  • Encoding content encoded strings and formats as bytes.
  • Compacting integer values used for lengths and counts down to exact bit depths based on expected ranges.
  • Storing references to const, enum and null values instead of actual values.

Note:

  • Data is not validated against the JSON schema.
  • References are not followed and "allOf", "anyOf", "oneOf" properties are ignored. Make sure you dereference your schemas beforehand.

Usage

import { encode, decode } from 'minibit';

const data = {
   // data
};

const schema = {
   // JSON Schema
};

const buffer = encode(data, schema)

const dataB = decode(buffer, schema)

API

buffer = encode(data, schema)

Encodes data to buffer.

data = decode(buffer, schema)

Decodes data from buffer.

Backwards Compatibility

The following changes in schema break backwards compatibility for encoded data:

  • Adding to object properties, enums, array prefix items anywhere other than at the end.
  • Removing object properties, enums, array prefix items.
  • Changing order of object properties, enums, array prefix items.
  • Changing length/quantity properties such as minItems, maxItems, minLength, maxLength, minimum, maximum, etc.
  • Changing string contentEncoding or format.

It is recommended to make the root schema an object, only add new properties and mark old properties as deprecated.

MiniBit does not validate data and treats object properties as optional. Decoding will not fail if a deprecated properties is not present.

Benchmarks

Benchmarks use a sample object that include all JSON schema types. The code for it can be found here.

SerializerSize
minibit90 bytes
msgpack232 bytes
JSON306 bytes

License

MIT

Keywords

protobuf

FAQs

Package last updated on 25 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts