Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binary-types

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-types

helpers for binary-parser

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
increased by3300%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 01 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc