What is buffer-equal?
The buffer-equal npm package is a simple utility for checking if two Node.js Buffer or Uint8Array instances contain the same bytes. It is primarily used for comparing buffers in a way that is both efficient and straightforward.
What are buffer-equal's main functionalities?
Buffer Equality Check
This feature allows you to compare two buffers to determine if they are equal. It returns true if they are equal, false otherwise.
const bufferEqual = require('buffer-equal');
const buf1 = Buffer.from('hello world');
const buf2 = Buffer.from('hello world');
const buf3 = Buffer.from('goodbye');
console.log(bufferEqual(buf1, buf2)); // true
console.log(bufferEqual(buf1, buf3)); // false
Other packages similar to buffer-equal
buffer-equals
This package offers a similar functionality to buffer-equal. It provides a method to compare two Node.js Buffer or Uint8Array objects for equality. The difference is mainly in the implementation and possibly in performance characteristics.
buffer-equal
Return whether two buffers are equal.
example
var bufferEqual = require('buffer-equal');
console.dir(bufferEqual(
new Buffer([253,254,255]),
new Buffer([253,254,255])
));
console.dir(bufferEqual(
new Buffer('abc'),
new Buffer('abcd')
));
console.dir(bufferEqual(
new Buffer('abc'),
'abc'
));
output:
true
false
undefined
methods
var bufferEqual = require('buffer-equal');
bufferEqual(a, b)
Return whether the two buffers a
and b
are equal.
If a
or b
is not a buffer, return undefined
.
install
With npm do:
npm install buffer-equal
license
MIT