decktape/libs/buffer.js
2017-08-25 15:18:07 +02:00

45 lines
806 B
JavaScript

class BufferReader {
constructor(buffer) {
this.rposition = 0;
this.buffer = buffer;
}
read(inAmount) {
const arr = [];
const amount = this.rposition + inAmount;
if (amount > this.buffer.length) {
amount = this.buffer.length - this.rposition;
}
for (let i = this.rposition; i < amount; ++i)
arr.push(this.buffer[i]);
this.rposition = amount;
return arr;
}
notEnded() {
return this.rposition < this.buffer.length;
}
setPosition(inPosition) {
this.rposition = inPosition;
}
setPositionFromEnd(inPosition) {
this.rposition = this.buffer.length - inPosition;
}
skip(inAmount) {
this.rposition += inAmount;
}
getCurrentPosition() {
return this.rposition;
}
close() {
}
}
module.exports = BufferReader;