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.5 to 1.4.0

dist/binary_parser.d.ts

235

dist/context.js

@@ -1,139 +0,146 @@

"use strict";function _typeof(obj) {if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {_typeof = function _typeof(obj) {return typeof obj;};} else {_typeof = function _typeof(obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};}return _typeof(obj);} //= =======================================================================================
// class Context
//= =======================================================================================
"use strict";
//----------------------------------------------------------------------------------------
// constructor
//----------------------------------------------------------------------------------------
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Context = void 0;
var Context = function Context() {
this.code = "";
this.scopes = [["vars"]];
this.isAsync = false;
this.bitFields = [];
this.tmpVariableCount = 0;
this.references = {};
};
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
//----------------------------------------------------------------------------------------
// public methods
//----------------------------------------------------------------------------------------
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
Context.prototype.generateVariable = function (name) {
var arr = [];
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
Array.prototype.push.apply(arr, this.scopes[this.scopes.length - 1]);
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
// $parent. prefixes allow sub-parsers to access values of their parent parsers
while (/^\$parent\./.test(name)) {
arr.pop();
name = name.replace(/^\$parent\./, "");
}
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
if (name) {
arr.push(name);
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
return arr.join(".");
};
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
Context.prototype.generateOption = function (val) {
switch (_typeof(val)) {
case "number":
return val.toString();
case "string":
return this.generateVariable(val);
case "function":
return "(".concat(val, ").call(").concat(this.generateVariable(), ", vars)");
default:
return undefined;}
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
};
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
Context.prototype.generateError = function () {
var args = Array.prototype.slice.call(arguments);
var err = Context.interpolate.apply(this, args);
var Context =
/*#__PURE__*/
function () {
function Context() {
_classCallCheck(this, Context);
if (this.isAsync) {
this.pushCode("return process.nextTick(function() { callback(new Error(".concat(
err, "), vars); });"));
_defineProperty(this, "code", '');
} else {
this.pushCode("throw new Error(".concat(err, ");"));
}
};
_defineProperty(this, "scopes", [['vars']]);
Context.prototype.generateTmpVariable = function () {
return "$tmp".concat(this.tmpVariableCount++);
};
_defineProperty(this, "bitFields", []);
Context.prototype.pushCode = function () {
var args = Array.prototype.slice.call(arguments);
_defineProperty(this, "tmpVariableCount", 0);
this.code += "".concat(Context.interpolate.apply(this, args), "\n");
};
Context.prototype.pushPath = function (name) {
if (name) {
this.scopes[this.scopes.length - 1].push(name);
_defineProperty(this, "references", {});
}
};
Context.prototype.popPath = function (name) {
if (name) {
this.scopes[this.scopes.length - 1].pop();
}
};
_createClass(Context, [{
key: "generateVariable",
value: function generateVariable(name) {
var arr = [];
var scopes = this.scopes[this.scopes.length - 1];
arr.push.apply(arr, _toConsumableArray(scopes));
Context.prototype.pushScope = function (name) {
this.scopes.push([name]);
};
if (name) {
arr.push(name);
}
Context.prototype.popScope = function () {
this.scopes.pop();
};
return arr.join('.');
}
}, {
key: "generateOption",
value: function generateOption(val) {
switch (_typeof(val)) {
case 'number':
return val.toString();
Context.prototype.addReference = function (alias) {
if (this.references[alias]) return;
this.references[alias] = { resolved: false, requested: false };
};
case 'string':
return this.generateVariable(val);
Context.prototype.markResolved = function (alias) {
this.references[alias].resolved = true;
};
case 'function':
return "(".concat(val, ").call(").concat(this.generateVariable(), ", vars)");
}
}
}, {
key: "generateError",
value: function generateError(err) {
this.pushCode('throw new Error(' + err + ');');
}
}, {
key: "generateTmpVariable",
value: function generateTmpVariable() {
return '$tmp' + this.tmpVariableCount++;
}
}, {
key: "pushCode",
value: function pushCode(code) {
this.code += code + '\n';
}
}, {
key: "pushPath",
value: function pushPath(name) {
if (name) {
this.scopes[this.scopes.length - 1].push(name);
}
}
}, {
key: "popPath",
value: function popPath(name) {
if (name) {
this.scopes[this.scopes.length - 1].pop();
}
}
}, {
key: "pushScope",
value: function pushScope(name) {
this.scopes.push([name]);
}
}, {
key: "popScope",
value: function popScope() {
this.scopes.pop();
}
}, {
key: "addReference",
value: function addReference(alias) {
if (this.references[alias]) return;
this.references[alias] = {
resolved: false,
requested: false
};
}
}, {
key: "markResolved",
value: function markResolved(alias) {
this.references[alias].resolved = true;
}
}, {
key: "markRequested",
value: function markRequested(aliasList) {
var _this = this;
Context.prototype.markRequested = function (aliasList) {
aliasList.forEach(
function (alias) {
this.references[alias].requested = true;
}.bind(this));
aliasList.forEach(function (alias) {
_this.references[alias].requested = true;
});
}
}, {
key: "getUnresolvedReferences",
value: function getUnresolvedReferences() {
var references = this.references;
return Object.keys(this.references).filter(function (alias) {
return !references[alias].resolved && !references[alias].requested;
});
}
}]);
};
return Context;
}();
Context.prototype.getUnresolvedReferences = function () {
var references = this.references;
return Object.keys(this.references).filter(function (alias) {
return !references[alias].resolved && !references[alias].requested;
});
};
//----------------------------------------------------------------------------------------
// private methods
//----------------------------------------------------------------------------------------
Context.interpolate = function (s) {
var re = /{\d+}/g;
var matches = s.match(re);
var params = Array.prototype.slice.call(arguments, 1);
if (matches) {
matches.forEach(function (match) {
var index = parseInt(match.substr(1, match.length - 2), 10);
s = s.replace(match, params[index].toString());
});
}
return s;
};
exports.Context = Context;
exports.Context = Context;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL2xpYi9jb250ZXh0LnRzIl0sIm5hbWVzIjpbIkNvbnRleHQiLCJuYW1lIiwiYXJyIiwic2NvcGVzIiwibGVuZ3RoIiwicHVzaCIsImpvaW4iLCJ2YWwiLCJ0b1N0cmluZyIsImdlbmVyYXRlVmFyaWFibGUiLCJlcnIiLCJwdXNoQ29kZSIsInRtcFZhcmlhYmxlQ291bnQiLCJjb2RlIiwicG9wIiwiYWxpYXMiLCJyZWZlcmVuY2VzIiwicmVzb2x2ZWQiLCJyZXF1ZXN0ZWQiLCJhbGlhc0xpc3QiLCJmb3JFYWNoIiwiT2JqZWN0Iiwia2V5cyIsImZpbHRlciJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztJQUVhQSxPOzs7Ozs7a0NBQ0osRTs7b0NBQ0UsQ0FBQyxDQUFDLE1BQUQsQ0FBRCxDOzt1Q0FDYSxFOzs4Q0FDSCxDOzt3Q0FDd0QsRTs7Ozs7cUNBRTFEQyxJLEVBQWU7QUFDOUIsVUFBTUMsR0FBRyxHQUFHLEVBQVo7QUFFQSxVQUFNQyxNQUFNLEdBQUcsS0FBS0EsTUFBTCxDQUFZLEtBQUtBLE1BQUwsQ0FBWUMs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Skge1xuICAgIGFsaWFzTGlzdC5mb3JFYWNoKGFsaWFzID0+IHtcbiAgICAgIHRoaXMucmVmZXJlbmNlc1thbGlhc10ucmVxdWVzdGVkID0gdHJ1ZTtcbiAgICB9KTtcbiAgfVxuXG4gIGdldFVucmVzb2x2ZWRSZWZlcmVuY2VzKCkge1xuICAgIGNvbnN0IHJlZmVyZW5jZXMgPSB0aGlzLnJlZmVyZW5jZXM7XG4gICAgcmV0dXJuIE9iamVjdC5rZXlzKHRoaXMucmVmZXJlbmNlcykuZmlsdGVyKFxuICAgICAgYWxpYXMgPT4gIXJlZmVyZW5jZXNbYWxpYXNdLnJlc29sdmVkICYmICFyZWZlcmVuY2VzW2FsaWFzXS5yZXF1ZXN0ZWQsXG4gICAgKTtcbiAgfVxufVxuIl19
//= =======================================================================================
// Globals
//= =======================================================================================
var { Buffer } = require("buffer");
var vm = require("vm");

@@ -5,0 +6,0 @@

{
"name": "@gmod/binary-parser",
"version": "1.3.5",
"version": "1.4.0",
"description": "Blazing-fast binary parser builder",

@@ -16,3 +16,3 @@ "main": "dist/binary_parser.js",

"eslint-plugin-import": "^2.10.0",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-prettier": "^3.1.0",
"jest": "^24.7.1",

@@ -22,3 +22,3 @@ "mocha": "^6.0.0",

"puppeteer": "^1.11.0",
"webpack": "^4.28.4",
"webpack": "^4.37.0",
"webpack-cli": "^3.2.1"

@@ -32,2 +32,5 @@ },

},
"browser": {
"vm": "./vm-browser.js"
},
"keywords": [

@@ -34,0 +37,0 @@ "binary",

@@ -19,6 +19,23 @@

Important! Default this library is default little endian instead instead of big endian while https://github.com/keichi/binary-parser is default big endian
## Special data types
The ITF-8 and LTF-8 types documented in https://samtools.github.io/hts-specs/CRAMv3.pdf
The 64-bit parsing in this library is done by https://www.npmjs.com/package/long and simply returns .toNumber() on the parsed 64 bit data.
You can also access `Long` inside formatter callbacks (this is not possible in keichi/binary-parser since these are eval'd and the `Long` library instance is not available to the eval'd code)
## Differences with keichi/binary-parser
* This library is default little endian instead instead of big endian while https://github.com/keichi/binary-parser is default big endian
* The return value of the parse `{result: {<parsed results>},offset: <number of bytes parsed>}` instead of just `{<parsed results>}`
## Example usage
Example of reading a 64-bit int
new Parser()
.uint64('mylong64bitint')

@@ -29,2 +46,2 @@ .int64('mylong64bitint')

Verification of whether it is valid 2^53 max int is not done for 64 bit either
Verification of whether the long is a valid 2^53 int is not done for 64 bit numbers. If you require this make a custom callback using `Long` in a formatter for buffer

Sorry, the diff of this file is too big to display

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