Skip to content

Commit 68cb7ab

Browse files
committed
bufferequals polyfill
1 parent 0872954 commit 68cb7ab

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

conditions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('lodash'),
2-
ipcheck = require('ipcheck');
2+
ipcheck = require('ipcheck'),
3+
bufferEquals = require('./lib/bufferequals');
34

45
var conditions = {
56
NumericEquals: function NumericEquals(a, b) {
@@ -58,11 +59,11 @@ var conditions = {
5859
},
5960
BinaryEquals: function BinaryEquals(a, b) {
6061
if(!_.isString(b) || !(a instanceof Buffer)) return false;
61-
return a.equals(new Buffer(b, 'base64'));
62+
return bufferEquals(a, new Buffer(b, 'base64'));
6263
},
6364
BinaryNotEquals: function BinaryEquals(a, b) {
6465
if(!_.isString(b) || !(a instanceof Buffer)) return false;
65-
return !a.equals(new Buffer(b, 'base64'));
66+
return !bufferEquals(a, new Buffer(b, 'base64'));
6667
},
6768
/*
6869
ArnEquals

lib/bufferequals.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function(a, b) {
2+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) return false;
3+
if (typeof a.equals === 'function') return a.equals(b);
4+
if (a === b) return true;
5+
if (a.length !== b.length) return false;
6+
for (var i = 0; i < a.length; i++) {
7+
if (a[i] !== b[i]) return false;
8+
}
9+
return true;
10+
};

0 commit comments

Comments
 (0)