2.1.3 • Published 3 months ago

binarytf v2.1.3

Weekly downloads
298
License
MIT
Repository
github
Last release
3 months ago

Discord Twitter Follow Patreon Donate PayPal Donate

GitHub Total alerts Language grade: JavaScript Coverage Status

npm npm npm bundle size npm bundle size


About

Binary Term Format is a term format inspired in ETF with more types and circular reference serialization and deserialization. This term format is designed to fix one of ETF's flaws: byte size.

Serializing this object:

{
	"test": ["hello", "world"],
	"more": {
		"nested": "objects",
		"do": ["you", "like", "it?"]
	}
}

Takes 80 bytes as JSON.stringify()'d, 116 bytes as ETF using devsnek/earl, and just 71 bytes in BTF.

The extreme compression is achieved by delimiting the bytes using a technique similar to null delimited strings. Allowing every string, array, set, map, and object, to trim the byte size by 3 (4 bytes for length/size -> 1 byte to delimit the field). TypedArrays do not get this feature, since they have a type for all elements instead of a type for each element, [0] works because it is encoded as ArrayType + NumberByteLiteralType + 0x00 + NullDelimiter, but this technique would not work in Uint8Array[0] (Uint8ArrayType + 0x00 + 0x00 + 0x00 + 0x01 + 0x00).

And this is also achieved by using special types for empty collections, [null] takes 3 bytes (ArrayType + NullType + NullDelimiter), but [] takes a single byte (EmptyArrayType). This also applies to empty objects, sets, and maps.

Usage

This module is plug-and-play, it exposes two functions, serialize and deserialize, and would be used in the following way:

const { serialize, deserialize } = require('binarytf');

const serialized = serialize({ hello: 'world' });
const deserialized = deserialize(serialized);
console.log(deserialized); // { hello: 'world' }

This module is TypeScript ready and comes with types included. To import with ESM use the following syntax:

import { serialize, deserialize } from 'binarytf';

Credit

binarytf is heavily based on devsnek/earl, this module wouldn't be possible without it's author:

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request!

Author

binarytf © kyranet, released under the MIT License. Authored and maintained by kyranet.

Github kyranet - Twitter @kyranet_

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

2.1.4-next.434596b

4 months ago

2.1.4-next.bf1c3b1

3 months ago

2.1.4-next.530a770

4 months ago

2.1.4-next.07c8cf2

4 months ago

2.1.4-next.7e95e59

4 months ago

2.1.4-next.1432ea2

4 months ago

2.1.4-next.82ca989

4 months ago

2.1.4-next.5118bff

5 months ago

2.1.4-next.d2b6d99

4 months ago

2.1.4-next.f540869

5 months ago

2.1.4-next.fde4761

5 months ago

2.1.4-next.8c2c5f0

5 months ago

2.1.4-next.c6952fe

5 months ago

2.1.4-next.ae7e27e

5 months ago

2.1.4-next.e9d3891

5 months ago

2.1.4-next.4f27253

5 months ago

2.1.4-next.1fc2a54

5 months ago

2.1.4-next.9f94746

6 months ago

2.1.4-next.da8db46

6 months ago

2.1.4-next.520f172

6 months ago

2.1.4-next.ee1c5c1

6 months ago

2.1.4-next.7631e98

6 months ago

2.1.4-next.d7f20e8

7 months ago

2.1.4-next.ce05b65

7 months ago

2.1.4-next.de15769

7 months ago

2.1.4-next.22d6838

7 months ago

2.1.4-next.9020eec

7 months ago

2.1.4-next.77c16be

7 months ago

2.1.4-next.327c7b3

8 months ago

2.1.4-next.ac10419

8 months ago

2.1.4-next.12a3232

8 months ago

2.1.4-next.1bd424f

8 months ago

2.1.4-next.40768f1

9 months ago

2.1.4-next.5ec7273

9 months ago

2.1.4-next.d4e14e5

10 months ago

2.1.4-next.a1cf384

9 months ago

2.1.4-next.b452d85

9 months ago

2.1.4-next.3dc71ea

10 months ago

2.1.4-next.963b0f7

9 months ago

2.1.4-next.790bb4f

10 months ago

2.1.4-next.f8a1121

10 months ago

2.1.4-next.de4074d

10 months ago

2.1.4-next.8a25c50

11 months ago

2.1.4-next.eb51932

11 months ago

2.1.4-next.eac726e

11 months ago

2.1.4-next.41a2533

11 months ago

2.1.4-next.2a6f0f7

11 months ago

2.1.4-next.24246d0

12 months ago

2.1.4-next.474ae39

11 months ago

2.1.3

2 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

6 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago