Merge pull request #751 from eordano/fix/bufferReadNoLength
Remove calls to read() with no arguments
This commit is contained in:
commit
c7edfdd2b1
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var $ = require('../util/preconditions');
|
||||||
var bufferUtil = require('../util/buffer');
|
var bufferUtil = require('../util/buffer');
|
||||||
var BN = require('../crypto/bn');
|
var BN = require('../crypto/bn');
|
||||||
|
|
||||||
|
@ -28,11 +29,7 @@ BufferReader.prototype.eof = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
BufferReader.prototype.read = function(len) {
|
BufferReader.prototype.read = function(len) {
|
||||||
if (_.isUndefined(len)) {
|
$.checkArgument(!_.isUndefined(len), 'Must specify a length');
|
||||||
len = this.buf.length;
|
|
||||||
console.error('No length provided');
|
|
||||||
console.trace();
|
|
||||||
}
|
|
||||||
var buf = this.buf.slice(this.pos, this.pos + len);
|
var buf = this.buf.slice(this.pos, this.pos + len);
|
||||||
this.pos = this.pos + len;
|
this.pos = this.pos + len;
|
||||||
return buf;
|
return buf;
|
||||||
|
|
|
@ -44,7 +44,7 @@ describe('BufferReader', function() {
|
||||||
it('should return the same buffer', function() {
|
it('should return the same buffer', function() {
|
||||||
var buf = new Buffer([0]);
|
var buf = new Buffer([0]);
|
||||||
var br = new BufferReader({buf: buf});
|
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() {
|
it('should return a buffer of this length', function() {
|
||||||
|
@ -269,7 +269,7 @@ describe('BufferReader', function() {
|
||||||
it('should reverse this [0, 1]', function() {
|
it('should reverse this [0, 1]', function() {
|
||||||
var buf = new Buffer([0, 1]);
|
var buf = new Buffer([0, 1]);
|
||||||
var br = new BufferReader({buf: buf});
|
var br = new BufferReader({buf: buf});
|
||||||
br.reverse().read().toString('hex').should.equal('0100');
|
br.reverse().readAll().toString('hex').should.equal('0100');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue