Comparing version 1.3.0 to 1.4.0
17
index.js
@@ -275,3 +275,2 @@ var varint = require('varint') | ||
var b_tag = varint.decode(buffer, start+c) | ||
if(b_tag === t_tag && buffer.compare(target, t_start, t_length, start+c, start+c+t_length) === 0) | ||
@@ -401,3 +400,3 @@ return start+c+(b_tag>>TAG_SIZE)+varint.decode.bytes | ||
var type = tag & TAG_MASK | ||
if(type == OBJECT) { | ||
if(type === OBJECT) { | ||
for(var c = varint.decode.bytes; c < len;) { | ||
@@ -411,18 +410,16 @@ var key_start = start+c | ||
var next_start = varint.decode.bytes + (value_tag >> TAG_SIZE) | ||
iter(buffer, value_start, key_start) | ||
if (iter(buffer, value_start, key_start)) return start | ||
c += next_start | ||
} | ||
return start | ||
} | ||
else if(type == ARRAY) { | ||
else if(type === ARRAY) { | ||
var i = 0 | ||
for(var c = varint.decode.bytes; c < len;) { | ||
iter(buffer, start+c, i) | ||
var key_tag = varint.decode(buffer, start+c) | ||
c += varint.decode.bytes + (key_tag >> TAG_SIZE) | ||
if (iter(buffer, start+c, i++)) return start | ||
var value_tag = varint.decode(buffer, start+c) | ||
c += varint.decode.bytes + (value_tag >> TAG_SIZE) | ||
} | ||
} | ||
return -1 | ||
return start | ||
} else return -1 | ||
} | ||
@@ -429,0 +426,0 @@ |
{ | ||
"name": "bipf", | ||
"description": "binary in-place format", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"homepage": "https://github.com/dominictarr/binary", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -195,2 +195,9 @@ # bipf | ||
### iterate (buffer, start, fn) => void | ||
If the field at `start` is an object or array, then `iterate` will call the `fn` | ||
with arguments `fn(buffer, pointer, key)` for each subfield. If the field at | ||
`start` is not an array or object, this returns `-1`. You can stop/abort the | ||
iteration by making `fn` return any truthy value. | ||
### seekKey (buffer, start, target) => pointer | ||
@@ -197,0 +204,0 @@ |
@@ -49,3 +49,3 @@ var binary = require('../') | ||
return c+l //read_value(c-2, b) | ||
// c += | ||
// c += | ||
c+=l+2+l2+2 | ||
@@ -118,3 +118,3 @@ } | ||
tape('iterate', function (t) { | ||
tape('iterate object', function (t) { | ||
var pkg_buf = Buffer.alloc(binary.encodingLength(pkg)) | ||
@@ -132,3 +132,20 @@ binary.encode(pkg, pkg_buf, 0) | ||
tape('iterate array', function (t) { | ||
var myarr = ['cat', 'dog', 'bird', 'elephant']; | ||
var myarr_buf = Buffer.alloc(binary.encodingLength(myarr)); | ||
binary.encode(myarr, myarr_buf, 0); | ||
var expectedResults = [ | ||
[0, 2, 'cat'], | ||
[1, 6, 'dog'], | ||
[2, 10, 'bird'], | ||
[3, 15, 'elephant'], | ||
]; | ||
binary.iterate(myarr_buf, 0, function (buffer, pointer, key) { | ||
var expected = expectedResults.shift(); | ||
t.equal(key, expected[0], '' + expected[0]); | ||
t.equal(pointer, expected[1], '' + expected[1]); | ||
t.equal(binary.decode(buffer, pointer), expected[2], '' + expected[2]); | ||
}); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
255
0
2
33140
9
735