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

bipf

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bipf - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

test/compare.js

87

index.js

@@ -193,3 +193,4 @@ var varint = require('varint')

function seekKey (buffer, start, target) {
target = Buffer.isBuffer(target) ? target : new Buffer(target)
if(start === -1) return -1
target = Buffer.isBuffer(target) ? target : Buffer.from(target)
var targetLength = target.length

@@ -248,3 +249,3 @@ var tag = varint.decode(buffer, start)

start = seekKey(buffer, start, string)
if(start == -1) return -1
if(start === -1) return -1
}

@@ -254,5 +255,25 @@ return start

//for some reason, seek path
function createSeekPathSrc(target) {
return (
'"use strict";\n' + //go fast sauce!
target.map(function (e, i) {
return ' var k'+i+' = Buffer.from('+ JSON.stringify(e) +');' //strings only!
}).join('\n') + '\n'+
" return function (buffer, start) {\n"+
target.map(function (_, i) {
return " start = seekKey(buffer, start, k"+i+")"
}).join('\n') + '\n' +
' return start;\n'+
'}\n'
)
}
function createSeekPath(target) {
return new Function('seekKey', createSeekPathSrc(target))(seekKey)
}
function compareString (buffer, start, target) {
if(start === -1) return null
target = Buffer.isBuffer(target) ? target : new Buffer(target)
target = Buffer.isBuffer(target) ? target : Buffer.from(target)
var tag = varint.decode(buffer, start)

@@ -268,2 +289,44 @@ if(tag & TAG_MASK !== STRING) return null

function compare (buffer1, start1, buffer2, start2) {
//handle null pointers...
// console.log(start1, start2)
if(start1 === -1 || start2 === -1)
return start1 - start2
var tag1 = varint.decode(buffer1, start1)
var len1 = varint.decode.bytes
var tag2 = varint.decode(buffer2, start2)
var len2 = varint.decode.bytes
var type1 = tag1 & TAG_MASK
var type2 = tag2 & TAG_MASK
//allow comparison of number types. **javascriptism**
//maybe it's better to just have one number type? how can I make a varint double?
if(type1 === INT && type2 === DOUBLE)
return buffer1.readIntLE(start1+len1) - buffer2.readDoubleLE(start2+len2)
if(type1 === DOUBLE && type1 === INT)
return buffer1.readDoubleLE(start1+len1) - buffer2.readInt32LE(start2+len2)
if(type1 !== type2)
return type1 - type2
//if they are the same type, compare encoded value.
//TODO: compare by type semantics...
if(type1 === DOUBLE)
return buffer1.readDoubleLE(start1+len1) - buffer2.readDoubleLE(start2+len2)
if(type1 === INT)
return buffer1.readInt32LE(start1+len1) - buffer2.readInt32LE(start2+len2)
//except for strings, sort shorter values first
if(type1 !== STRING) {
var result = type1 - type2
if(result) return result
}
return buffer1.compare(buffer2,
start2+len2, start2+len2+(tag2 >> TAG_SIZE),
start1+len1, start1+len1 + (tag1 >> TAG_SIZE)
)
}
function iterate(buffer, start, iter) {

@@ -299,2 +362,15 @@ var tag = varint.decode(buffer, start)

function createCompareAt(paths) {
var getPaths = paths.map(createSeekPath)
return function (a, b) {
for(var i = 0; i < getPaths.length; i++) {
var _a = getPaths[i](a, 0)
var _b = getPaths[i](b, 0)
var r = compare(a, _a, b, _b)
if(r) return r
}
return 0
}
}
module.exports = {

@@ -311,4 +387,7 @@ encode: encode,

seekKey2: seekKey2,
createSeekPath: createSeekPath,
seekPath: seekPath,
compareString: compareString,
compare: compare,
createCompareAt: createCompareAt,
iterate: iterate,

@@ -327,3 +406,1 @@ types: {

4

package.json
{
"name": "bipf",
"description": "binary in-place format",
"version": "1.0.0",
"version": "1.1.0",
"homepage": "https://github.com/dominictarr/binary",

@@ -17,3 +17,3 @@ "repository": {

"scripts": {
"test": "node test.js"
"test": "node test/index.js && node test/compare.js"
},

@@ -20,0 +20,0 @@ "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)",

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