GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - binarytf/binarytf: Binary Term Format

BranchesTags
Open more actions menu

Latest commit

 

History

617 Commits
617 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
.yarn
.yarn
 
 
src
src
 
 
static
static
 
 
tests
tests
 
 
.all-contributorsrc
.all-contributorsrc
 
 
.cliff-jumperrc.yml
.cliff-jumperrc.yml
 
 
.editorconfig
.editorconfig
 
 
.eslintignore
.eslintignore
 
 
.eslintrc.json
.eslintrc.json
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.yarnrc.yml
.yarnrc.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
SPEC.md
SPEC.md
 
 
cliff.toml
cliff.toml
 
 
package.json
package.json
 
 
tsconfig.base.json
tsconfig.base.json
 
 
tsconfig.eslint.json
tsconfig.eslint.json
 
 
tsup.config.ts
tsup.config.ts
 
 
typedoc.json
typedoc.json
 
 
vitest.config.ts
vitest.config.ts
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

logo

BinaryTF

Discord Twitter Follow Patreon Donate PayPal Donate

GitHub

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:

  • Gus Caplan

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

Please make sure to read the Contributing Guide before making a pull request.

Thank you to all the people who already contributed!

About

Binary Term Format

binarytf.github.io/binarytf/

Topics

binarydeserializationhacktoberfestmessageserializationterm-format

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

19 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.