Merge pull request #751 from eordano/fix/bufferReadNoLength

Remove calls to read() with no arguments
This commit is contained in:
Braydon Fuller 2014-12-15 17:56:56 -05:00
commit c7edfdd2b1
2 changed files with 4 additions and 7 deletions

View File

@ -1,6 +1,7 @@
'use strict';
var _ = require('lodash');
var $ = require('../util/preconditions');
var bufferUtil = require('../util/buffer');
var BN = require('../crypto/bn');
@ -28,11 +29,7 @@ BufferReader.prototype.eof = function() {
};
BufferReader.prototype.read = function(len) {
if (_.isUndefined(len)) {
len = this.buf.length;
console.error('No length provided');
console.trace();
}
$.checkArgument(!_.isUndefined(len), 'Must specify a length');
var buf = this.buf.slice(this.pos, this.pos + len);
this.pos = this.pos + len;
return buf;

View File

@ -44,7 +44,7 @@ describe('BufferReader', function() {
it('should return the same buffer', function() {
var buf = new Buffer([0]);
var br = new BufferReader({buf: buf});
br.read().toString('hex').should.equal(buf.toString('hex'));
br.readAll().toString('hex').should.equal(buf.toString('hex'));
});
it('should return a buffer of this length', function() {
@ -269,7 +269,7 @@ describe('BufferReader', function() {
it('should reverse this [0, 1]', function() {
var buf = new Buffer([0, 1]);
var br = new BufferReader({buf: buf});
br.reverse().read().toString('hex').should.equal('0100');
br.reverse().readAll().toString('hex').should.equal('0100');
});
});