@jsvfs/core
Version:
The JavaScript Virtual File System - an extensible engine for file operations.
48 lines (47 loc) • 2.64 kB
TypeScript
/// <reference types="node" />
import { Item } from './Item';
import type { Adapter, LinkType } from '@jsvfs/types';
/** Create a JavaScript virtual file system in memory. */
export declare class VirtualFileSystem {
/** @param {Adapter} [adapter] - The adapter for this instance; if none is provided, then it defaults to noop. */
constructor(adapter?: Adapter);
/** The file system adapter for this instance. */
private readonly adapter;
/** The root of the file system tree. */
private readonly root;
/** An internal cache of paths removed from root. */
private readonly rmCache;
/** The separator character for this file system. */
get separator(): '/';
/** Determine if a given path is included in the rm cache. */
private isRmCached;
/** Add a given path to the rm cache. */
private addRmCache;
/**
* Read the contents of a file. If the adapter supports pass-through read, the file
* will be read from persistent storage if it is not in the virtual dile system.
*/
read(path: string): Promise<Buffer>;
/** Write the contents of a file; creating directories in the tree as needed. Optionally append to the file. */
write(path: string, contents?: string | String | Buffer, append?: boolean): void;
/** Delete a file; if the target is a hardlink, also deletes the link contents. Returns false if the item does not exist. */
delete(path: string): boolean;
/** Make a directory or directory tree; silently continues if path already exists. */
mkdir(path: string): void;
/** Read the contents of a directory. */
readdir(path: string): string[];
readdir(path: string, long: true): Item[];
readdir(path: string, long: boolean): string[] | Item[];
/** Remove a directory and it's contents. If the path is a folder link, both the link and the link target will be removed. */
rmdir(path: string): boolean;
/** Create a link to a folder or file; optionally create as a hardlink. Returns false if the link cannot be created. */
link(from: string, to: string, type?: LinkType): boolean;
/** Remove a link; returns false if not a link. Does not delete files, this is not a Node API. */
unlink(path: string): boolean;
/** Check to see if a path exists in the virtual file system tree. */
exists(path: string): boolean;
/** Prepare the file system with a snapshot of the underlying persistent file system. */
snapshot(): Promise<void>;
/** Commit the current state of the file system to persistent storage. */
commit(): Promise<void>;
}