@mlightcad/shx-parser
Version:
A TypeScript library for parsing AutoCAD SHX font files
111 lines (110 loc) • 3.62 kB
TypeScript
/**
* A utility class for reading binary data from an ArrayBuffer.
* Provides methods to read various data types and manage the read position.
*/
export declare class ShxFileReader {
/** Current position in the buffer */
private position;
/** DataView instance for reading binary data */
private data;
/**
* Converts an unsigned byte to a signed byte as used in SHX format.
* Values > 127 are converted to their signed equivalent (-128 to -1).
* @param value - The unsigned byte value to convert
* @returns The signed byte value
*/
static byteToSByte(value: number): number;
/**
* Creates a new ShxFileReader instance.
* @param arraybuffer - The ArrayBuffer to read from
*/
constructor(arraybuffer: ArrayBuffer);
/**
* Reads a specified number of bytes from the current position.
* @param length - Number of bytes to read (optional)
* @returns A Uint8Array containing the read bytes
* @throws Error if reading beyond buffer bounds
*/
readBytes(length?: number): Uint8Array;
/**
* Skips a specified number of bytes from the current position.
* @param length - Number of bytes to skip
* @throws Error if skipping beyond buffer bounds
*/
skip(length: number): void;
/**
* Reads an unsigned 8-bit integer.
* @returns The read uint8 value
* @throws Error if reading beyond buffer bounds
*/
readUint8(): number;
/**
* Reads a signed 8-bit integer.
* @returns The read int8 value
* @throws Error if reading beyond buffer bounds
*/
readInt8(): number;
/**
* Reads an unsigned 16-bit integer.
* @param littleEndian If false, a big-endian value should be read.
* @returns The read uint16 value
* @throws Error if reading beyond buffer bounds
*/
readUint16(littleEndian?: boolean): number;
/**
* Reads a signed 16-bit integer.
* @returns The read int16 value
* @throws Error if reading beyond buffer bounds
*/
readInt16(): number;
/**
* Reads an unsigned 32-bit integer.
* @returns The read uint32 value
* @throws Error if reading beyond buffer bounds
*/
readUint32(): number;
/**
* Reads a signed 32-bit integer.
* @returns The read int32 value
* @throws Error if reading beyond buffer bounds
*/
readInt32(): number;
/**
* Reads a 32-bit floating point number.
* @returns The read float32 value
* @throws Error if reading beyond buffer bounds
*/
readFloat32(): number;
/**
* Reads a 64-bit floating point number.
* @returns The read float64 value
* @throws Error if reading beyond buffer bounds
*/
readFloat64(): number;
/**
* Sets the current read position in the buffer.
* @param position - The new position to set
*/
setPosition(position: number): void;
/**
* Checks if the current position is at the end of the buffer.
* @returns True if at the end of the buffer, false otherwise
*/
isEnd(): boolean;
/**
* Gets the current position in the buffer.
* @returns The current position
*/
get currentPosition(): number;
/**
* Gets the total length of the buffer.
* @returns The buffer length in bytes
*/
get length(): number;
/**
* Throws an error when attempting to read beyond buffer bounds.
* @param position - The position that caused the error
* @throws Error with details about the out of range access
*/
private throwOutOfRangeError;
}