What is buffer-indexof?
The buffer-indexof npm package provides functionality to find the index of a buffer within another buffer. This is particularly useful when dealing with binary data streams where you need to locate specific sequences of bytes within a larger byte stream.
What are buffer-indexof's main functionalities?
Finding the index of a buffer within another buffer
This feature allows you to find the starting index of a pattern buffer within another buffer. It returns the index position where the pattern starts in the buffer. If the pattern is not found, it returns -1.
const bufferIndexOf = require('buffer-indexof');
const buffer = Buffer.from('hello world');
const pattern = Buffer.from('world');
const index = bufferIndexOf(buffer, pattern);
console.log(index); // Outputs: 6
Other packages similar to buffer-indexof
buffer-equals
This package provides functionality to check if two buffers are equal. While buffer-indexof is used to find the position of a buffer within another buffer, buffer-equals is used to compare two buffers for equality.
buffertools
Buffertools is a more comprehensive toolkit for manipulating buffers. It includes functionality similar to buffer-indexof, such as searching for buffers within buffers, but also includes additional tools like concatenation, slicing, and comparison of buffers.

buffer-indexof
find the index of a buffer in a buffer. should behave like String.indexOf etc.
var bindexOf = require('buffer-indexof');
var newLineBuffer = new Buffer("\n");
var b = new Buffer("hi\nho\nsilver");
bindexOf(b,newLineBuffer) === 2
bindexOf(b,newLineBuffer,3) === 5
bindexOf(b,newLineBuffer,6) === -1
CHANGELOG
- 1.0.0
- 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