From 5759d8a705b3f2aacbe6e752efad1032af58d309 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 29 May 2014 23:16:20 +0200 Subject: [PATCH 1/3] bytesRead,bytesWritten -> bytes --- decode.js | 2 +- encode.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/decode.js b/decode.js index 6269e73..dbce40d 100644 --- a/decode.js +++ b/decode.js @@ -18,7 +18,7 @@ function read(buf, offset) { shift += 7 } while (b >= MSB) - read.bytesRead = counter - offset + read.bytes = counter - offset return res } diff --git a/encode.js b/encode.js index 63f5149..d395723 100644 --- a/encode.js +++ b/encode.js @@ -20,7 +20,7 @@ function encode(num, out, offset) { } out[offset] = num | 0 - encode.bytesWritten = offset - oldOffset + 1 + encode.bytes = offset - oldOffset + 1 return out } From d2f7af4ff9c80b6462009cdffb7a0007ea708b50 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 29 May 2014 23:18:02 +0200 Subject: [PATCH 2/3] fixed tests --- test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test.js b/test.js index 4c5f51d..4609f4f 100644 --- a/test.js +++ b/test.js @@ -13,7 +13,7 @@ test('fuzz test', function(assert) { encoded = encode(expect) var data = decode(encoded) assert.equal(expect, data, 'fuzz test: ' + expect.toString()) - assert.equal(decode.bytesRead, encoded.length) + assert.equal(decode.bytes, encoded.length) } assert.end() @@ -25,7 +25,7 @@ test('test single byte works as expected', function(assert) { buf[1] = 2 var data = decode(buf) assert.equal(data, 300, 'should equal 300') - assert.equal(decode.bytesRead, 2) + assert.equal(decode.bytes, 2) assert.end() }) @@ -43,7 +43,7 @@ test('test decode single bytes', function(assert) { buf[0] = expected var data = decode(buf) assert.equal(data, expected) - assert.equal(decode.bytesRead, 1) + assert.equal(decode.bytes, 1) assert.end() }) @@ -54,21 +54,21 @@ test('test decode multiple bytes with zero', function(assert) { buf[1] = expected var data = decode(buf) assert.equal(data, expected << 7) - assert.equal(decode.bytesRead, 2) + assert.equal(decode.bytes, 2) assert.end() }) test('encode single byte', function(assert) { var expected = randint(parseInt('1111111', '2')) assert.deepEqual(encode(expected), [expected]) - assert.equal(encode.bytesWritten, 1) + assert.equal(encode.bytes, 1) assert.end() }) test('encode multiple byte with zero first byte', function(assert) { var expected = 0x0F00 assert.deepEqual(encode(expected), [0x80, 0x1E]) - assert.equal(encode.bytesWritten, 2) + assert.equal(encode.bytes, 2) assert.end() }) @@ -101,7 +101,7 @@ test('fuzz test - big', function(assert) { encoded = encode(expect) var data = decode(encoded) assert.equal(expect, data, 'fuzz test: ' + expect.toString()) - assert.equal(decode.bytesRead, encoded.length) + assert.equal(decode.bytes, encoded.length) } assert.end() From 11bf118d964db104523590467557097a5b18f56e Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 29 May 2014 23:20:32 +0200 Subject: [PATCH 3/3] fix docs --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index df72382..a82dfc3 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ and returns that array filled with integers. decodes `data`, which can be either a buffer or array of integers, from position `offset` or default 0 and returns the decoded original integer. -### varint.decode.bytesRead +### varint.decode.bytes -if you also require the length (number of bytes) that were required to decode the integer you can access it via `varint.decode.bytesRead`. this is an integer property that will tell you the number of bytes that the last .decode() call had to use to decode. +if you also require the length (number of bytes) that were required to decode the integer you can access it via `varint.decode.bytes`. this is an integer property that will tell you the number of bytes that the last .decode() call had to use to decode. -### varint.encode.bytesWritten +### varint.encode.bytes -similar to `bytesRead` when encoding a number it can be useful to know how many bytes where written (especially if you pass an output array). you can access this via `varint.encode.bytesWritten` which holds the number of bytes written in the last encode. +similar to `decode.bytes` when encoding a number it can be useful to know how many bytes where written (especially if you pass an output array). you can access this via `varint.encode.bytes` which holds the number of bytes written in the last encode. ### varint.encodingLength(num)