elflib
Version:
ELF file reader and writer
39 lines (38 loc) • 1.8 kB
TypeScript
/// <reference types="node" />
import { FileHandle } from 'fs/promises';
/** An abstract interface for a file-reading interface.
* This is used by the ELF parser to read the file from many different sources. */
export interface Reader {
/** The path of the file, if it is a file. */
path?: string;
/** Called to open the data source asynchronously. */
open(): Promise<void>;
/** Called to read data from the data source.
* @param length The amount of data to read.
* @param position If specified, seek to this position first. */
read(length: number, position?: number): Promise<Uint8Array>;
/** Called to return a data view interface to the data source.
* @param length The size of the data view.
* @param position The position of the data view. */
view(length: number, position?: number): Promise<DataView>;
/** Returns the size of the data source */
size(): number;
/** Closes the data source */
close(): Promise<void>;
}
export declare function buffer<TBuffer extends Uint8Array>(buffer: TBuffer | ArrayBuffer): Reader;
export declare function array(array: number[]): Reader;
export declare function fileHandle(fh: FileHandle): Promise<Reader>;
export declare function fileDescriptor(handle: number): Reader;
export declare function filePath(path: string): Reader;
export interface HelperDataView extends DataView {
readUInt8: (ix: number) => number;
readUInt16: (ix: number) => number;
readUInt32: (ix: number) => number;
readUInt64: (ix: number) => bigint;
readSInt8: (ix: number) => number;
readSInt16: (ix: number) => number;
readSInt32: (ix: number) => number;
readSInt64: (ix: number) => bigint;
}
export declare function HelperDataView(view: DataView, bigEndian: boolean): HelperDataView;