cbarrick/CircularBuffer — pull request #1 by noodlefrenzy (2014-12-12 01:50:00+00:00)
Title: Fix issue with expand after read causing tail to be set incorrectly

I've been using this extensively in my node-amqp-1-0 module to keep track of incoming data, and it's been incredibly useful. However, this bug just bit me when I had a bunch of data coming in all at once, and reads wound up getting interleaved with expands - the "tail" gets set from self.length, which internally uses the "head" that's already been reassigned. Just fetching the length before setting anything solved the problem - I tried to pull out a simple repro case.

I also altered toString to accept toString('hex'), which is immensely useful for me in debugging.

Thanks again for the great module, hope an unsolicited PR is ok :)