allow bufferreader.read to specify length
...to be more symmetric with the write function of bufferwriter
This commit is contained in:
parent
7918f53f12
commit
6e1dfd3003
|
@ -28,7 +28,9 @@ BufferReader.prototype.buffer = function(len) {
|
|||
return buf;
|
||||
};
|
||||
|
||||
BufferReader.prototype.read = function() {
|
||||
BufferReader.prototype.read = function(len) {
|
||||
if (len)
|
||||
return this.buffer(len);
|
||||
var buf = this.buf.slice(this.pos);
|
||||
this.pos = this.buf.length;
|
||||
return buf;
|
||||
|
|
|
@ -58,6 +58,16 @@ describe('BufferReader', function() {
|
|||
br.read().toString('hex').should.equal(buf.toString('hex'));
|
||||
});
|
||||
|
||||
it('should return a buffer of this length', function() {
|
||||
var buf = new Buffer(10);
|
||||
buf.fill(0);
|
||||
var br = new BufferReader(buf);
|
||||
var buf2 = br.read(2);
|
||||
buf2.length.should.equal(2);
|
||||
br.eof().should.equal(false);
|
||||
br.pos.should.equal(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#readUInt8', function() {
|
||||
|
|
Loading…
Reference in New Issue