}
rQshiftStr(len) {
- if (typeof(len) === 'undefined') { len = this._rQlen - this._rQi; }
let str = "";
// Handle large arrays in steps to avoid long strings on the stack
for (let i = 0; i < len; i += 4096) {
}
rQshiftBytes(len) {
- if (typeof(len) === 'undefined') { len = this._rQlen - this._rQi; }
this._rQi += len;
return new Uint8Array(this._rQ.buffer, this._rQi - len, len);
}
rQshiftTo(target, len) {
- if (len === undefined) { len = this._rQlen - this._rQi; }
// TODO: make this just use set with views when using a ArrayBuffer to store the rQ
target.set(new Uint8Array(this._rQ.buffer, this._rQi, len));
this._rQi += len;
}
rQpeekBytes(len) {
- if (typeof(len) === 'undefined') { len = this._rQlen - this._rQi; }
return new Uint8Array(this._rQ.buffer, this._rQi, len);
}
expect(sock._rQlen - sock._rQi).to.equal(befLen - 3);
});
- it('should shift the entire rest of the queue off if no length is given', function () {
- sock.rQshiftStr();
- expect(sock._rQlen - sock._rQi).to.equal(0);
- });
-
it('should be able to handle very large strings', function () {
const BIG_LEN = 500000;
const RQ_BIG = new Uint8Array(BIG_LEN);
sock._rQ.set(RQ_BIG);
sock._rQlen = RQ_BIG.length;
- const shifted = sock.rQshiftStr();
+ const shifted = sock.rQshiftStr(BIG_LEN);
expect(shifted).to.be.equal(expected);
expect(sock._rQlen - sock._rQi).to.equal(0);
expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3));
expect(sock._rQlen - sock._rQi).to.equal(befLen - 3);
});
-
- it('should shift the entire rest of the queue off if no length is given', function () {
- sock.rQshiftBytes();
- expect(sock._rQlen - sock._rQi).to.equal(0);
- });
});
describe('rQpeekBytes', function () {
expect(sl).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 0, 2));
});
- it('should use the rest of the receive queue if no end is given', function () {
- const sl = sock.rQpeekBytes();
- expect(sl).to.have.length(RQ_TEMPLATE.length);
- expect(sl).to.array.equal(RQ_TEMPLATE);
- });
-
it('should take the current rQi in to account', function () {
sock._rQi = 1;
expect(sock.rQpeekBytes(2)).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, 1, 2));