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

@gmod/binary-parser

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gmod/binary-parser - npm Package Compare versions

Comparing version 1.3.3 to 1.3.4

.babelrc

97

lib/binary_parser.js

@@ -1,13 +0,11 @@

//========================================================================================
//= =======================================================================================
// Globals
//========================================================================================
//= =======================================================================================
var vm = require("vm");
var Context = require("./context").Context;
var Long = require('long');
var Long = require("long");
if (typeof window !== 'undefined')
window.Buffer = Buffer
if (typeof self !== 'undefined')
self.Buffer = Buffer // this is for webworker, and also is not an elseif to avoid window polyfills in webworker
if (typeof window !== "undefined") window.Buffer = Buffer;
if (typeof self !== "undefined") self.Buffer = Buffer; // this is for webworker, and also is not an elseif to avoid window polyfills in webworker

@@ -40,3 +38,3 @@ var PRIMITIVE_TYPES = {

Itf8: null,
Ltf8: null,
Ltf8: null
};

@@ -63,5 +61,5 @@

//========================================================================================
//= =======================================================================================
// class Parser
//========================================================================================
//= =======================================================================================

@@ -106,3 +104,3 @@ //----------------------------------------------------------------------------------------

BIT_RANGE.forEach(function(i) {
Parser.prototype["bit" + i.toString()] = function(varName, options) {
Parser.prototype[`bit${i.toString()}`] = function(varName, options) {
if (!options) {

@@ -172,3 +170,3 @@ options = {};

throw new Error(
'Specified primitive type "' + options.type + '" is not supported.'
`Specified primitive type "${options.type}" is not supported.`
);

@@ -181,3 +179,3 @@ }

Parser.prototype.choice = function(varName, options) {
if (arguments.length == 1 && typeof varName === "object") {
if (arguments.length === 1 && typeof varName === "object") {
options = varName;

@@ -199,5 +197,3 @@ varName = null;

if (!options.choices[key]) {
throw new Error(
"Choice Case " + key + " of " + varName + " is not valid."
);
throw new Error(`Choice Case ${key} of ${varName} is not valid.`);
}

@@ -211,5 +207,3 @@

throw new Error(
'Specified primitive type "' +
options.choices[key] +
'" is not supported.'
`Specified primitive type "${options.choices[key]}" is not supported.`
);

@@ -223,3 +217,3 @@ }

Parser.prototype.nest = function(varName, options) {
if (arguments.length == 1 && typeof varName === "object") {
if (arguments.length === 1 && typeof varName === "object") {
options = varName;

@@ -253,3 +247,3 @@ varName = null;

default:
throw new Error("Invalid endianess: " + endianess);
throw new Error(`Invalid endianess: ${endianess}`);
}

@@ -338,3 +332,3 @@

Parser.prototype.compile = function() {
var src = "(function(buffer, constructorFn, Long) { " + this.getCode() + " })";
var src = `(function(buffer, constructorFn, Long) { ${this.getCode()} })`;
this.compiled = vm.runInThisContext(src);

@@ -425,3 +419,3 @@ };

if (this.type) {
this["generate" + this.type](ctx);
this[`generate${this.type}`](ctx);
this.generateAssert(ctx);

@@ -478,3 +472,3 @@ }

Object.keys(PRIMITIVE_TYPES).forEach(function(type) {
Parser.prototype["generate" + type] = function(ctx) {
Parser.prototype[`generate${type}`] = function(ctx) {
ctx.pushCode(

@@ -500,4 +494,4 @@ "{0} = buffer.read{1}(offset);",

var sum = 0;
ctx.bitFields.forEach(function(parser) {
sum += parser.options.length;
ctx.bitFields.forEach(function(p) {
sum += p.options.length;
});

@@ -532,11 +526,11 @@

var isBigEndian = this.endian === "be";
ctx.bitFields.forEach(function(parser) {
ctx.bitFields.forEach(function(p) {
ctx.pushCode(
"{0} = {1} >> {2} & {3};",
parser.varName,
p.varName,
val,
isBigEndian ? sum - bitOffset - parser.options.length : bitOffset,
(1 << parser.options.length) - 1
isBigEndian ? sum - bitOffset - p.options.length : bitOffset,
(1 << p.options.length) - 1
);
bitOffset += parser.options.length;
bitOffset += p.options.length;
});

@@ -719,10 +713,9 @@

ctx.pushCode("switch({0}) {", tag);
Object.keys(this.options.choices).forEach(function(tag) {
var type = this.options.choices[tag];
if (isNaN(parseInt(tag, 10))) {
ctx.pushCode("case '{0}':", tag);
Object.keys(this.options.choices).forEach(function(t) {
var type = this.options.choices[t];
if (Number.isNaN(parseInt(t, 10))) {
ctx.pushCode("case '{0}':", t);
} else {
ctx.pushCode("case {0}:", t);
}
else {
ctx.pushCode("case {0}:", tag);
}
this.generateChoiceCase(ctx, this.varName, type);

@@ -772,10 +765,10 @@ ctx.pushCode("break;");

///////////////////// CRAM-specific types //////////////////////////
Parser.prototype.itf8 = function(varName,options) {
return this.setNextParser('itf8', varName,options);
// /////////////////// CRAM-specific types //////////////////////////
Parser.prototype.itf8 = function(varName, options) {
return this.setNextParser("itf8", varName, options);
};
Parser.prototype.generateItf8 = function(ctx) {
const name = ctx.generateVariable(this.varName)
const countFlags = ctx.generateTmpVariable()
const name = ctx.generateVariable(this.varName);
const countFlags = ctx.generateTmpVariable();
ctx.pushCode(`

@@ -801,12 +794,12 @@ var ${countFlags} = buffer[offset];

}
`)
`);
};
Parser.prototype.ltf8 = function(varName,options) {
return this.setNextParser('ltf8', varName,options);
Parser.prototype.ltf8 = function(varName, options) {
return this.setNextParser("ltf8", varName, options);
};
Parser.prototype.generateLtf8 = function(ctx) {
const name = ctx.generateVariable(this.varName)
const countFlags = ctx.generateTmpVariable()
const name = ctx.generateVariable(this.varName);
const countFlags = ctx.generateTmpVariable();
ctx.pushCode(`

@@ -853,9 +846,9 @@ var ${countFlags} = buffer[offset];

}
`)
}
`);
};
//========================================================================================
//= =======================================================================================
// Exports
//========================================================================================
//= =======================================================================================
exports.Parser = Parser;

@@ -1,4 +0,4 @@

//========================================================================================
//= =======================================================================================
// class Context
//========================================================================================
//= =======================================================================================

@@ -29,4 +29,4 @@ //----------------------------------------------------------------------------------------

while (/^\$parent\./.test(name)) {
arr.pop()
name = name.replace(/^\$parent\./, '')
arr.pop();
name = name.replace(/^\$parent\./, "");
}

@@ -48,3 +48,5 @@

case "function":
return "(" + val + ").call(" + this.generateVariable() + ", vars)";
return `(${val}).call(${this.generateVariable()}, vars)`;
default:
return undefined;
}

@@ -59,8 +61,6 @@ };

this.pushCode(
"return process.nextTick(function() { callback(new Error(" +
err +
"), vars); });"
`return process.nextTick(function() { callback(new Error(${err}), vars); });`
);
} else {
this.pushCode("throw new Error(" + err + ");");
this.pushCode(`throw new Error(${err});`);
}

@@ -70,3 +70,3 @@ };

Context.prototype.generateTmpVariable = function() {
return "$tmp" + this.tmpVariableCount++;
return `$tmp${this.tmpVariableCount++}`;
};

@@ -77,3 +77,3 @@

this.code += Context.interpolate.apply(this, args) + "\n";
this.code += `${Context.interpolate.apply(this, args)}\n`;
};

@@ -80,0 +80,0 @@

{
"name": "@gmod/binary-parser",
"version": "1.3.3",
"version": "1.3.4",
"description": "Blazing-fast binary parser builder",
"main": "lib/binary_parser.js",
"main": "dist/binary_parser.js",
"devDependencies": {
"istanbul": "^0.4.5",
"mocha": "^3.5.3",
"opn-cli": "^3.1.0",
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"eslint": "^5.14.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-prettier": "^2.6.0",
"jest": "^24.7.1",
"mocha": "^6.0.0",
"prettier": "^1.9.2",
"webpack": "^4.6.0",
"webpack-cli": "^2.0.15"
"puppeteer": "^1.11.0",
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1"
},
"scripts": {
"fmt": "npx prettier --write '{lib,test,example}/**/*.js'",
"check-fmt": "npx prettier --list-different '{lib,test,example}/**/*.js'",
"test": "npx mocha --reporter spec",
"cover": "npx istanbul cover --report html node_modules/.bin/_mocha",
"test-webpack": "npx webpack --config test/browser/webpack.config.js && opn test/browser/run-mocha.html"
"test": "jest",
"lint": "eslint lib example test/*.js",
"build": "babel lib -d dist",
"test-webpack": "webpack --config test/browser/webpack.config.js && node test/browser/run-puppeteer.js"
},

@@ -21,0 +30,0 @@ "keywords": [

@@ -0,4 +1,13 @@

# binary-parser
[![Greenkeeper badge](https://badges.greenkeeper.io/GMOD/binary-parser.svg)](https://greenkeeper.io/)
[![Build Status](https://travis-ci.com/GMOD/binary-parser.svg?branch=master)](https://travis-ci.com/GMOD/binary-parser)
[![codecov](https://codecov.io/gh/GMOD/binary-parser/branch/master/graph/badge.svg)](https://codecov.io/gh/GMOD/binary-parser)
@gmod/binary-parser is a fork of https://github.com/keichi/binary-parser that also handles 64-bit longs and itf8 and ltf8 types
## Installation
Binary-parser can be installed with [npm](https://npmjs.org/):

@@ -10,2 +19,7 @@

Important! Default this library is default little endian instead instead of big endian while https://github.com/keichi/binary-parser is default big endian
Example of reading a 64-bit int
.buffer('mylong64bitint', { length: 8, formatter: function(buf) { return Long.fromBytes(buf, true, this.endian==='le').toNumber() } })
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