binary-types
helpers for binary-parser
Last updated 12 years ago by nathan7 .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install binary-types 
SYNC missed versions from official npm registry.

binary-types

helpers for binary-parser

Installation

npm install binary-types

Types

  • u8
  • u16le
  • u16be
  • u32le
  • u32be
  • f32le
  • f32be
  • f64le
  • f64be

Examples

'use strict'
var binary = require('binary-types')
  , read = binary.read
  , write = binary.write

exports.parse = require('binary-parser')(function* parser() {
  var value = yield* read.u8()
  return value
})

exports.bufferify = function(str) {
  var buf = Buffer(str.length)
  if (buf.length > 0xFF) throw new Error('too long')
  return Buffer.concat(write.u8(buf.length), buf)
}

API

var binary = require('binary-types')
  , read = binary.read
  , write = binary.write

yield* read[type]()

returns the decoded value.

write[type](value)

returns a buffer with the encoded value.

endianness shortcuts

to avoid repeating the endianness over and over:

> read.be.u16 === read.u16be
true
> read.le.u16 === read.u16le
true
> binary.le.read === read.le
true
> binary.be.write === write.be
true

Current Tags

  • 2.1.0                                ...           latest (12 years ago)

6 Versions

  • 2.1.0                                ...           12 years ago
  • 2.0.0                                ...           12 years ago
  • 1.1.2                                ...           12 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 28
Today 0
This Week 0
This Month 10
Last Day 0
Last Week 2
Last Month 7
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

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