Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js SlowBuffer detection

Node.js SlowBuffer detection


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


The Buffer.isBuffer method will return true for SlowBuffer and Buffer objects.

Solution courtesy of: Eric Zhang


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js SlowBuffer detection


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription