gbx
Version:
a slim, fast and easy to set up Gamebox (GBX) parser written in TypeScript
150 lines (149 loc) • 4.45 kB
TypeScript
/// <reference types="node" />
/**
* Handle data streams.
*/
export default class DataStream {
private stream;
private position;
constructor(stream: Buffer | Array<number>);
/**
* Creates an array with a callback function applied to each index.
* @param length length of the array.
* @param callback arrow function with index as argument.
* @returns an array with the function applied to each index.
*/
createArray<T>(length: number, callback: (index: number) => T): T[];
/**
* Reads a single byte at the current pointer position without advancing the pointer.
* @returns a number between 0 to 255.
*/
peekByte(offset?: number): number;
/**
* Reads a single byte at the current pointer position.
* @returns a number between 0 to 255.
*/
readByte(): number;
/**
* Reads multiple bytes at the current pointer position without advancing the pointer.
* @param count Amount of bytes to read.
* @returns an array of numbers between 0 to 255.
*/
peekBytes(count: number): number[];
/**
* Reads multiple bytes at the current pointer position.
* @param count Amount of bytes to read.
* @returns an array of numbers between 0 to 255.
*/
readBytes(count: number): number[];
/**
* Reads a byte array as a number.
* @param bytes Array of bytes.
* @returns a number (signed if the array is >= 4 long, unsigned otherwise).
*/
private bytesToNumber;
/**
* Reads multiple bytes at the current pointer position
* without advancing the pointer and returns them as an unsigned number.
* @returns a positive number.
*/
peekNumbers(count: number): number;
/**
* Reads multiple bytes at the current pointer position
* and returns them as an unsigned number.
* @returns a positive number.
*/
readNumbers(count: number): number;
/**
* Reads a 32-bit float, consisting of 4 bytes based on IEEE-754.
* @returns a floating point number.
*/
readFloat(): number;
/**
* Peeks an unsigned 16-bit integer.
* @returns unsigned 16-bit integer.
*/
peekUInt16(): number;
/**
* Reads an unsigned 16-bit integer.
* @returns unsigned 16-bit integer.
*/
readUInt16(): number;
/**
* Peeks an unsigned 32-bit integer.
* @returns unsigned 32-bit integer.
*/
peekUInt32(): number;
/**
* Reads an unsigned 32-bit integer.
* @returns unsigned 32-bit integer.
*/
readUInt32(): number;
/**
* Reads a boolean, consisting of 4 bytes.
* @returns true or false.
*/
readBoolean(): boolean;
/**
* Reads a string of a given length.
* @param count length of the string.
* @returns a string.
*/
readString(count?: number): string;
/**
* Reads a single character
* @returns a 1-long string.
*/
readChar(): string;
/**
* Reads two consecutive 32-bit integers.
* @returns an array of two numbers.
*/
readInt2(): Int2;
/**
* Reads three consecutive 32-bit integers.
* @returns an array of three numbers.
*/
readInt3(): Int3;
/**
* Reads a vector of size 2 as floats.
* @returns an array of two floats.
*/
readVector2(): Vector2;
/**
* Reads a vector of size 3 as floats.
* @returns an array of three floats.
*/
readVector3(): Vector3;
/**
* Reads three consecutive bytes.
* @returns an array of three bytes.
*/
readByte3(): Byte3;
/**
* Reads three consecutive lookback strings.
* @returns object of id, collection and author.
*/
readMeta(): IMeta;
/**
* Reads a file reference.
* @returns a string consisting of a file path.
*/
readFileReference(): string;
private nodeList;
/**
* Reads a node reference.
*/
readNodeReference<NodeType>(): NodeType | undefined;
private lookbackVersion?;
private lookbackStrings;
/**
* Reads a lookback string.
* @returns a string.
*/
readLookbackString(): string;
/**
* Skips to the next chunk within the same class ID. Very unsafe, as it does not take lookback strings into account, because of its naive skip method.
* @todo Add support for skipping nested chunks.
*/
forceChunkSkip(fullChunkId: number): void;
}