@firesystem/memory
Version:
In-memory implementation of Virtual File System
59 lines (55 loc) • 1.8 kB
TypeScript
import {
FileEntry,
BaseFileSystem,
TypedEventEmitter,
FileSystemEventPayloads,
IFileSystemCapabilities,
FileMetadata,
FSEvent,
Disposable,
FileStat,
} from "@firesystem/core";
interface MemoryFileSystemOptions {
initialFiles?: FileEntry[];
}
declare class MemoryFileSystem extends BaseFileSystem {
private files;
private watchers;
readonly events: TypedEventEmitter<FileSystemEventPayloads>;
readonly capabilities: IFileSystemCapabilities;
constructor(options?: MemoryFileSystemOptions);
initialize(): Promise<void>;
readFile(path: string): Promise<FileEntry>;
writeFile(
path: string,
content: any,
metadata?: FileMetadata,
): Promise<FileEntry>;
deleteFile(path: string): Promise<void>;
exists(path: string): Promise<boolean>;
readDir(path: string): Promise<FileEntry[]>;
mkdir(path: string, recursive?: boolean): Promise<FileEntry>;
rmdir(path: string, recursive?: boolean): Promise<void>;
rename(oldPath: string, newPath: string): Promise<FileEntry>;
move(sourcePaths: string[], targetPath: string): Promise<void>;
copy(sourcePath: string, targetPath: string): Promise<FileEntry>;
watch(pattern: string, callback: (event: FSEvent) => void): Disposable;
stat(path: string): Promise<FileStat>;
glob(pattern: string): Promise<string[]>;
clear(): Promise<void>;
size(): Promise<number>;
private calculateSize;
private ensureParentExists;
private deleteRecursive;
private matchesPattern;
private notifyWatchers;
private generateWatcherId;
canModify(path: string): Promise<boolean>;
canCreateIn(parentPath: string): Promise<boolean>;
writeFileAtomic(
path: string,
content: any,
metadata?: FileMetadata,
): Promise<FileEntry>;
}
export { MemoryFileSystem, type MemoryFileSystemOptions };