@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
51 lines • 2.48 kB
TypeScript
/**
* A read-only handle that fetches its file a chunk at a time.
*
* The read-side twin of `FileHandle`, for a read-only open of a file larger
* than one chunk; a smaller file is read whole, since whole is what the file
* cache keeps. Nothing moves at open: a read fetches the chunk it lands in
* through the file adapter's ranged read, and that chunk is kept so a sequential
* read of small pieces costs one request per chunk. The file ends where a
* fetch comes back short, not at the size the open saw: a rendering need
* not be as long as the stored bytes a stat measured, so that size answers
* only until the end has been seen. Mirrors Python's `ChunkedHandle`.
*/
export declare class ChunkedHandle {
readonly path: string;
size: number;
pos: number;
private readonly fetch;
private start;
private kept;
private end;
private generation;
constructor(path: string, size: number, fetch: (offset: number, size: number) => Promise<Uint8Array>);
/** Read at an explicit offset without moving the position. */
pread(offset: number, size: number): Promise<Uint8Array>;
/** Whether the kept bytes or known EOF answer without fetching. */
holds(offset: number, size: number): boolean;
/** Whether reading `size` bytes at the position (a negative size: the rest) needs a fetch first. */
lacks(size: number): boolean;
/** Fetch what a read of `size` bytes at the position lacks; any other size, one more chunk. */
fill(size: number): Promise<void>;
/** The kept bytes from `offset`, at most `size` of them; empty when none are kept there. */
peek(offset: number, size: number): Uint8Array;
/** True once the position sits at or past where the file is known to end. */
get eof(): boolean;
/** Forget the kept bytes: the next read fetches the file anew. */
drop(): void;
private atEnd;
private keptToEnd;
private covers;
private slice;
/**
* Fetch so a read at `offset` of `size` is answerable, and answer the
* bytes from `offset` on. A fetch that continues the kept bytes is joined
* onto what they hold from `offset` on, so a line can run across two
* chunks. Reads may overlap (FUSE issues them concurrently), so the state
* is read before the fetch and each read answers from its own bytes; a
* `drop` while the fetch was out keeps them from being installed.
*/
private load;
}
//# sourceMappingURL=chunked.d.ts.map