# @as-com/bufio

> Buffer and serialization utilities for TypeScript

Latest version **0.2.11** (published 2018-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @as-com/bufio
pnpm add @as-com/bufio
yarn add @as-com/bufio
bun add @as-com/bufio
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.11 |
| Published | 2018-05-22 |
| First published | 2018-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=7.6.0 |
| Dependencies | 1 |
| Unpacked size | 186.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andrew Sun |
| Maintainers | as-com |
| Keywords | buffer, serialization |

## Links

- npm: https://www.npmjs.com/package/@as-com/bufio
- Repository: https://github.com/as-com/bufio
- Issues: https://github.com/as-com/bufio/issues
- npm.io page: https://npm.io/package/@as-com/bufio

## Dependencies (1)

- [n64](https://npm.io/package/n64.md) ~0.1.1

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.2.11 (latest) — 2018-05-22
- 0.2.10 — 2018-05-22
- 0.2.9 — 2018-05-22
- 0.2.8 — 2018-05-22
- 0.2.7 — 2018-05-22
- 0.2.6 — 2018-05-22
- 0.2.5 — 2018-05-22
- 0.2.4 — 2018-05-22
- 0.2.3 — 2018-05-22
- 0.2.2 — 2018-05-22
- 0.2.1 — 2018-05-22
- 0.2.0 — 2018-05-22

## README

# bufio

Buffer and serialization utilities for javascript.

## Usage

``` js
const assert = require('assert');
const bio = require('bufio');

const bw = bio.write();
bw.writeU64(100);
bw.writeString('foo', 'ascii');
const data = bw.render();

const br = bio.read(data);
assert(br.readU64() === 100);
assert(br.readString('ascii') === 'foo');
```

## Struct Usage

``` js
const bio = require('bufio');

class MyStruct extends bio.Struct {
  constructor() {
    super();
    this.str = 'hello';
    this.value = 0;
  }

  write(bw) {
    bw.writeVarString(this.str, 'ascii');
    bw.writeU64(this.value);
    return this;
  }

  read(br) {
    this.str = br.readVarString('ascii');
    this.value = br.readU64();
    return this;
  }
}

const obj = new MyStruct();

console.log('Buffer:');
console.log(obj.encode());

console.log('Decoded:');
console.log(MyStruct.decode(obj.encode()));

console.log('Hex:');
console.log(obj.toHex());

console.log('Decoded:');
console.log(MyStruct.fromHex(obj.toHex()));

console.log('Base64:');
console.log(obj.toBase64());
```

## Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. `</legalese>`

## License

- Copyright (c) 2017, Christopher Jeffrey (MIT License).

See LICENSE for more info.

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