rw-parser
Version:
Parses RenderWare DFF and TXD files into usable format!
61 lines (60 loc) • 1.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ByteStream = void 0;
var ByteStream = /** @class */ (function () {
function ByteStream(stream) {
this._cursor = 0;
this._stream = stream;
}
ByteStream.prototype.readUint8 = function () {
var uint8 = this._stream.readUInt8(this._cursor);
this._cursor++;
return uint8;
};
ByteStream.prototype.readUint16 = function () {
var uint16 = this._stream.readUInt16LE(this._cursor);
this._cursor += 2;
return uint16;
};
ByteStream.prototype.readUint32 = function () {
var uint32 = this._stream.readUInt32LE(this._cursor);
this._cursor += 4;
return uint32;
};
ByteStream.prototype.readInt32 = function () {
var int32 = this._stream.readInt32LE(this._cursor);
this._cursor += 4;
return int32;
};
ByteStream.prototype.readFloat = function () {
var float = this._stream.readFloatLE(this._cursor);
this._cursor += 4;
return float;
};
ByteStream.prototype.readString = function (size) {
var string = this._stream.toString('ascii', this._cursor, this._cursor + size);
this._cursor += size;
return string.split(/\0/g).shift() || '';
};
ByteStream.prototype.read = function (size) {
var data = new Uint8Array(size);
for (var i = 0; i < size; i++) {
data[i] = this.readUint8();
}
return data;
};
ByteStream.prototype.getSize = function () {
return this._stream.byteLength;
};
ByteStream.prototype.getPosition = function () {
return this._cursor;
};
ByteStream.prototype.setPosition = function (position) {
this._cursor = position;
};
ByteStream.prototype.skip = function (size) {
this._cursor += size;
};
return ByteStream;
}());
exports.ByteStream = ByteStream;