UNPKG

silvie

Version:

Typescript Back-end Framework

147 lines (146 loc) 3.87 kB
/// <reference types="node" /> /// <reference types="node" /> import { Stats, ReadStream, WriteStream } from 'fs'; type TEncoding = 'utf8' | 'ascii' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex'; type TReadOptions = TEncoding | { encoding: TEncoding; flag?: string; }; type TWriteOptions = TEncoding | { encoding: TEncoding; flag?: string; }; type TReadStreamOptions = { flags?: string; encoding?: TEncoding; fd?: number; mode?: number; autoClose?: boolean; emitClose?: boolean; start?: number; end?: number; highWaterMark?: number; }; type TWriteStreamOptions = { flags?: string; encoding?: TEncoding; fd?: number; mode?: number; autoClose?: boolean; emitClose?: boolean; start?: number; highWaterMark?: number; }; export default class Disk { private readonly basePath; /** * Resolve a filename in the current disk * @param filename */ private resolve; constructor(basePath: any); /** * Get file stats * @param filename */ stat(filename: string): Promise<Stats>; /** * Reads a file with the given options * @param filename * @param options */ get(filename: string, options?: TReadOptions): Promise<string | Buffer>; /** * Writes a content to a file with the given options * @param filename * @param contents * @param options */ put(filename: string, contents: string | Buffer | Uint8Array, options: TWriteOptions): Promise<boolean>; /** * Checks to see if a file exists * @param filename */ exists(filename: string): Promise<boolean>; /** * Checks to see if a file not exists * @param filename */ missing(filename: string): Promise<boolean>; /** * Check to see if a path is a directory * @param path */ isDirectory(path: string): Promise<boolean>; /** * Rename a file * @param oldPath * @param newPath */ rename(oldPath: string, newPath: string): Promise<boolean>; /** * Move a file * @param oldPath * @param newPath * @param overwrite */ move(oldPath: string, newPath: string, overwrite?: boolean): Promise<boolean>; /** * Copy a file or directory * @param source * @param destination * @param overwrite */ copy(source: string, destination: string, overwrite?: boolean): Promise<boolean>; /** * Copy a file * @param filename * @param destination * @param overwrite */ copyFile(filename: string, destination: string, overwrite?: boolean): Promise<boolean>; /** * Copy a directory * @param source * @param destination * @param overwrite */ copyDirectory(source: string, destination: string, overwrite?: boolean): Promise<boolean>; /** * Delete a file or directory * @param path * @param recursive */ delete(path: string, recursive?: boolean): Promise<boolean>; /** * Delete a file * @param filename */ deleteFile(filename: string): Promise<boolean>; /** * Delete a directory * @param path * @param recursive */ deleteDirectory(path: string, recursive?: boolean): Promise<boolean>; /** * Create a directory * @param path * @param recursive * @param mode */ makeDirectory(path: string, recursive?: boolean, mode?: number): Promise<boolean>; /** * Create a read stream from a path * @param path * @param options */ readStreamFrom(path: string, options?: TReadStreamOptions): ReadStream; /** * Create a write stream to a path * @param path * @param options */ writeStreamTo(path: string, options?: TWriteStreamOptions): WriteStream; } export {};