BufferWriter.prototype.set
This commit is contained in:
parent
3475ee973c
commit
0d9b54711e
|
@ -1,9 +1,17 @@
|
||||||
var BN = require('./bn');
|
var BN = require('./bn');
|
||||||
|
|
||||||
var BufferWriter = function BufferWriter(bufs) {
|
var BufferWriter = function BufferWriter(obj) {
|
||||||
if (!(this instanceof BufferWriter))
|
if (!(this instanceof BufferWriter))
|
||||||
return new BufferReader(buf);
|
return new BufferReader(obj);
|
||||||
this.bufs = bufs || [];
|
if (obj)
|
||||||
|
this.set(obj);
|
||||||
|
else
|
||||||
|
this.bufs = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
BufferWriter.prototype.set = function(obj) {
|
||||||
|
this.bufs = obj.bufs || this.bufs || [];
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
BufferWriter.prototype.concat = function() {
|
BufferWriter.prototype.concat = function() {
|
||||||
|
|
|
@ -10,12 +10,24 @@ describe('BufferWriter', function() {
|
||||||
should.exist(bw);
|
should.exist(bw);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#set', function() {
|
||||||
|
|
||||||
|
it('set bufs', function() {
|
||||||
|
var buf1 = new Buffer([0]);
|
||||||
|
var buf2 = new Buffer([1]);
|
||||||
|
var bufs = [buf1, buf2];
|
||||||
|
var bw = new BufferWriter().set({bufs: [buf1, buf2]});
|
||||||
|
bw.concat().toString('hex').should.equal('0001');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#concat', function() {
|
describe('#concat', function() {
|
||||||
|
|
||||||
it('should concat these two bufs', function() {
|
it('should concat these two bufs', function() {
|
||||||
var buf1 = new Buffer([0]);
|
var buf1 = new Buffer([0]);
|
||||||
var buf2 = new Buffer([1]);
|
var buf2 = new Buffer([1]);
|
||||||
var bw = new BufferWriter([buf1, buf2]);
|
var bw = new BufferWriter({bufs: [buf1, buf2]});
|
||||||
bw.concat().toString('hex').should.equal('0001');
|
bw.concat().toString('hex').should.equal('0001');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue