InMemoryFileSystemBackend Class

A FileSystemBackend that keeps the files in memory: the default backend of the browsing contexts (see BrowsingContextOptions.FileSystem). It is thread-safe, and can be shared by several browsing contexts.

public sealed class InMemoryFileSystemBackend : FileSystemBackend
Inheritance
FileSystemBackend InMemoryFileSystemBackend

Constructors

NameDescription
InMemoryFileSystemBackend()

InMemoryFileSystemBackend()

InMemoryFileSystemBackend.cs
public InMemoryFileSystemBackend()

No documentation is available.

Methods

NameDescription
CreateEntry(string, IReadOnlyList<string>, FileSystemHandleKind, long)Creates an empty file or an empty directory, and returns true; returns false when its parent directory does not exist or when an entry already has its name.
GetEntries(string, IReadOnlyList<string>)Returns the entries of a directory (in any order), or null when the directory does not exist.
GetEntryKind(string, IReadOnlyList<string>)Returns the kind of the entry at a path, or null when there is none.
GetFileInfo(string, IReadOnlyList<string>)Returns the size and the modification timestamp of a file, or null when the file does not exist.
GetUsage(string)Returns an estimation of the number of bytes used by the file system of an origin (navigator.storage.estimate()). The default is 0: the usage is not reported.
MoveFile(string, IReadOnlyList<string>, IReadOnlyList<string>)Moves a file to another path (another name, another directory, or both), replacing the file that has the new path when there is one, and returns true; returns false when the file or the new parent directory does not exist, or when the new path is the one of a directory.
ReadFile(string, IReadOnlyList<string>, long, Span<byte>)Reads bytes of a file from a position, and returns the number of bytes read (less than the length of the buffer at the end of the file; 0 when the file does not exist).
RemoveEntry(string, IReadOnlyList<string>)Removes a file, or a directory with all its entries, and returns true; returns false when the entry does not exist. The root directory is emptied, not removed.
ReplaceFileContent(string, IReadOnlyList<string>, ReadOnlyMemory<byte>, long)Replaces the content of a file atomically (a writable stream is closed), and returns true; returns false when the file does not exist.
SetFileSize(string, IReadOnlyList<string>, long, long)Sets the size of a file: the file is truncated, or grows with zeros.
WriteFile(string, IReadOnlyList<string>, long, ReadOnlySpan<byte>, long)Writes bytes into a file at a position (the access handles write in place): the file grows when the bytes end after its end, and the bytes between its end and a greater position are zeros.

CreateEntry(string, IReadOnlyList<string>, FileSystemHandleKind, long)

InMemoryFileSystemBackend.cs

Creates an empty file or an empty directory, and returns true; returns false when its parent directory does not exist or when an entry already has its name.

public override bool CreateEntry(string origin, IReadOnlyList<string> path, FileSystemHandleKind kind, long modificationTime)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the new entry.
kind FileSystemHandleKind
The kind of the entry.
modificationTime long
The modification timestamp of a new file, in milliseconds since the Unix epoch.

Returns

bool

GetEntries(string, IReadOnlyList<string>)

InMemoryFileSystemBackend.cs

Returns the entries of a directory (in any order), or null when the directory does not exist.

public override IReadOnlyList<FileSystemEntry>? GetEntries(string origin, IReadOnlyList<string> path)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the directory (empty for the root directory).

Returns

IReadOnlyList<FileSystemEntry>?

GetEntryKind(string, IReadOnlyList<string>)

InMemoryFileSystemBackend.cs

Returns the kind of the entry at a path, or null when there is none.

public override FileSystemHandleKind? GetEntryKind(string origin, IReadOnlyList<string> path)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the entry (empty for the root directory).

Returns

FileSystemHandleKind?

GetFileInfo(string, IReadOnlyList<string>)

InMemoryFileSystemBackend.cs

Returns the size and the modification timestamp of a file, or null when the file does not exist.

public override FileSystemFileInfo? GetFileInfo(string origin, IReadOnlyList<string> path)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the file.

Returns

FileSystemFileInfo?

Returns an estimation of the number of bytes used by the file system of an origin (navigator.storage.estimate()). The default is 0: the usage is not reported.

public override long GetUsage(string origin)

Parameters

origin string
The serialization of the origin.

Returns

long

MoveFile(string, IReadOnlyList<string>, IReadOnlyList<string>)

InMemoryFileSystemBackend.cs

Moves a file to another path (another name, another directory, or both), replacing the file that has the new path when there is one, and returns true; returns false when the file or the new parent directory does not exist, or when the new path is the one of a directory.

public override bool MoveFile(string origin, IReadOnlyList<string> path, IReadOnlyList<string> newPath)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the file.
newPath IReadOnlyList<string>
The new path of the file.

Returns

bool

ReadFile(string, IReadOnlyList<string>, long, Span<byte>)

InMemoryFileSystemBackend.cs

Reads bytes of a file from a position, and returns the number of bytes read (less than the length of the buffer at the end of the file; 0 when the file does not exist).

public override int ReadFile(string origin, IReadOnlyList<string> path, long position, Span<byte> buffer)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the file.
position long
The position of the first byte to read.
buffer Span<byte>
The buffer to fill.

Returns

int

RemoveEntry(string, IReadOnlyList<string>)

InMemoryFileSystemBackend.cs

Removes a file, or a directory with all its entries, and returns true; returns false when the entry does not exist. The root directory is emptied, not removed.

public override bool RemoveEntry(string origin, IReadOnlyList<string> path)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the entry.

Returns

bool

ReplaceFileContent(string, IReadOnlyList<string>, ReadOnlyMemory<byte>, long)

InMemoryFileSystemBackend.cs

Replaces the content of a file atomically (a writable stream is closed), and returns true; returns false when the file does not exist.

public override bool ReplaceFileContent(string origin, IReadOnlyList<string> path, ReadOnlyMemory<byte> content, long modificationTime)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the file.
content ReadOnlyMemory<byte>
The new content.
modificationTime long
The new modification timestamp of the file, in milliseconds since the Unix epoch.

Returns

bool

SetFileSize(string, IReadOnlyList<string>, long, long)

InMemoryFileSystemBackend.cs

Sets the size of a file: the file is truncated, or grows with zeros.

public override void SetFileSize(string origin, IReadOnlyList<string> path, long size, long modificationTime)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the file.
size long
The new size.
modificationTime long
The new modification timestamp of the file, in milliseconds since the Unix epoch.

WriteFile(string, IReadOnlyList<string>, long, ReadOnlySpan<byte>, long)

InMemoryFileSystemBackend.cs

Writes bytes into a file at a position (the access handles write in place): the file grows when the bytes end after its end, and the bytes between its end and a greater position are zeros.

public override void WriteFile(string origin, IReadOnlyList<string> path, long position, ReadOnlySpan<byte> data, long modificationTime)

Parameters

origin string
The serialization of the origin.
path IReadOnlyList<string>
The path of the file.
position long
The position of the first byte to write.
data ReadOnlySpan<byte>
The bytes to write.
modificationTime long
The new modification timestamp of the file, in milliseconds since the Unix epoch.