# bufio

> Buffer and serialization utilities for javascript

Latest version **1.2.3** (published 2025-01-15) · MIT license · 0 weekly downloads

## Install

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

## 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 | 1.2.3 |
| Published | 2025-01-15 |
| First published | 2017-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 114 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Christopher Jeffrey |
| Maintainers | chjj, nodweber, pinheadmz |
| Keywords | buffer, serialization |

## Links

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

## 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

- 1.2.3 (latest) — 2025-01-15
- 1.2.2 — 2024-10-02
- 1.2.1 — 2023-08-31
- 1.2.0 — 2022-12-16
- 1.1.3 — 2022-10-20
- 1.1.2 — 2022-10-20
- 1.1.1 — 2022-10-20
- 1.1.0 — 2022-10-20
- 1.0.7 — 2020-06-13
- 1.0.6 — 2019-03-21
- 1.0.5 — 2019-03-11
- 1.0.4 — 2019-01-22
- 1.0.3 — 2018-11-29
- 1.0.2 — 2018-09-29
- 1.0.1 — 2018-07-19
- … 8 more at https://npm.io/package/bufio/versions

## 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');
const data = bw.render();

const br = bio.read(data);
assert(br.readU64() === 100);
assert(br.readString(3) === '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/bufio · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
