binary-markup
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

Logo of the project

Build Status codecov NpmLicense npm Commitizen friendly

BML

Binary markup language

BML a powerful declarative and symmetrical parser and packer for binary data.

Instead of writing imperative code to parse a piece of data, you declaratively define a data structure that describes your data. And you can use it in one direction to parse data into Javascript objects, and in the other direction, to pack objects into binary data.

Installing / Getting started

NodeJS: Just use npm to install BML and you are set :)

npm install binary-markup --save
yarn add binary-markup

Example

First describe structure of binary data

const { byte, struct } = require('binary-markup');
 
// define composite type
const rgb = struct(byte`r`, byte`g`, byte`b`);
// you can use previously defined type to describe more complex ones
const colorsType = struct(rgb`main`, rgb`secondary`);

Now you can read and parse binary data

const fs = require('fs');
const { parse } = require('binary-markup');
 
fs.readFile('file.bin', function(err, data) {
  console.log(parse(colorsType, data));
});

You can as well convert javascript object to binary data

const { pack } = require('binary-markup');
 
console.log(
  pack(colorsType, {
    main: {
      r: 211,
      g: 33,
      b: 22,
    },
    secondary: {
      r: 255,
      g: 255,
      b: 255,
    },
  })
);

Features

TBD

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Links

Licensing

The code in this project is licensed under MIT license.

Package Sidebar

Install

npm i binary-markup

Weekly Downloads

0

Version

0.9.0

License

MIT

Unpacked Size

436 kB

Total Files

160

Last publish

Collaborators

  • srg-kostyrko