Skip to content

@sqlrooms/webcontainer / WebContainerFsAdapter

Class: WebContainerFsAdapter ​

Implements ​

  • IFileSystem

Constructors ​

Constructor ​

new WebContainerFsAdapter(webContainer): WebContainerFsAdapter

Parameters ​

ParameterType
webContainerWebContainerLike

Returns ​

WebContainerFsAdapter

Methods ​

asFileSystem() ​

asFileSystem(): IFileSystem

Returns ​

IFileSystem


syncFromWebContainer() ​

syncFromWebContainer(): Promise<void>

Returns ​

Promise<void>


readFile() ​

readFile(path, options?): Promise<string>

Read the contents of a file as a string (default: utf8)

Parameters ​

ParameterType
pathstring
options?{ encoding?: BufferEncoding | null | undefined; } | BufferEncoding

Returns ​

Promise<string>

Throws ​

Error if file doesn't exist or is a directory

Implementation of ​

IFileSystem.readFile


readFileBuffer() ​

readFileBuffer(path): Promise<Uint8Array<ArrayBufferLike>>

Read the contents of a file as a Uint8Array (binary)

Parameters ​

ParameterType
pathstring

Returns ​

Promise<Uint8Array<ArrayBufferLike>>

Throws ​

Error if file doesn't exist or is a directory

Implementation of ​

IFileSystem.readFileBuffer


writeFile() ​

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

Write content to a file, creating it if it doesn't exist

Parameters ​

ParameterType
pathstring
contentFileContent
options?BufferEncoding | { encoding?: BufferEncoding | undefined; }

Returns ​

Promise<void>

Implementation of ​

IFileSystem.writeFile


appendFile() ​

appendFile(path, content, options?): Promise<void>

Append content to a file, creating it if it doesn't exist

Parameters ​

ParameterType
pathstring
contentFileContent
options?BufferEncoding | { encoding?: BufferEncoding | undefined; }

Returns ​

Promise<void>

Implementation of ​

IFileSystem.appendFile


exists() ​

exists(path): Promise<boolean>

Check if a path exists

Parameters ​

ParameterType
pathstring

Returns ​

Promise<boolean>

Implementation of ​

IFileSystem.exists


stat() ​

stat(path): Promise<FsStat>

Get file/directory information

Parameters ​

ParameterType
pathstring

Returns ​

Promise<FsStat>

Throws ​

Error if path doesn't exist

Implementation of ​

IFileSystem.stat


mkdir() ​

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

Create a directory

Parameters ​

ParameterType
pathstring
options?MkdirOptions

Returns ​

Promise<void>

Throws ​

Error if parent doesn't exist (unless recursive) or path exists

Implementation of ​

IFileSystem.mkdir


readdir() ​

readdir(path): Promise<string[]>

Read directory contents

Parameters ​

ParameterType
pathstring

Returns ​

Promise<string[]>

Array of entry names (not full paths)

Throws ​

Error if path doesn't exist or is not a directory

Implementation of ​

IFileSystem.readdir


rm() ​

rm(path, options?): Promise<void>

Remove a file or directory

Parameters ​

ParameterType
pathstring
options?RmOptions

Returns ​

Promise<void>

Throws ​

Error if path doesn't exist (unless force) or directory not empty (unless recursive)

Implementation of ​

IFileSystem.rm


cp() ​

cp(src, dest, options?): Promise<void>

Copy a file or directory

Parameters ​

ParameterType
srcstring
deststring
options?CpOptions

Returns ​

Promise<void>

Throws ​

Error if source doesn't exist or trying to copy directory without recursive

Implementation of ​

IFileSystem.cp


mv() ​

mv(src, dest): Promise<void>

Move/rename a file or directory

Parameters ​

ParameterType
srcstring
deststring

Returns ​

Promise<void>

Implementation of ​

IFileSystem.mv


resolvePath() ​

resolvePath(base, path): string

Resolve a relative path against a base path

Parameters ​

ParameterType
basestring
pathstring

Returns ​

string

Implementation of ​

IFileSystem.resolvePath


getAllPaths() ​

getAllPaths(): string[]

Get all paths in the filesystem (useful for glob matching) Optional - implementations may return empty array if not supported

Returns ​

string[]

Implementation of ​

IFileSystem.getAllPaths


chmod() ​

chmod(path, mode): Promise<void>

Change file/directory permissions

Parameters ​

ParameterType
pathstring
modenumber

Returns ​

Promise<void>

Throws ​

Error if path doesn't exist

Implementation of ​

IFileSystem.chmod


symlink(_target, _linkPath): Promise<void>

Create a symbolic link

Parameters ​

ParameterType
_targetstring
_linkPathstring

Returns ​

Promise<void>

Throws ​

Error if linkPath already exists

Implementation of ​

IFileSystem.symlink


link(_existingPath, _newPath): Promise<void>

Create a hard link

Parameters ​

ParameterType
_existingPathstring
_newPathstring

Returns ​

Promise<void>

Throws ​

Error if existingPath doesn't exist or newPath already exists

Implementation of ​

IFileSystem.link


readlink(path): Promise<string>

Read the target of a symbolic link

Parameters ​

ParameterType
pathstring

Returns ​

Promise<string>

Throws ​

Error if path doesn't exist or is not a symlink

Implementation of ​

IFileSystem.readlink


lstat() ​

lstat(path): Promise<FsStat>

Get file/directory information without following symlinks

Parameters ​

ParameterType
pathstring

Returns ​

Promise<FsStat>

Throws ​

Error if path doesn't exist

Implementation of ​

IFileSystem.lstat


realpath() ​

realpath(path): Promise<string>

Resolve all symlinks in a path to get the canonical physical path. This is equivalent to POSIX realpath() - it resolves all symlinks in the path and returns the absolute physical path. Used by pwd -P and cd -P for symlink resolution.

Parameters ​

ParameterType
pathstring

Returns ​

Promise<string>

Throws ​

Error if path doesn't exist or contains a broken symlink

Implementation of ​

IFileSystem.realpath


utimes() ​

utimes(path, atime, mtime): Promise<void>

Set access and modification times of a file

Parameters ​

ParameterTypeDescription
pathstringThe file path
atimeDateAccess time (currently ignored, kept for API compatibility)
mtimeDateModification time

Returns ​

Promise<void>

Throws ​

Error if path doesn't exist

Implementation of ​

IFileSystem.utimes