# binarnia

> parse binary buffer to json according to schema

Latest version **5.1.0** (published 2025-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install binarnia
pnpm add binarnia
yarn add binarnia
bun add binarnia
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2025-02-11 |
| First published | 2018-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | coderaiser |
| Maintainers | coderaiser |
| Keywords | read, uint, buffer |

## Links

- npm: https://www.npmjs.com/package/binarnia
- Repository: https://github.com/coderaiser/binarnia
- Issues: https://github.com/coderaiser/binarnia/issues
- npm.io page: https://npm.io/package/binarnia

## Dependencies (2)

- [currify](https://npm.io/package/currify.md) ^4.0.0
- [read-uint](https://npm.io/package/read-uint.md) ^2.0.0

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 5.1.0 (latest) — 2025-02-11
- 5.0.0 — 2025-02-11
- 4.1.0 — 2023-10-20
- 4.0.0 — 2023-10-20
- 3.1.3 — 2020-07-03
- 3.1.2 — 2020-04-16
- 3.1.1 — 2019-09-23
- 3.1.0 — 2019-09-23
- 3.0.0 — 2019-09-23
- 2.1.0 — 2019-05-16
- 2.0.0 — 2019-05-10
- 1.2.1 — 2019-05-06
- 1.2.0 — 2019-05-06
- 1.1.2 — 2018-10-10
- 1.1.1 — 2018-08-16
- … 2 more at https://npm.io/package/binarnia/versions

## README

# Binarnia [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage][CoverageIMGURL]][CoverageURL]

Parse binary buffer to json according to schema.

## Install

```
npm i binarnia
```

## How to use?

```js
const binarnia = require('binarnia');
const schema = [{
    offset: '0x01',
    name: 'arch',
    size: 1,
    type: 'value',
}];

const buffer = Buffer.from([0x22]);

// endianness = 'LE'
binarnia({
    schema,
    buffer,
});

// returns
({
    arch: '0x22',
});

// directly pass endianness
binarnia({
    schema,
    endian: 'BE',
    buffer,
});

// returns
({
    arch: '0x22',
});

const array = [0x22];

// works with array as well
binarnia({
    schema,
    endian: 'BE',
    buffer: array,
});

// returns
({
    arch: 'x22',
});
```

### Value

```js
const schema = [{
    offset: '0x00',
    name: 'format',
    size: 1,
    type: 'value',
}];

const buffer = [0x03];

binarnia({
    schema,
    buffer,
});

// returns
({
    format: '0x03',
});
```

### Decimal

```js
const schema = [{
    offset: '0x00',
    name: 'size',
    size: 1,
    type: 'decimal',
}];

const buffer = [0x03];

binarnia({
    schema,
    buffer,
});

// returns
({
    size: '51',
});
```

### String

```js
const schema = [{
    offset: '0x00',
    name: 'message',
    size: 5,
    type: 'string',
}];

const buffer = [
    0x68,
    0x65,
    0x6c,
    0x6c,
    0x6f,
    0x27,
    0x00,
];

binarnia({
    schema,
    endian: 'BE',
    buffer,
});

// returns
({
    message: 'hello',
});
```

### Bit

```js
const schema = [{
    name: 'format',
    size: 1,
    type: 'bit',
    bit: {
        '0x1': 'MZ',
        '0x2': 'PE',
        '0x4': 'ELF',
    },
}];

const buffer = [0x03];

const result = binarnia({
    offset: '0x00',
    schema,
    buffer,
});

// returns
({
    format: ['MZ', 'PE'],
});
```

### Enum

```js
const binarnia = require('binarnia');
const schema = [{
    offset: '0x00',
    name: 'format',
    size: 1,
    type: 'enum',
    enum: {
        '0x22': 'MZ',
        '0x33': 'PE',
    },
}];

const buffer = Buffer.from([0x22, 0x01]);

binarnia({
    schema,
    buffer,
});

// returns
({
    format: 'MZ',
});
```

### Links

```js
const schema = [{
    name: 'msg_size',
    size: 1,
    type: 'value',
}, {
    name: 'msg',
    size: '<msg_size>',
    type: 'string',
}];

const buffer = [0x1, 0x31];

binarnia({
    schema,
    buffer,
});

// returns
({
    msg_size: '0x01',
    msg: '1',
});
```

### Array

```js
const binarnia = require('binarnia');
const schema = [{
    offset: '0x01',
    name: 'arch',
    size: 1,
    type: 'array',
    array: [
        'x32',
        'x64',
    ],
}];

const buffer = Buffer.from([0x22, 0x01]);

binarnia({
    schema,
    buffer,
});

// returns
({
    arch: 'x32',
});
```

### Ignore

```js
const schema = [{
    name: 'format',
    size: 2,
    type: 'value',
}, {
    name: 'reserved',
    size: 2,
    type: 'ignore',
}];

const buffer = [
    0x01,
    0x02,
    0x03,
    0x04,
];

binarnia({
    schema,
    buffer,
});

// returns
({
    format: '0x201',
});
```

### sizeof(schema)

```js
const schema = [{
    name: 'a',
    size: 4,
    type: 'value',
}, {
    name: 'b',
    size: 4,
    type: 'value',
}];

binarnia.sizeof(schema);
// returns
8;
```

## License

MIT

[NPMIMGURL]: https://img.shields.io/npm/v/binarnia.svg?style=flat&longCache=true
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/binarnia/master.svg?style=flat&longCache=true
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/binarnia "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/binarnia "Build Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[CoverageURL]: https://coveralls.io/github/coderaiser/binarnia?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/binarnia/badge.svg?branch=master&service=github

---
_Source: https://npm.io/package/binarnia · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
