Browse Source

more convenient bufferreader

patch-2
Ryan X. Charles 11 years ago
parent
commit
572582938f
  1. 11
      lib/bufferreader.js
  2. 9
      test/bufferreader.js

11
lib/bufferreader.js

@ -1,10 +1,15 @@
var BN = require('./bn');
var BufferReader = function BufferReader(obj) {
var BufferReader = function BufferReader(buf) {
if (!(this instanceof BufferReader))
return new BufferReader(obj);
if (obj)
return new BufferReader(buf);
if (Buffer.isBuffer(buf)) {
this.set({buf: buf});
}
else if (buf) {
var obj = buf;
this.set(obj);
}
};
BufferReader.prototype.set = function(obj) {

9
test/bufferreader.js

@ -7,6 +7,15 @@ describe('BufferReader', function() {
it('should make a new BufferReader', function() {
var br = new BufferReader();
should.exist(br);
br = BufferReader();
should.exist(br);
});
it('should create a new bufferreader with a buffer', function() {
var buf = new Buffer(0);
var br = new BufferReader(buf);
should.exist(br);
Buffer.isBuffer(br.buf).should.equal(true);
});
describe('#set', function() {

Loading…
Cancel
Save