Skip to content

Class: LocalFileSystem

FileSystem implementation that stores files in a folder on the local machine.

const fs = new LocalFileSystem({ root: "./data" });
await fs.init();
await fs.writeFile("hello.txt", "hi");
const home = new LocalFileSystem({ root: "~/projects/data" });
const scratch = tmpFS("my-job");
const cache = homeFS(".cache/app");
  • BaseFileSystem<"local">

new LocalFileSystem(options): LocalFileSystem

LocalFileSystemOptions

LocalFileSystem

BaseFileSystem<"local">.constructor

protected _init: () => Promise<void>

Memoized initialization. Every operation that needs a ready backend awaits this, so callers (e.g. Mastra) may call init every time or never; both are fine.

Promise<void>

BaseFileSystem._init


readonly backend: "local"

Identifier for the underlying implementation.

Examples: “disk”, “ftp”, “sftp”, “memory”, “s3”, or “dbfs”.

BaseFileSystem.backend


protected readonly createRoot: boolean

BaseFileSystem.createRoot


readonly id: string

Unique identifier for this filesystem instance.

BaseFileSystem.id


readonly readOnly: boolean

BaseFileSystem.readOnly


readonly root: string

POSIX-normalized root (see posixPath.normalizeRoot).

BaseFileSystem.root

appendFile(inputPath, content): Promise<void>

string

FileContent

Promise<void>

BaseFileSystem.appendFile


protected assertWritable(operation): void

string

void

BaseFileSystem.assertWritable


close(): Promise<void>

Release connections or other resources.

Promise<void>

BaseFileSystem.close


copyFile(sourcePath, destinationPath, options?): Promise<void>

string

string

CopyOptions = {}

Promise<void>

BaseFileSystem.copyFile


protected createDirectoryAt(resolvedPath): Promise<void>

string

Promise<void>

BaseFileSystem.createDirectoryAt


protected createRootDirectory(): Promise<void>

Ensure root exists when createRoot is true.

Default is a no-op. Local adapters typically mkdir -p; remote adapters leave the default when the root is provisioned out of band.

Promise<void>

BaseFileSystem.createRootDirectory


deleteFile(inputPath, options?): Promise<void>

string

RemoveOptions = {}

Promise<void>

BaseFileSystem.deleteFile


protected deleteFileAt(resolvedPath): Promise<void>

string

Promise<void>

BaseFileSystem.deleteFileAt


protected ensureParentDirectory(inputPath): Promise<void>

Create parent directories for inputPath when it is nested.

string

Promise<void>

BaseFileSystem.ensureParentDirectory


exists(inputPath): Promise<boolean>

string

Promise<boolean>

BaseFileSystem.exists


init(): Promise<void>

Prepare, connect to, or validate the filesystem.

Promise<void>

BaseFileSystem.init


protected isNotFoundError(error): boolean

Recognize the backend’s not-found error.

Default accepts FileSystemError NOT_FOUND plus common SDK / HTTP “not found” shapes via inferFileSystemErrorCode. Override for backend-specific codes (e.g. Node ENOENT) that do not carry a message.

unknown

boolean

BaseFileSystem.isNotFoundError


protected joinNamespace(parent, child): string

string

string

string

BaseFileSystem.joinNamespace


protected listDirectoryAt(resolvedPath): Promise<FileEntry[]>

Return only the direct children of a directory (name is the basename).

string

Promise<FileEntry[]>

BaseFileSystem.listDirectoryAt


protected mapError(err, filePath): FileSystemError

Classify Node errno codes; BaseFileSystem wraps every primitive.

unknown

string

FileSystemError

BaseFileSystem.mapError


mkdir(inputPath, options?): Promise<void>

string

MakeDirectoryOptions = {}

Promise<void>

BaseFileSystem.mkdir


moveFile(sourcePath, destinationPath, options?): Promise<void>

string

string

CopyOptions = {}

Promise<void>

BaseFileSystem.moveFile


protected normalizePath(inputPath): string

Normalize an input path into an absolute POSIX path inside the virtual filesystem namespace (/a/b). Backslashes are converted; .. escaping the root throws FileSystemError PERMISSION_DENIED.

string

string

BaseFileSystem.normalizePath


protected onClose(): Promise<void>

Override when the backend owns connections or other resources.

Promise<void>

BaseFileSystem.onClose


protected onInit(): Promise<void>

Override when the backend requires connection or validation work.

Promise<void>

BaseFileSystem.onInit


protected preparePath(resolvedPath, options?): Promise<string>

When contained, resolve symlinks and ensure the real path still sits under root. Missing leaf paths are allowed when allowMissing is set so writes can create new files.

string

boolean

Promise<string>

BaseFileSystem.preparePath


protected readBytesAt(resolvedPath): Promise<Uint8Array<ArrayBufferLike>>

string

Promise<Uint8Array<ArrayBufferLike>>

BaseFileSystem.readBytesAt


readdir(inputPath, options?): Promise<FileEntry[]>

string

ListOptions = {}

Promise<FileEntry[]>

BaseFileSystem.readdir


readFile(inputPath): Promise<Uint8Array<ArrayBufferLike>>

Read a file as binary data.

string

Promise<Uint8Array<ArrayBufferLike>>

BaseFileSystem.readFile

readFile(inputPath, options): Promise<string>

Read and decode a file as text.

string

ReadFileOptions & object

Promise<string>

BaseFileSystem.readFile


protected removeDirectoryAt(resolvedPath): Promise<void>

Remove an empty directory.

Recursive deletion is implemented by BaseFileSystem.

string

Promise<void>

BaseFileSystem.removeDirectoryAt


protected resolveBackendPath(namespacePath): string

Convert a normalized namespace path (/a/b) into a backend path.

Joins root with the namespace using POSIX /, then applies toBackendPath. Override toBackendPath instead of this method unless the join itself must change.

string

string

BaseFileSystem.resolveBackendPath


protected resolveFor(inputPath, options?): Promise<string>

Resolve inputPath, ensure init, and run preparePath.

string

boolean

Promise<string>

BaseFileSystem.resolveFor


resolvePath(inputPath): string

string

string

BaseFileSystem.resolvePath


rmdir(inputPath, options?): Promise<void>

string

RemoveOptions = {}

Promise<void>

BaseFileSystem.rmdir


stat(inputPath): Promise<FileStat>

string

Promise<FileStat>

BaseFileSystem.stat


protected statAt(resolvedPath): Promise<Omit<FileStat, "path">>

string

Promise<Omit<FileStat, "path">>

BaseFileSystem.statAt


protected toBackendPath(posixBackendPath): string

Convert a POSIX backend path (under root) into the form the underlying API expects.

Default is identity. Local disk overrides with posixPath.toHost. Databricks / object-store adapters usually leave the default.

string

string

BaseFileSystem.toBackendPath


protected toBytes(content): Uint8Array

FileContent

Uint8Array

BaseFileSystem.toBytes


protected toRelativePath(namespacePath): string

Namespace path without a leading slash (. for the root).

string

string

BaseFileSystem.toRelativePath


protected tryAppendFileAt(resolvedPath, content): Promise<boolean>

Override when the backend supports native append.

Parent directories are already created by appendFile. Return true when the operation was performed. The default causes BaseFileSystem to use read-concatenate-write.

string

Uint8Array

Promise<boolean>

BaseFileSystem.tryAppendFileAt


protected tryCopyFileAt(sourcePath, destinationPath, options): Promise<boolean>

Override when the backend supports native server-side copying.

Parent directories of the destination are already created by copyFile.

string

string

Required<CopyOptions>

Promise<boolean>

BaseFileSystem.tryCopyFileAt


protected tryMoveFileAt(sourcePath, destinationPath, options): Promise<boolean>

Override for native rename or move support.

Parent directories of the destination are already created by moveFile.

string

string

Required<CopyOptions>

Promise<boolean>

BaseFileSystem.tryMoveFileAt


protected writeBytesAt(resolvedPath, content, options): Promise<void>

string

Uint8Array

Required<WriteFileOptions>

Promise<void>

BaseFileSystem.writeBytesAt


writeFile(inputPath, content, options?): Promise<void>

string

FileContent

WriteFileOptions = {}

Promise<void>

BaseFileSystem.writeFile