UNPKG

unreal.js

Version:

A pak reader for games like VALORANT & Fortnite written in Node.JS

94 lines (93 loc) 2.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FFileArchive = void 0; const FArchive_1 = require("./FArchive"); const fs_1 = __importDefault(require("fs")); const VersionContainer_1 = require("../versions/VersionContainer"); /** * File Reader */ class FFileArchive extends FArchive_1.FArchive { /** * Creates an instance * @param {?string} path Path to the file * @param {?VersionContainer} versions Versions * @constructor * @public */ constructor(path, versions = VersionContainer_1.VersionContainer.DEFAULT) { super(versions); /** * Position of the reader * @type {number} * @protected */ this.position = 0; /** * Whether to use little endian * @type {boolean} * @public */ this.littleEndian = true; if (path) { this.path = path; this.handle = fs_1.default.openSync(path, "rs"); this.stats = fs_1.default.fstatSync(this.handle); } } /** * Size of the reader * @type {number} * @public */ get size() { return this.stats.size; } /** * Current position * @type {number} * @public */ get pos() { return this.position; } set pos(pos) { this.position = pos; } /** * Reads to a buffer * @param {Buffer} b Destination * @param {number} off Offset in buffer * @param {number} len Length to read * @returns {void} * @public */ readToBuffer(b, off = 0, len = b.length) { fs_1.default.readSync(this.handle, b, off, len, this.position); this.position += len; } /** * Clones this * @returns {FFileArchive} Clone * @public */ clone() { const clone = new FFileArchive(); clone.path = this.path; clone.handle = this.handle; clone.stats = this.stats; return clone; } /** * Returns FArchive info for error * @returns {string} * @public */ printError() { return `FFileArchive Info: pos ${this.pos}, stopper ${this.size}, file ${this.path}`; } } exports.FFileArchive = FFileArchive;