bufio
Buffer and serialization utilities for javascript
Last updated a year ago by nodweber .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install bufio 
SYNC missed versions from official npm registry.

bufio

Buffer and serialization utilities for javascript.

Usage

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

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.

Current Tags

  • 1.2.1                                ...           latest (a year ago)

21 Versions

  • 1.2.1                                ...           a year ago
  • 1.2.0                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
  • 0.0.0                                ...           7 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE