UNPKG

ooafs

Version:

Type-safe Object-Oriented Async FileSystem

72 lines (71 loc) 2.55 kB
/// <reference types="node" /> import * as Path from 'path'; import EntryFilter from './EntryFilter'; import EntryType from './EntryType'; import Fs from 'fs-extra'; import { CreateReadStreamOptions, Directory, EntryBase, File } from './FSTypings'; /** * This class represents a generic filesystem entry. If you use TypeScript, you * can use the `File` and `Directory` interfaces which hide some methods for a * better type-safety */ export default class Entry implements File, Directory { readonly path: string; constructor(path: string); get e(): Entry; get d(): Directory; get f(): File; get absolutePath(): string; get parsedPath(): Path.ParsedPath; get name(): string; get extension(): string; child(relativePath: string): Entry; copy(dest: string | EntryBase): Promise<this>; createDirectory(): Promise<Directory>; createDirectory(subpath: string): Promise<Directory>; createFile(): Promise<File>; createFile(subpath: string): Promise<File>; createReadStream(options?: CreateReadStreamOptions): Fs.ReadStream; equals(other: EntryBase): boolean; exists(): Promise<boolean>; type(): Promise<EntryType>; isDirectory(): Promise<boolean>; isFile(): Promise<boolean>; list(filter: EntryFilter & { type: EntryType.DIRECTORY; }): Promise<Directory[]>; list(filter: EntryFilter & { type: EntryType.FILE; }): Promise<File[]>; list(filter?: EntryFilter): Promise<Entry[]>; listRecursively(filter: EntryFilter & { type: EntryType.DIRECTORY; }): Promise<Directory[]>; listRecursively(filter: EntryFilter & { type: EntryType.FILE; }): Promise<File[]>; listRecursively(filter?: EntryFilter): Promise<Entry[]>; move(dest: string | EntryBase): Promise<this>; parent(): Directory; read(options: { encoding: string; flags?: string; }): Promise<string>; read(options: { encoding?: never; flags?: string; }): Promise<Buffer>; read(encoding: string): Promise<string>; read(): Promise<Buffer>; remove(): Promise<void>; size(): Promise<number>; stat(): Promise<Fs.Stats>; write(data: any, options?: string | Fs.WriteFileOptions): Promise<void>; /** * Returns an `Entry` * @param path If the path is already an entry, it is returned as is. If it * is specified as a string, a new `Entry` is returned */ static from(path: string): Entry; static from<T extends EntryBase>(path: string | T): T; }