MemoryFileProvider
Defined in: file-provider/memory.ts:28
In-memory file provider
Example
Section titled “Example”const provider = new MemoryFileProvider({ '/spec/index.md': '# Main\n:::include ./intro.md :::', '/spec/intro.md': '## Introduction\nContent here...'});
const content = await provider.readText('/spec/index.md');const resolved = provider.resolve('/spec/index.md', './intro.md');// resolved === '/spec/intro.md'Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MemoryFileProvider(
files):MemoryFileProvider
Defined in: file-provider/memory.ts:31
Parameters
Section titled “Parameters”Record<string, string> = {}
Returns
Section titled “Returns”MemoryFileProvider
Methods
Section titled “Methods”canonicalize()
Section titled “canonicalize()”canonicalize(
path):string
Defined in: file-provider/memory.ts:92
Convert a path to its canonical form
Canonical paths are:
- Absolute (no relative segments)
- Normalized (no . or .. segments)
- Consistent across platform (forward slashes for web/memory)
Parameters
Section titled “Parameters”string
Path to canonicalize
Returns
Section titled “Returns”string
Canonical path
Implementation of
Section titled “Implementation of”deleteFile()
Section titled “deleteFile()”deleteFile(
path):boolean
Defined in: file-provider/memory.ts:48
Remove a file from memory
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
hasFile()
Section titled “hasFile()”hasFile(
path):boolean
Defined in: file-provider/memory.ts:55
Check if a file exists
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
listFiles()
Section titled “listFiles()”listFiles():
string[]
Defined in: file-provider/memory.ts:62
Get all file paths
Returns
Section titled “Returns”string[]
readText()
Section titled “readText()”readText(
path):Promise<string>
Defined in: file-provider/memory.ts:66
Read file contents as UTF-8 text
Parameters
Section titled “Parameters”string
Canonical file path
Returns
Section titled “Returns”Promise<string>
File contents as string
Throws
Section titled “Throws”FileNotFoundError if file doesn’t exist
Throws
Section titled “Throws”FileReadError if file cannot be read
Implementation of
Section titled “Implementation of”resolve()
Section titled “resolve()”resolve(
fromFile,relativePath):string
Defined in: file-provider/memory.ts:77
Resolve a relative path from a source file’s location
Parameters
Section titled “Parameters”fromFile
Section titled “fromFile”string
Canonical path of the file containing the reference
relativePath
Section titled “relativePath”string
Relative path to resolve (e.g., ”./foo.md”, ”../bar.md”)
Returns
Section titled “Returns”string
Canonical resolved path
Implementation of
Section titled “Implementation of”setFile()
Section titled “setFile()”setFile(
path,content):void
Defined in: file-provider/memory.ts:41
Add or update a file in memory
Parameters
Section titled “Parameters”string
content
Section titled “content”string
Returns
Section titled “Returns”void