Socket
Socket
Sign inDemoInstall

buffer-indexof

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

bm.js

71

index.js

@@ -7,5 +7,13 @@ module.exports = function bufferIndexOf(buf,search,offset){

for(var i=offset;i<buf.length;++i){
if(buf[i] != search[m]){
s = -1;
// <-- go back
// match abc to aabc
// 'aabc'
// 'aab'
// ^ no match
// a'abc'
// ^ set index here now and look at these again.
// 'abc' yay!
i -= m-1
m = 0;

@@ -19,3 +27,2 @@ }

}
}

@@ -26,1 +33,61 @@

}
module.exports.bm = function bm(buf,search,offset){
var m = 0, j = 0
var table = []
var ret = -1;
for(var i=offset||0;i<buf.length;++i){
console.log('i',i)
table[i] = [[i,0]]
if(buf[i] === search[0]) {
for(j = search.length-1;j>0;--j){
table[i].push([i+j,j])
console.log('j',j)
if(buf[i+j] !== search[j]) {
//i += j
j = -1
break
}
}
if(j === 0) {
ret = i
break
}
}
}
console.log(table)
renderTable(table,buf,search)
return ret
}
var chalk = require('chalk')
function renderTable(table,buf,search){
var s = ''
console.log('-----')
console.log('search:',search)
console.log('-----')
console.log(buf+'')
table.forEach(function(a){
if(!a) return;// console.log('')
a.forEach(function(v){
if(!v) return;
var pad = ''
while(pad.length < v[0]){
pad += ' '
}
if(search[v[1]] === buf[v[0]]) console.log(pad+chalk.green(search[v[1]]))
else console.log(pad+chalk.red(search[v[1]]))
})
})
console.log('-----')
}

3

package.json
{
"name": "buffer-indexof",
"description": "find the index of a buffer in a buffer",
"version": "1.0.0",
"version": "1.0.1",
"repository": {

@@ -15,4 +15,5 @@ "url": "git://github.com/soldair/node-buffer-indexof.git"

"devDependencies": {
"chalk": "^1.1.3",
"tape": "~1.1.0"
}
}

@@ -36,1 +36,3 @@ [![Build Status](https://secure.travis-ci.org/soldair/node-buffer-indexof.png)](http://travis-ci.org/soldair/node-buffer-indexof)

- fixed issue finding multibyte needles in haystack. thanks @imulus
- 1.0.1
- fixed failing to find partial matches as pointed out by @bahaa-aidi in #2

@@ -30,1 +30,9 @@ var test = require('tape');

})
test("can handle overlapping matches",function(t){
console.log(1,'aaaba'.indexOf('aaba'))
console.log(2,bindexOf(new Buffer('aaaba'), new Buffer('aaba')))
console.log(3,(new Buffer('aaaba')).indexOf(new Buffer('aaba')))
t.end()
})
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