35 lines
720 B
JavaScript
35 lines
720 B
JavaScript
const { readFileSync } = require("node:fs");
|
|
|
|
module.exports = class Reader {
|
|
constructor(path) {
|
|
this.buf = readFileSync(path);
|
|
this.offset = 0;
|
|
}
|
|
|
|
read_i32() {
|
|
let value = this.buf.readInt32LE(this.offset);
|
|
this.offset += 4;
|
|
return value;
|
|
}
|
|
|
|
read_u8() {
|
|
let value = this.buf.readUint8(this.offset);
|
|
this.offset++;
|
|
return value;
|
|
}
|
|
|
|
read_char() {
|
|
return String.fromCharCode(this.read_u8());
|
|
}
|
|
|
|
read_string() {
|
|
let out = "";
|
|
while (this.offset < this.buf.length) {
|
|
let c = this.read_char();
|
|
if (c == '\n') break;
|
|
out += c;
|
|
}
|
|
|
|
return out;
|
|
}
|
|
} |