ooafs
Version:
Type-safe Object-Oriented Async FileSystem
63 lines (62 loc) • 2.24 kB
TypeScript
/// <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);
readonly absolutePath: string;
readonly parsedPath: Path.ParsedPath;
readonly name: string;
readonly extension: string;
asEntry(): this;
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>;
}