Binato/server/ActionBuffer.js

19 lines
502 B
JavaScript
Raw Normal View History

module.exports = class {
constructor(initialData = Buffer) {
this.actionBuffer;
if (initialData.length == 0) {
this.actionBuffer = Buffer.alloc(0);
} else {
this.actionBuffer = initialData;
}
}
bufferAction(data = Buffer) {
if (data.length != 0)
this.actionBuffer = Buffer.concat([this.actionBuffer, data], this.actionBuffer.length + data.length);
}
toBuffer() {
return this.actionBuffer;
}
}