mirror of
https://github.com/astefanutti/decktape.git
synced 2024-12-12 13:49:13 +03:00
45 lines
806 B
JavaScript
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;
|