Node.js SlowBuffer detection
Problem
I added an xor method to the buffer class that make sure that argument instanceof Buffer
. The require('crypto')
has a method of randomBytes that gives an object that appears to be a slow buffer.
I am trying to allow xor method of Buffer to only allow Buffer objects and SlowBuffers, but key instanceof SlowBuffer
gives an error. Does anyone know how I can detect if key is an instanceof SlowBuffer?
var key;
crypto.randomBytes(10,function(err,bytes) {
key = bytes;
});
//key instanceof SlowBuffer
Problem courtesy of: Ra is dead
Solution
The http://nodejs.org/api/buffer.html#buffer_class_method_buffer_isbuffer_obj Buffer.isBuffer
method will return true for SlowBuffer and Buffer objects.
Solution courtesy of: Eric Zhang
Discussion
View additional discussion.