UNPKG

@loom-io/in-memory-adapter

Version:

A file system wrapper for Node.js and Bun

36 lines (35 loc) 2.06 kB
import { FileHandler } from './file-handler.js'; import { type SourceAdapter, type rmdirOptions, type ObjectDirentInterface } from '@loom-io/core'; import { MEMORY_TYPE, MemoryDirectory, MemoryFile, MemoryObject, MemoryRoot } from '../definitions.js'; export declare class Adapter implements SourceAdapter { protected storage: MemoryRoot; constructor(); protected compareNameAndType<T extends MemoryObject>(item: T, name: string, type?: MEMORY_TYPE): item is T; protected getLastPartOfPath(path: string | undefined, ref: MEMORY_TYPE.FILE): MemoryFile; protected getLastPartOfPath(path: string | undefined, ref: MEMORY_TYPE.DIRECTORY): MemoryDirectory | MemoryRoot; protected getLastPartOfPath(path: string | undefined, ref?: MEMORY_TYPE): MemoryObject | MemoryRoot; protected createMissingDirectories(ref: MemoryDirectory | MemoryRoot, pathParts: string[]): MemoryDirectory | MemoryRoot; protected createDirectory(name: string, content?: MemoryObject[]): MemoryDirectory; protected createFile(name: string, content?: Buffer): MemoryFile; protected createObject(path: string, ref: MEMORY_TYPE.FILE): MemoryFile; protected createObject(path: string, ref: MEMORY_TYPE.DIRECTORY): MemoryDirectory; protected exists(path: string, ref: MEMORY_TYPE): boolean; fileExists(path: string): boolean; dirExists(path: string): boolean; mkdir(path: string): void; readdir(path: string): ObjectDirentInterface[]; rmdir(path: string, options?: rmdirOptions): void; stat(path: string): Promise<{ size: number; mtime: Date; birthtime: Date; }>; readFile(path: string): Buffer; readFile(path: string, encoding: BufferEncoding): string; writeFile(path: string, content: Buffer): void; writeFile(path: string, content: string, encoding?: BufferEncoding): void; deleteFile(path: string): void; openFile(path: string, mode?: 'r' | 'w'): FileHandler; isCopyable<T extends SourceAdapter>(adapter: T): boolean; copyFile(from: string, to: string): void; }