# Filesystem API URL: /docs/api/filesystem Filesystem API [#filesystem-api] Use the filesystem API when configuring how kernels read and write project files. The package provides constructors for Node.js, in-memory, and any fs-compatible backends, plus bridge utilities for cross-worker filesystem access. Filesystem Types [#filesystem-types] ; (path: string): Promise>; }", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "writeFile", "description": "Write file (text or binary).", "tags": [], "type": "(path: string, data: Uint8Array | string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "mkdir", "description": "Create directory, optionally recursive.", "tags": [], "type": "(path: string, options?: { recursive?: boolean; }) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "readdir", "description": "List directory entries (file/dir names).", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "unlink", "description": "Delete file.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "rmdir", "description": "Remove an empty directory.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "rename", "description": "Rename / move a file or directory.", "tags": [], "type": "(oldPath: string, newPath: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "stat", "description": "Get file or directory metadata.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "lstat", "description": "Get file or directory metadata without following symlinks.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "exists", "description": "Check if path exists.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "watch", "description": "Subscribe to filesystem change events for the given paths.\nReturns an unsubscribe function. Events are filtered server-side.", "tags": [], "type": "((request: RuntimeWatchRequest, handler: (event: RuntimeWatchEvent) => void) => () => void) | undefined", "simplifiedType": "function", "required": false, "deprecated": false } ] }} /> ; (path: string): Promise>; }", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "writeFile", "description": "Write file (text or binary).", "tags": [], "type": "(path: string, data: Uint8Array | string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "mkdir", "description": "Create directory, optionally recursive.", "tags": [], "type": "(path: string, options?: { recursive?: boolean; }) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "readdir", "description": "List directory entries (file/dir names).", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "unlink", "description": "Delete file.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "rmdir", "description": "Remove an empty directory.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "rename", "description": "Rename / move a file or directory.", "tags": [], "type": "(oldPath: string, newPath: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "stat", "description": "Get file or directory metadata.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "lstat", "description": "Get file or directory metadata without following symlinks.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "exists", "description": "Check if path exists.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "watch", "description": "Subscribe to filesystem change events for the given paths.\nReturns an unsubscribe function. Events are filtered server-side.", "tags": [], "type": "((request: RuntimeWatchRequest, handler: (event: RuntimeWatchEvent) => void) => () => void) | undefined", "simplifiedType": "function", "required": false, "deprecated": false }, { "name": "readFiles", "description": "Batch-read multiple files as binary. Default: `Promise.all(paths.map(readFile))`.", "tags": [], "type": "(paths: string[]) => Promise>>", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "readdirContents", "description": "Read all file contents in a directory (skips subdirectories).", "tags": [], "type": "(directoryPath: string) => Promise>>", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "readdirStat", "description": "Get stat information for all entries in a directory.", "tags": [], "type": "(directoryPath: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "ensureDir", "description": "Ensure a directory exists, creating parents as needed. Default: `mkdir(path, { recursive: true })`.", "tags": [], "type": "(path: string) => Promise", "simplifiedType": "function", "required": true, "deprecated": false } ] }} /> `).", "entries": [ { "name": "promises", "description": "", "tags": [], "type": "{ readFile(path: string, encoding: \"utf8\"): Promise; readFile(path: string): Promise; writeFile(path: string, data: Uint8Array | string): Promise; mkdir(path: string, options?: { recursive?: boolean; }): Promise; readdir(path: string): Promise; unlink(path: string): Promise; rmdir(path: string): Promise; rename(oldPath: string, newPath: string): Promise; stat(path: string): Promise; lstat(path: string): Promise; }", "simplifiedType": "object", "required": true, "deprecated": false } ] }} /> Constructors [#constructors] | Function | Import Path | Description | | ------------------------------- | ---------------------------- | --------------------------------------------------------- | | `fromNodeFS(basePath)` | `@taucad/runtime/filesystem` | Node.js filesystem rooted at `basePath` | | `fromMemoryFS(files?)` | `@taucad/runtime` | In-memory Map-backed filesystem, optionally seeded | | `fromFsLike(fs, rootPath?)` | `@taucad/runtime` | Any fs-compatible object (BrowserFS, memfs, polyfills) | | `createRuntimeFileSystem(base)` | `@taucad/runtime/filesystem` | Wrap `RuntimeFileSystemBase` with enhanced helper methods | Bridge Types [#bridge-types] void", "simplifiedType": "function", "required": true, "deprecated": false } ] }} /> void", "simplifiedType": "function", "required": true, "deprecated": false } ] }} /> void", "simplifiedType": "function", "required": true, "deprecated": false }, { "name": "activePorts", "description": "", "tags": [], "type": "Set", "simplifiedType": "object", "required": true, "deprecated": false }, { "name": "serverHandles", "description": "", "tags": [], "type": "Map", "simplifiedType": "object", "required": true, "deprecated": false } ] }} /> Bridge Utilities [#bridge-utilities] For cross-worker filesystem access, these utilities create MessagePort-based bridges: | Function | Description | | ---------------------------------------------- | -------------------------------------------------------------------- | | `createBridgePort(handlers)` | Create a MessagePort bridge to a filesystem. Returns `BridgeHandle`. | | `createBridgeServer(handlers, port, options?)` | Serve an object's methods over a MessagePort. | | `createBridgeProxy(port)` | Create a Proxy-based client that dispatches calls over MessagePort. | | `createBridgeCall(port, method, args)` | Send a single RPC call over a MessagePort and await the response. | | `exposeFileSystem(handlers, options?)` | Expose a filesystem to incoming bridge connections. | | `createFileSystemBridge(handlers, options?)` | Create a MessageChannel and transfer a port to a worker. | | `catchMessages(port, handler)` | Attach an error-handling message listener to a MessagePort. | | `extractTransferables(value)` | Walk a value and collect ArrayBuffers for transfer. | Usage [#usage] Node.js Filesystem [#nodejs-filesystem] ```typescript import { createRuntimeClient } from '@taucad/runtime'; import { fromNodeFS } from '@taucad/runtime/filesystem/node'; import { replicad } from '@taucad/runtime/kernels'; import { esbuild } from '@taucad/runtime/bundler'; const client = createRuntimeClient({ kernels: [replicad()], bundlers: [esbuild()], fileSystem: fromNodeFS('/path/to/project'), }); ``` In-Memory Filesystem [#in-memory-filesystem] ```typescript import { createRuntimeClient, fromMemoryFS } from '@taucad/runtime'; import { replicad } from '@taucad/runtime/kernels'; import { esbuild } from '@taucad/runtime/bundler'; const client = createRuntimeClient({ kernels: [replicad()], bundlers: [esbuild()], fileSystem: fromMemoryFS({ 'main.ts': 'export default function main() { return null; }', }), }); ``` Filesystem Bridge [#filesystem-bridge] ```typescript @ts-nocheck import { createBridgePort } from '@taucad/runtime/filesystem'; import { fromNodeFS } from '@taucad/runtime/filesystem/node'; const fileSystem = fromNodeFS('/path/to/project'); const { port, dispose } = createBridgePort(fileSystem); // Transfer port to a worker for remote filesystem access worker.postMessage({ fsPort: port }, [port]); // When done, release resources dispose(); ``` Related [#related] * [Set Up the Filesystem](../guides/filesystem-setup) -- Practical guide to filesystem configuration * [Worker Model](../concepts/worker-model) -- How the filesystem is bridged to the worker * [API: Client](./client) -- `createRuntimeClient` filesystem option * [API: Types](./types) -- `RuntimeFileSystemBase`, `RuntimeFileSystem`