UNPKG

@jsvfs/core

Version:

The JavaScript Virtual File System - an extensible engine for file operations.

73 lines (72 loc) 2.46 kB
/// <reference types="node" /> import type { Adapter, FolderType, ItemType, LinkType } from '@jsvfs/types'; export declare type RealItem = File | Folder | Root; export declare type Item = RealItem | Link; declare abstract class ItemBase { constructor(item: Partial<ItemBase>); /** The file system adapter instance to use. */ adapter: Adapter; /** The type of item. */ type: ItemType; /** The absolute path to the item. */ path: string; /** The name of the item. */ name: string; /** Contents of the item. */ contents?: any; /** The parent of the item. */ parent?: ParentItem; /** The status of the commit. */ committed: boolean; /** The size of the item. */ abstract get size(): number; /** Method to commit the item to persistent storage. */ abstract commit(): Promise<void>; } export declare class ParentItem extends ItemBase { constructor(item: Partial<ParentItem>); /** The type of item, root or a folder. */ type: FolderType; /** The children of the folder. */ contents: Map<string, Item>; list(): string[]; list(long: true): Item[]; list(long: boolean): string[] | Item[]; get(name: string): Item; set(name: string, item: Item): void; delete(name: string): boolean; get size(): number; get count(): number; commit(): Promise<void>; } /** Represents a folder item in the file system. */ export declare class Folder extends ParentItem { constructor(item: Partial<Folder>); /** The type of item, a folder. */ type: 'folder'; } /** A special item; represents the top-level of the file system. */ export declare class Root extends ParentItem { constructor(adapter: Adapter); /** The type of item, a root folder. */ type: 'root'; } /** Represents a file item in the file system. */ export declare class File extends ItemBase { constructor(item: Partial<File>); /** The type of item, a file. */ type: 'file'; contents: Buffer; get size(): number; commit(): Promise<void>; } /** Represents a link item in the file system; defaults to type 'softlink'. */ export declare class Link extends ItemBase { constructor(item: Partial<Link>); /** The type of item, either a hardlink or softlink. */ type: LinkType; contents: RealItem; get size(): number; commit(): Promise<void>; } export {};