@zenfs/core
Version:
A filesystem, anywhere
118 lines (117 loc) • 3.76 kB
TypeScript
import type { File } from './file.js';
import { type Stats } from './stats.js';
export type FileContents = ArrayBufferView | string;
/**
* Metadata about a FileSystem
*/
export interface FileSystemMetadata {
/**
* The name of the FS
*/
name: string;
/**
* Whether the FS is readonly or not
*/
readonly: boolean;
/**
* The total space
*/
totalSpace: number;
/**
* The available space
*/
freeSpace: number;
/**
* If set, disables File from using a resizable array buffer.
* @default false
*/
noResizableBuffers: boolean;
/**
* If set, disables caching on async file systems.
* This means *sync operations will not work*.
* It has no affect on sync file systems.
* @default false
*/
noAsyncCache: boolean;
/**
* The optimal block size to use with the file system
* @default 4096
*/
blockSize?: number;
/**
* Total number of (file) nodes available
*/
totalNodes?: number;
/**
* Number of free (file) nodes available
*/
freeNodes?: number;
/**
* The type of the FS
*/
type: number;
}
/**
* Provides a consistent and easy to use internal API.
* Default implementations for `exists` and `existsSync` are included.
* If you are extending this class, note that every path is an absolute path and all arguments are present.
* @internal
*/
export declare abstract class FileSystem {
/**
* Get metadata about the current file system
*/
metadata(): FileSystemMetadata;
/**
* Whether the sync cache should be disabled.
* Only affects async things.
* @internal @protected
*/
_disableSync?: boolean;
constructor(...args: any[]);
ready(): Promise<void>;
abstract rename(oldPath: string, newPath: string): Promise<void>;
abstract renameSync(oldPath: string, newPath: string): void;
abstract stat(path: string): Promise<Stats>;
abstract statSync(path: string): Stats;
/**
* Opens the file at `path` with `flag`. The file must exist.
* @param path The path to open.
* @param flag The flag to use when opening the file.
*/
abstract openFile(path: string, flag: string): Promise<File>;
/**
* Opens the file at `path` with `flag`. The file must exist.
* @param path The path to open.
* @param flag The flag to use when opening the file.
*/
abstract openFileSync(path: string, flag: string): File;
/**
* Create the file at `path` with `mode`. Then, open it with `flag`.
*/
abstract createFile(path: string, flag: string, mode: number): Promise<File>;
/**
* Create the file at `path` with `mode`. Then, open it with `flag`.
*/
abstract createFileSync(path: string, flag: string, mode: number): File;
abstract unlink(path: string): Promise<void>;
abstract unlinkSync(path: string): void;
abstract rmdir(path: string): Promise<void>;
abstract rmdirSync(path: string): void;
abstract mkdir(path: string, mode: number): Promise<void>;
abstract mkdirSync(path: string, mode: number): void;
abstract readdir(path: string): Promise<string[]>;
abstract readdirSync(path: string): string[];
/**
* Test whether or not `path` exists.
*/
exists(path: string): Promise<boolean>;
/**
* Test whether or not `path` exists.
*/
existsSync(path: string): boolean;
abstract link(target: string, link: string): Promise<void>;
abstract linkSync(target: string, link: string): void;
abstract sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
abstract syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}