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 - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

read.es5.js

15

index.js
'use strict';
try { //jshint evil:true
void new Function('return function*(){yield 1}')
module.exports = require('./index.es6')
}
catch (e) {
module.exports = require('./index.es5')
}
var binary = exports
, read = require('./read')
, write = require('./write')
binary.read = read
binary.write = write
binary.le = { read: read.le, write: write.le }
binary.be = { read: read.be, write: write.be }
{
"name": "binary-types",
"version": "1.1.2",
"version": "2.0.0",
"description": "helpers for binary-parser",

@@ -24,3 +24,3 @@ "main": "index.js",

"scripts": {
"prepublish": "regenerator -r index.es6.js > index.es5.js"
"prepublish": "regenerator -r read.es6.js > read.es5.js"
},

@@ -27,0 +27,0 @@ "devDependencies": {

@@ -9,50 +9,62 @@ # binary-types

## API
## Types
* u8
* u16le
* u16be
* u32le
* u32be
* f32le
* f32be
* f64le
* f64be
## Examples
```js
'use strict'
module.exports = require('binary-parser')(parser)
var read = require('binary-types')
var binary = require('binary-types')
, read = binary.read
, write = binary.write
function* parser() {
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)
}
```
### u8
### u16le
### u16be
### u32le
### u32be
### f32le
### f32be
### f64le
### f64be
## API
```js
var binary = require('binary-types')
, read = binary.read
, write = binary.write
```
what it says on the tin.
### `yield* read[type]()`
### le
returns the decoded value.
```js
read.le =
{ __proto__: read
, u16: read.u16le
, u32: read.u32le
, f32: read.f32le
, f64: read.f64le
}
```
### `write[type](value)`
### be
returns a buffer with the encoded value.
```js
read.be =
{ __proto__: read
, u16: read.u16be
, u32: read.u32be
, f32: read.f32be
, f64: read.f64be
}
### 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
```
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