UNPKG

@amadeus-it-group/kassette

Version:

Development server, used mainly for testing, which proxies requests and is able to easily manage local mocks.

45 lines (44 loc) 1.68 kB
/** tells if file system node at given `path` exists */ export declare function exists(path: string): Promise<boolean>; /** creates the hierarchy of folders given by `path` */ export declare function ensurePath(path: string): Promise<void>; /** writes `content` into the file at given `path` */ export declare function writeFile(path: string, content: string | Buffer): Promise<void>; export interface FileHandlerSpec { /** the path of the folder containing the file */ readonly root: string; /** the file name */ readonly name: string; } export interface IFileHandler { /** the full path of the file */ readonly path: string; /** the file name */ readonly name: string; /** tells whether the file exists or not */ exists(): Promise<boolean>; /** reads and returns the content of the file or returns `null` if it doesn't exist */ read(): Promise<Buffer | null>; /** writes the given content into the file */ write(content: Buffer | string | null | undefined): Promise<void>; /** gets the size and the last modified time of the file, or returns `null` if it doesn't exist */ stat(): Promise<{ mtime: number; size: number; } | null>; } export declare class FileHandler implements IFileHandler { private readonly _spec; constructor(spec: FileHandlerSpec | string); /** the root of the file */ private get _root(); get name(): string; get path(): string; exists(): Promise<boolean>; read(): Promise<Buffer | null>; write(content: Buffer | string | null | undefined): Promise<void>; stat(): Promise<{ mtime: number; size: number; } | null>; }