Volatile file provider with recursive copy/delete, name validation and cycle protection; data does not survive a restart.
All file operations are asynchronous. Directory and file IDs are strings; null as parent/target denotes the root. Invalid names, name collisions, unknown IDs, duplicate IDs and cycles fail. Copy preserves contents, assigns new IDs and includes descendants. Remove deletes recursively. Without stored contents, download is empty; directory downloads are unavailable.
new TxMemoryFileProvider(entries?: TxFileEntry[]): TxMemoryFileProvider| Member | Type / return | Behavior |
|---|---|---|
| list | (parentId: string | null, signal?: AbortSignal) => Promise<{ id: string; parentId: string | null; name: string; isDirectory: boolean; size?: number; modified?: Date; content?: Blob; }[]> | Returns entries in the parent directory; null reads the root. |
| createDirectory | (parentId: string | null, name: string) => Promise<{ id: string; parentId: string | null; name: string; isDirectory: boolean; size?: number; modified?: Date; content?: Blob; }> | Creates a directory with a valid name unique within its parent. |
| rename | (id: string, name: string) => Promise<void> | Renames a file or directory; preserves its ID and parent. |
| move | (id: string, target: string | null) => Promise<void> | Moves an entry to the target directory; cycles are rejected. |
| copy | (id: string, target: string | null) => Promise<void> | Recursively copies an entry to the target directory, assigning new IDs. |
| remove | (id: string) => Promise<void> | Removes the record or recursively removes a file/directory tree. |
| upload | (parentId: string | null, file: File, signal?: AbortSignal) => Promise<{ id: string; parentId: string | null; name: string; size: number; isDirectory: boolean; content: Blob; modified: Date; }> | Uploads a file to the specified directory and returns its new entry. |
| download | (id: string) => Promise<Blob> | Returns file contents; downloading a directory fails. |
import { TxMemoryFileProvider } from '@tekocloud.de/tecexpress'
const provider = new TxMemoryFileProvider()
const folder = await provider.createDirectory(null, 'Documents')
const file = await provider.upload(folder.id, new File(['Hello'], 'hello.txt'))
await provider.rename(file.id, 'renamed.txt')
await provider.copy(file.id, null)
await provider.move(file.id, null).catch(error => console.log(error.message)) // name collision
console.log(await provider.list(folder.id), await provider.download(file.id))
await provider.remove(folder.id) // recursive