JoshGlazebrook / smart-buffer

smart-buffer is a Buffer wrapper that adds automatic read & write offset tracking, string operations, data insertions, and more.
https://www.npmjs.com/package/smart-buffer
MIT License
102 stars 18 forks source link

readBuffer with len to undefined does not work #2

Closed erakis closed 8 years ago

erakis commented 8 years ago

Hi,

When calling the function readBuffer() without specifying the len, the internal endpoint variable is set to NaN.

But in the doc : @param len {Number} Numbers of bytes to read. (Defaults to the remaining data length)

Defaults is not set properly. Fix proposed :

    SmartBuffer.prototype.readBuffer = function (len) {
        var endpoint = Math.min(this.length, this._readOffset + (len || this.length));
        var ret = this.buff.slice(this._readOffset, endpoint);
        this._readOffset = endpoint;
        return ret;
    };

Sorry, I don't have time to create a pull requests at this time.

JoshGlazebrook commented 8 years ago

Should be fixed. Thanks for spotting that!