Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
buffer-indexof-polyfill
Advanced tools
This is a polyfill for Buffer#indexOf introduced in NodeJS 4.0.
Weekly downloads
Package description
The buffer-indexof-polyfill npm package provides a polyfill for the `indexOf` method on Buffer instances in Node.js. This is particularly useful for environments or versions of Node.js where `Buffer.indexOf` is not available. It allows developers to search for sequences within buffer objects, similar to how strings are searched in JavaScript.
Finding the index of a string within a buffer
This feature allows you to find the first occurrence of a string within a buffer. The code sample demonstrates searching for the string 'world' within a buffer containing 'hello world', which returns the index 6, indicating the start of the match.
var indexOf = require('buffer-indexof-polyfill');
var buf = Buffer.from('hello world');
var index = indexOf(buf, 'world');
console.log(index); // Outputs: 6
Finding the index of a buffer within another buffer
This feature enables searching for a sequence of bytes (represented by a buffer) within another buffer. The example shows how to find a buffer containing 'world' within another buffer, yielding the same result as searching for a string.
var indexOf = require('buffer-indexof-polyfill');
var buf = Buffer.from('hello world');
var search = Buffer.from('world');
var index = indexOf(buf, search);
console.log(index); // Outputs: 6
Similar to buffer-indexof-polyfill, buffer-indexof provides functionality to find the index of a buffer within another buffer. The main difference is that buffer-indexof is not specifically a polyfill and may offer optimized performance for certain use cases.
While not directly offering the same functionality, safe-buffer provides a safer way to work with buffers in Node.js, including a consistent API across different Node.js versions. It can be used alongside methods like `indexOf` to ensure compatibility and safety.
Readme
This is a polyfill for Buffer#indexOf
and Buffer#lastIndexOf introduced in NodeJS 4.0.
require("buffer-indexof-polyfill");
new Buffer("buffer").indexOf("uff") // return 1
new Buffer("buffer").indexOf("abc") // return -1
npm install buffer-indexof-polyfill
FAQs
This is a polyfill for Buffer#indexOf introduced in NodeJS 4.0.
The npm package buffer-indexof-polyfill receives a total of 2,142,385 weekly downloads. As such, buffer-indexof-polyfill popularity was classified as popular.
We found that buffer-indexof-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.