UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

49 lines • 2.02 kB
/** * What an fopen-style mode string says about a handle. * * One vocabulary for every dialect that opens by mode: monty's open * passes a CPython mode string, and quickjs's `std.open` and Python's * preview1 oflags/rights/fdflags translate onto the same facts. */ export interface OpenMode { /** The handle may read (r, +). */ readable: boolean; /** The handle may mutate its buffer (w, a, x, +). */ writable: boolean; /** Opening discards existing content (w). */ truncate: boolean; /** Every write lands at the end (a). */ append: boolean; /** A missing file is created (w, a, x). */ create: boolean; /** An existing file refuses the open (x). */ exclusive: boolean; /** The handle carries bytes, not text (b). */ binary: boolean; /** A directory may open, for a read: `os.open` and preview1 open one, `open` and SFTP refuse it. */ directory?: boolean; } /** A handle that only reads, as an open with no flags asks for. */ export declare const READ: OpenMode; /** * What open(2) flags say about a handle, in the mode vocabulary. The flag * numbers are the host's (`fs.constants` under node, Emscripten's own), so * they come with the flags. Mirrors Python's `open_mode`. */ export declare function openMode(flags: number, bits: Readonly<Record<'O_WRONLY' | 'O_RDWR' | 'O_CREAT' | 'O_EXCL' | 'O_TRUNC' | 'O_APPEND', number>>): OpenMode; /** * Read an fopen-style mode string into its facts, validating it. * * The rule is CPython's: one base, at most one each of `+`, `b`, `t`, * and never `b` together with `t`. A guest that opens in C's dialect * (QuickJS's std.open: fopen reads `rr` as `r` and spells exclusive * creation `wx`) reads its own mode and builds these facts itself. * * Args: * mode: the mode as the caller spelled it (`r`, `w+b`, `a`, `x`, ...). * * Throws: * Error: the mode does not parse, in CPython's own wording. */ export declare function parseMode(mode: string): OpenMode; //# sourceMappingURL=mode.d.ts.map