WasiInMemoryFileSystem Class
A file system in memory: files, directories, symbolic links and hard links that the module reads and writes, and that the host prepares (WasiInMemoryFileSystem.AddFile, WasiInMemoryFileSystem.AddDirectory, WasiInMemoryFileSystem.AddSymbolicLink) and reads (WasiInMemoryFileSystem.ReadAllBytes). It does not access the disk, so it works on every platform, including the browser.
public sealed class WasiInMemoryFileSystem : WasiFileSystemRemarks
The paths of the methods of the host are relative to the root, with / or \ separators. The file system is not thread-safe.
- Inheritance
WasiFileSystemWasiInMemoryFileSystem
Constructors
| Name | Description |
|---|---|
| WasiInMemoryFileSystem(bool) | Initializes a new instance of the WasiInMemoryFileSystem class, which is empty. |
WasiInMemoryFileSystem(bool)
WasiInMemoryFileSystem.csInitializes a new instance of the WasiInMemoryFileSystem class, which is empty.
public WasiInMemoryFileSystem(bool isReadOnly = false)Parameters
isReadOnlybool- Whether the module can only read the file system. The host can still change it.
Properties
| Name | Description |
|---|---|
| IsReadOnly | Gets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem. |
| MaxFileSize | Gets the maximum size of a file in bytes: a write or a truncation beyond fails with WasiErrno.FileTooLarge. The default and the upper limit is the maximum length of a .NET array. |
| TimeProvider | Gets the clock of the times of the files. The default is TimeProvider.System. |
IsReadOnly
WasiInMemoryFileSystem.csGets whether the module can only read the file system: the operations that change it return WasiErrno.ReadOnlyFileSystem.
public override bool IsReadOnly { get; }Property value
MaxFileSize
WasiInMemoryFileSystem.csGets the maximum size of a file in bytes: a write or a truncation beyond fails with WasiErrno.FileTooLarge. The default and the upper limit is the maximum length of a .NET array.
public long MaxFileSize { get; init; }Property value
TimeProvider
WasiInMemoryFileSystem.csGets the clock of the times of the files. The default is TimeProvider.System.
public TimeProvider TimeProvider { get; init; }Property value
Methods
| Name | Description |
|---|---|
| AddDirectory(string) | Adds a directory and its parents. |
| AddFile(string, ReadOnlySpan<byte>) | Adds a file, or replaces the content of a file, and creates its parent directories. |
| AddSymbolicLink(string, string) | Adds a symbolic link, and creates its parent directories. |
| CreateDirectory(string) | Creates a directory. |
| CreateHardLink(string, string) | Creates a hard link to a file. The default implementation throws a WasiException whose code is WasiErrno.NotSupported. |
| CreateSymbolicLink(string, string) | Creates a symbolic link. The default implementation throws a WasiException whose code is WasiErrno.NotSupported. |
| DeleteDirectory(string) | Deletes a directory. |
| DeleteFile(string) | Deletes a file or a symbolic link (not its target). |
| EnumerateDirectory(string) | Returns the entries of a directory, without . and ... |
| Exists(string) | Returns whether a file, a directory or a symbolic link exists. |
| GetStat(string) | Returns the status of a file, of a directory or of a symbolic link (not of its target), or null when it does not exist. |
| Move(string, string) | Moves a file, a directory or a symbolic link. |
| OpenFile(string, FileMode, FileAccess) | Opens a regular file. The stream of a regular file must be seekable. |
| ReadAllBytes(string) | Returns the content of a file. |
| ReadSymbolicLink(string) | Returns the target of a symbolic link, with / separators. A target that starts with / is absolute: WASI does not follow it. |
| SetTimes(string, DateTimeOffset?, DateTimeOffset?) | Changes the times of a file or of a directory. |
AddDirectory(string)
WasiInMemoryFileSystem.csAdds a directory and its parents.
Parameters
pathstring- The path of the directory.
Exceptions
ArgumentException- The path is not valid, or an entry of the path is not a directory.
AddFile(string, ReadOnlySpan<byte>)
WasiInMemoryFileSystem.csAdds a file, or replaces the content of a file, and creates its parent directories.
public void AddFile(string path, ReadOnlySpan<byte> content)Parameters
pathstring- The path of the file.
contentReadOnlySpan<byte>- The content of the file.
Exceptions
ArgumentException- The path is not valid, or an entry of the path is not a directory.
AddSymbolicLink(string, string)
WasiInMemoryFileSystem.csAdds a symbolic link, and creates its parent directories.
Parameters
pathstring- The path of the link.
targetstring- The target of the link, relative to the directory of the link, with
/separators.
Exceptions
ArgumentException- The path is not valid or exists, or an entry of the path is not a directory.
CreateDirectory(string)
WasiInMemoryFileSystem.csCreateHardLink(string, string)
WasiInMemoryFileSystem.csCreates a hard link to a file. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.
CreateSymbolicLink(string, string)
WasiInMemoryFileSystem.csCreates a symbolic link. The default implementation throws a WasiException whose code is WasiErrno.NotSupported.
DeleteDirectory(string)
WasiInMemoryFileSystem.csDeleteFile(string)
WasiInMemoryFileSystem.csEnumerateDirectory(string)
WasiInMemoryFileSystem.csReturns the entries of a directory, without . and ...
public override IEnumerable<WasiDirectoryEntry> EnumerateDirectory(string path)Exists(string)
WasiInMemoryFileSystem.csGetStat(string)
WasiInMemoryFileSystem.csReturns the status of a file, of a directory or of a symbolic link (not of its target), or null when it does not exist.
public override WasiFileStat? GetStat(string path)Move(string, string)
WasiInMemoryFileSystem.csMoves a file, a directory or a symbolic link.
OpenFile(string, FileMode, FileAccess)
WasiInMemoryFileSystem.csOpens a regular file. The stream of a regular file must be seekable.
public override Stream OpenFile(string path, FileMode mode, FileAccess access)Parameters
pathstring- The path of the file. Its parent is an existing directory.
modeFileMode- How the file is opened, or created.
accessFileAccess- The access to the file.
Returns
ReadAllBytes(string)
WasiInMemoryFileSystem.csReturns the content of a file.
Parameters
pathstring- The path of the file. The symbolic links are not followed.
Returns
byte[]
Exceptions
FileNotFoundException- The file does not exist, or is not a regular file.
ReadSymbolicLink(string)
WasiInMemoryFileSystem.csSetTimes(string, DateTimeOffset?, DateTimeOffset?)
WasiInMemoryFileSystem.csChanges the times of a file or of a directory.
public override void SetTimes(string path, DateTimeOffset? lastAccessTime, DateTimeOffset? lastWriteTime)Parameters
pathstring- The path of an existing file or directory.
lastAccessTimeDateTimeOffset?- The new time of the last access, or null to keep it.
lastWriteTimeDateTimeOffset?- The new time of the last write, or null to keep it.