UNPKG

1.27 kBPlain TextView Raw
1import {Predicate} from '../predicate';
2
3import {FileType} from './type';
4
5export interface FilesystemBase {
6 // The name of this item (just the name)
7 name(): string;
8
9 // The parent directory containing this element
10 parent(): PathReference;
11
12 // The type of path this is (symbolic link, etc.)
13 type(): FileType;
14
15 // Does this path exist?
16 exists(): boolean;
17
18 equals(other: FilesystemBase): boolean;
19}
20
21export interface FileReference extends FilesystemBase {
22 // Create or overwrite the file with this content
23 create(content: string): void;
24
25 // Read the content of this file as a UTF8 string
26 content(): string;
27
28 // Delete this file or fail silently in case of failure
29 unlink(): void;
30}
31
32export interface PathReference extends FilesystemBase {
33 // Get the immediate descendant child directories
34 directories(predicate?: RegExp | Predicate<PathReference>): Set<PathReference>;
35
36 // Immediate descendant child files
37 files(predicate?: RegExp | Predicate<FileReference>): Set<FileReference>;
38
39 // Traverse upward looking for a particular file (throws if not found)
40 findInAncestor(file: string): FilesystemBase;
41
42 // Recursive create of each component of the path (if nonexistent)
43 mkdir(): void;
44
45 // Remove or fail silently
46 unlink(): void;
47}