diff --git a/decode.js b/decode.js index a6d0135..4482a39 100644 --- a/decode.js +++ b/decode.js @@ -10,10 +10,11 @@ function read(buf, offset) { , counter = offset , b , l = buf.length - + do { if(counter >= l) { - read.bytesRead = 0 + read.bytes = 0 + read.bytesRead = 0 // DEPRECATED return undefined } b = buf[counter++] @@ -22,8 +23,8 @@ function read(buf, offset) { : (b & REST) * Math.pow(2, shift) shift += 7 } while (b >= MSB) - + read.bytes = counter - offset - + return res } diff --git a/test.js b/test.js index 594181e..e746562 100644 --- a/test.js +++ b/test.js @@ -126,6 +126,7 @@ test('buffer too short', function (assert) { while(l--) { var val = decode(buffer.slice(0, l)) assert.equal(val, undefined) + assert.equal(decode.bytes, 0) assert.equal(decode.bytesRead, 0) } assert.end()