unpak.js
Version:
Modern TypeScript library for reading Unreal Engine pak files and assets, inspired by CUE4Parse
90 lines • 2.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.FByteArchive = void 0;
const FArchive_1 = require("./FArchive");
const VersionContainer_1 = require("../versions/VersionContainer");
/**
* Byte Reader for UE4
* @extends {FArchive}
*/
class FByteArchive extends FArchive_1.FArchive {
/**
* Position of the reader
* @type {number}
* @protected
*/
position = 0;
/**
* Whether to use little endian
* @type {boolean}
* @public
*/
littleEndian = true;
/**
* Stores the buffer data
* @type {Buffer}
* @public
*/
data;
/**
* Creates an instance
* @param {Buffer} data Bytes to read
* @param {VersionContainer?} versions Container of versions
* @constructor
* @public
*/
constructor(data, versions = VersionContainer_1.VersionContainer.DEFAULT) {
super(versions);
this.data = data;
}
/**
* Current position
* @type {number}
* @public
*/
get pos() {
return this.position;
}
set pos(pos) {
this.position = pos;
}
/**
* Clones this instance
* @returns {FByteArchive}
* @public
*/
clone() {
const clone = new FByteArchive(this.data);
clone.pos = this.position;
return clone;
}
/**
* Size of data
* @type {number}
* @public
*/
get size() {
return this.data.length;
}
/**
* Reads to a buffer
* @param {Buffer} b Destination
* @param {number} off Offset
* @param {number} len Length
* @returns {void}
* @public
*/
readToBuffer(b, off = 0, len = b.length) {
this.data.copy(b, off, this.position, this.position += len);
}
/**
* Returns FByteArchive info for error
* @returns {string}
* @public
*/
printError() {
return `FByteArchive Info: pos ${this.position}, stopper ${this.size}`;
}
}
exports.FByteArchive = FByteArchive;
//# sourceMappingURL=FByteArchive.js.map
;