igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
65 lines (64 loc) • 2.08 kB
TypeScript
import { OpenMode, PathLike } from 'node:fs';
/**
* A wrapper for readable and writable files
*/
export default class IOFile {
private readonly pathLike;
private readonly fd;
private readonly size;
private tempBuffer;
private readPosition;
private fileBuffer?;
private constructor();
/**
* Return a new {@link IOFile} from a {@param pathLike}, with the {@param flags} mode.
*/
static fileFrom(pathLike: PathLike, flags: OpenMode): Promise<IOFile>;
/**
* Return a new {@link IOFile} of size {@param size} from a {@param pathLike}, with the
* {@param flags} mode. If the {@param pathLike} already exists, the existing file will be
* deleted.
*/
static fileOfSize(pathLike: string, flags: OpenMode, size: number): Promise<IOFile>;
getPathLike(): PathLike;
/**
* @returns if the seek position of the file has reached the end
*/
isEOF(): boolean;
getPosition(): number;
getSize(): number;
/**
* Seek to a specific {@param position} in the file
*/
seek(position: number): void;
/**
* Seek to the current position plus {@param size}
*/
skipNext(size: number): void;
/**
* @returns the next {@param size} bytes from the current seek position, without changing the
* seek position
*/
peekNext(size: number): Promise<Buffer>;
/**
* @returns the next {@param size} bytes from the current seek position, also incrementing the
* seek position the same amount
*/
readNext(size: number): Promise<Buffer>;
/**
* @returns bytes of size {@param size} at the seek position {@param offset}
*/
readAt(offset: number, size: number): Promise<Buffer>;
/**
* Write {@param buffer} to the current seek position
*/
write(buffer: Buffer): Promise<number>;
/**
* Write {@param buffer} at the seek position {@param offset}
*/
writeAt(buffer: Buffer, offset: number): Promise<number>;
/**
* Close the underlying file handle
*/
close(): Promise<void>;
}