Socket
Socket
Sign inDemoInstall

bitsyntax

Package Overview
Dependencies
4
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.1.0

LICENSE

8

lib/compile.js

@@ -16,2 +16,4 @@ // Compile patterns to recognisers and constructors

var Buffer = require('safe-buffer').Buffer;
var lines = [];

@@ -282,3 +284,3 @@ function $start() {

size_of(segments);
$line('var buf = new Buffer(buffersize);');
$line('var buf = Buffer.alloc(buffersize);');
$line('var offset = 0;');

@@ -289,4 +291,4 @@ emit_write(segments);

return new Function('write_int', 'write_float',
$result())(write_int, write_float);
return new Function('write_int', 'write_float', 'Buffer',
$result())(write_int, write_float, Buffer);
}

@@ -293,0 +295,0 @@

@@ -8,2 +8,3 @@ // -*- js-indent-level: 2 -*-

var ints = require('buffer-more-ints');
var Buffer = require('safe-buffer').Buffer;

@@ -14,3 +15,2 @@ // Interpret the pattern, writing values into a buffer

var segment = pattern[i];
switch (segment.type) {

@@ -36,3 +36,3 @@ case 'string':

var bufsize = size_of(pattern, bindings);
var buf = new Buffer(bufsize);
var buf = Buffer.alloc(bufsize);
write(buf, 0, pattern, bindings);

@@ -39,0 +39,0 @@ return buf;

@@ -36,7 +36,5 @@ // -*- js-indent: 2 -*-

var ints = require('buffer-more-ints');
var ints = require('buffer-more-ints'),
debug = require('debug')('bitsyntax-Interpreter');
var debug = (process.env.DEBUG) ?
function(s) { console.log(s); } : function () {};
function parse_int(bin, off, sizeInBytes, bigendian, signed) {

@@ -43,0 +41,0 @@ switch (sizeInBytes) {

{
"author": {
"name": "Michael Bridgen",
"email": "<mikeb@squaremobius.net>"
"name": "Michael Bridgen",
"email": "<mikeb@squaremobius.net>"
},
"name": "bitsyntax",
"description": "Pattern-matching on byte buffers",
"version": "0.0.4",
"license": "MIT",
"version": "0.1.0",
"repository": {

@@ -19,11 +20,13 @@ "type": "git",

"engines": {
"node": ">=0.6"
"node": ">=0.8"
},
"dependencies": {
"buffer-more-ints": "0.0.2"
"buffer-more-ints": "~1.0.0",
"debug": "~2.6.9",
"safe-buffer": "~5.1.2"
},
"devDependencies": {
"pegjs": "0.7.x",
"mocha": "1.x"
"mocha": "1.x",
"pegjs": "0.7.0"
}
}

@@ -7,2 +7,4 @@ var assert = require('assert');

var Buffer = require('safe-buffer').Buffer;
TEST_CASES = [

@@ -14,6 +16,6 @@ ['n:8', {n:255}, [255]],

['n:8, s/binary', {n: 255, s: new Buffer("foobar")}, [255, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]],
['n:8, s/binary', {n: 255, s: Buffer.from("foobar")}, [255, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]],
['n:8, "foobar", m:8', {n: 255, m:0}, [255, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72, 0]],
['n:8, s:n/binary', {n:6, s: new Buffer('foobar')}, [6, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]],
['n:8, s:n/binary', {n:4, s: new Buffer('foobar')}, [4, 0x66, 0x6f, 0x6f, 0x62]],
['n:8, s:n/binary', {n:6, s: Buffer.from('foobar')}, [6, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]],
['n:8, s:n/binary', {n:4, s: Buffer.from('foobar')}, [4, 0x66, 0x6f, 0x6f, 0x62]],
['n:size', {n:4, size:8}, [4]],

@@ -34,3 +36,3 @@ ['206:n/unit:8', {n:1}, [206]]

test(c[0], function() {
var buf = new Buffer(1024);
var buf = Buffer.alloc(1024);
var end = write(buf, 7, p, c[1]);

@@ -37,0 +39,0 @@ buf = buf.slice(7, end);

@@ -6,2 +6,3 @@ var match = require('../').match;

var Buffer = require('safe-buffer').Buffer;

@@ -59,6 +60,6 @@ var INT_TESTS = [

test(p[0], function() {
assert.deepEqual({n: tc[1]}, match(pattern, new Buffer(tc[0])));
assert.deepEqual({n: tc[1]}, match(pattern, Buffer.from(tc[0])));
});
test(p[0], function() {
assert.deepEqual({n: tc[1]}, cpattern(new Buffer(tc[0])));
assert.deepEqual({n: tc[1]}, cpattern(Buffer.from(tc[0])));
});

@@ -102,3 +103,3 @@ });

test(p[0], function() {
var m = match(pattern, new Buffer(tc[0]));
var m = match(pattern, Buffer.from(tc[0]));
assert.ok(m.n !== undefined);

@@ -108,3 +109,3 @@ assert.ok(Math.abs(tc[1] - m.n) < precision);

test(p[0], function() {
var m = cpattern(new Buffer(tc[0]));
var m = cpattern(Buffer.from(tc[0]));
assert.ok(m.n !== undefined);

@@ -133,13 +134,13 @@ assert.ok(Math.abs(tc[1] - m.n) < precision);

test(p[0], function() {
assert.deepEqual({n: new Buffer(p[1])},
match(pattern, new Buffer(p[1])));
assert.deepEqual({n: new Buffer(p[1])},
cpattern(new Buffer(p[1])));
assert.deepEqual({n: Buffer.from(p[1])},
match(pattern, Buffer.from(p[1])));
assert.deepEqual({n: Buffer.from(p[1])},
cpattern(Buffer.from(p[1])));
});
test(prest, function() {
var plusgarbage = p[1].concat([5, 98, 23, 244]);
assert.deepEqual({n: new Buffer(p[1])},
match(patternrest, new Buffer(plusgarbage)));
assert.deepEqual({n: new Buffer(p[1])},
cpatternrest(new Buffer(plusgarbage)));
assert.deepEqual({n: Buffer.from(p[1])},
match(patternrest, Buffer.from(plusgarbage)));
assert.deepEqual({n: Buffer.from(p[1])},
cpatternrest(Buffer.from(plusgarbage)));
});

@@ -155,3 +156,3 @@ });

['size, n:size/binary',
[[[2, 5, 6], new Buffer([5, 6])]]],
[[[2, 5, 6], Buffer.from([5, 6])]]],

@@ -169,6 +170,6 @@ ['a, b:a, n:b',

test(p[0], function() {
assert.deepEqual(tc[1], match(pattern, new Buffer(tc[0])).n);
assert.deepEqual(tc[1], match(pattern, Buffer.from(tc[0])).n);
});
test(p[0], function() {
assert.deepEqual(tc[1], cpattern(new Buffer(tc[0])).n);
assert.deepEqual(tc[1], cpattern(Buffer.from(tc[0])).n);
});

@@ -190,3 +191,3 @@ });

test(p[0], function() {
var res = match(pattern, new Buffer(p[1]));
var res = match(pattern, Buffer.from(p[1]));
assert.equal(res.n, p[2]);

@@ -193,0 +194,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc