BaseFileSystemclass

A filesystem. Could be on disk, or in memory, or in the cloud. Could be writable or read only. Or it could be an aggregation of all those things, merged together and read only.

object→BaseFileSystem
Namespace
Sandbox
Assembly
Sandbox.Filesystem
Declaration
public class Sandbox.BaseFileSystem

Methods24

Showing 24 methods

public void CreateDirectory(string folder)PUBLIC

Create a directory - or a tree of directories. Returns silently if the directory already exists.

ParameterTypeDescription
folderstring—
Returns:void—

public Sandbox.BaseFileSystem CreateSubSystem(string path)PUBLIC

Create a sub-filesystem at the specified path

ParameterTypeDescription
pathstring—
Returns:BaseFileSystem—

public void DeleteDirectory(string folder, bool recursive = False)PUBLIC

Delete a folder and optionally all of its contents

ParameterTypeDescription
folderstring—
recursive = Falsebool—
Returns:void—

public void DeleteFile(string path)PUBLIC

Delete a file

ParameterTypeDescription
pathstring—
Returns:void—

public bool DirectoryExists(string path)PUBLIC

Returns true if the directory exists on this filesystem

ParameterTypeDescription
pathstring—
Returns:bool—

public int DirectorySize(string path, bool recursive = False)PUBLIC

Gets the size in bytes of all the files in a directory

ParameterTypeDescription
pathstring—
recursive = Falsebool—
Returns:int—

public bool FileExists(string path)PUBLIC

Returns true if the file exists on this filesystem

ParameterTypeDescription
pathstring—
Returns:bool—

public long FileSize(string filepath)PUBLIC

Returns file size of given file.

ParameterTypeDescription
filepathstringFile path to the file to look up size of.
Returns:longFile size, in bytes.

public System.Collections.Generic.IEnumerable`1<string> FindDirectory(string folder, string pattern = *, bool recursive = False)PUBLIC

Get a list of directories

ParameterTypeDescription
folderstring—
pattern = *string—
recursive = Falsebool—
Returns:IEnumerable<string>—

public System.Collections.Generic.IEnumerable`1<string> FindFile(string folder, string pattern = *, bool recursive = False)PUBLIC

Get a list of files

ParameterTypeDescription
folderstring—
pattern = *string—
recursive = Falsebool—
Returns:IEnumerable<string>—

public ulong GetCrc(string filepath)PUBLIC

Returns CRC64 of the file contents.

ParameterTypeDescription
filepathstringFile path to the file to get CRC of.
Returns:ulongThe CRC64, or 0 if file is not found.

public System.Threading.Tasks.Task`1<ulong> GetCrcAsync(string filepath)PUBLIC

Returns CRC64 of the file contents.

ParameterTypeDescription
filepathstringFile path to the file to get CRC of.
Returns:Task<ulong>The CRC64, or 0 if file is not found.

public string GetFullPath(string path)PUBLIC

Returns the full physical path to a file or folder on disk, or null if it isn't on disk.

ParameterTypeDescription
pathstring—
Returns:string—

public System.IO.Stream OpenRead(string path, System.IO.FileMode mode = 3)PUBLIC

Open a file for read. Will throw an exception if it doesn't exist.

ParameterTypeDescription
pathstring—
mode = 3FileMode—
Returns:Stream—

public System.IO.Stream OpenWrite(string path, System.IO.FileMode mode = 2)PUBLIC

Open a file for write. If the file exists we'll overwrite it (by default)

ParameterTypeDescription
pathstring—
mode = 2FileMode—
Returns:Stream—

public System.Span`1<byte> ReadAllBytes(string path)PUBLIC

Read the contents of path and return it as a string

ParameterTypeDescription
pathstring—
Returns:Span<byte>—

public System.Threading.Tasks.Task`1<byte[]> ReadAllBytesAsync(string path)PUBLIC

Read the contents of path and return it as a string

ParameterTypeDescription
pathstring—
Returns:Task<byte[]>—

public string ReadAllText(string path)PUBLIC

Read the contents of path and return it as a string. Returns null if file not found.

ParameterTypeDescription
pathstring—
Returns:string—

public System.Threading.Tasks.Task`1<string> ReadAllTextAsync(string path)PUBLIC

Read the contents of path and return it as a string

ParameterTypeDescription
pathstring—
Returns:Task<string>—

public T ReadJson(string filename, T defaultValue = null)PUBLIC

Read Json from a file using System.Text.Json.JsonSerializer. This will throw exceptions if not valid json.

ParameterTypeDescription
filenamestring—
defaultValue = nullT—
Returns:T—

public T ReadJsonOrDefault(string filename, T returnOnError = null)PUBLIC

The same as ReadJson except will return a default value on missing/error.

ParameterTypeDescription
filenamestring—
returnOnError = nullT—
Returns:T—

public void WriteAllBytes(string path, byte[] contents)PUBLIC

Write the contents to the path. The file will be over-written if the file exists

ParameterTypeDescription
pathstring—
contentsbyte[]—
Returns:void—

public void WriteAllText(string path, string contents)PUBLIC

Write the contents to the path. The file will be over-written if the file exists

ParameterTypeDescription
pathstring—
contentsstring—
Returns:void—

public void WriteJson(string filename, T data)PUBLIC

Convert object to json and write it to the specified file

ParameterTypeDescription
filenamestring—
dataT—
Returns:void—

Properties2

Showing 2 properties

public bool Sandbox.BaseFileSystem.IsReadOnly { get; set; }PUBLICGETSET

Returns true if this filesystem is read only

Returns:bool—

public bool Sandbox.BaseFileSystem.IsValid { get; set; }PUBLICGETSET

Returns:bool—

On this page

Methodspublic System.Void CreateDirectory(System.String folder)public Sandbox.BaseFileSystem CreateSubSystem(System.String path)public System.Void DeleteDirectory(System.String folder, System.Boolean recursive = False)public System.Void DeleteFile(System.String path)public System.Boolean DirectoryExists(System.String path)public System.Int32 DirectorySize(System.String path, System.Boolean recursive = False)public System.Boolean FileExists(System.String path)public System.Int64 FileSize(System.String filepath)public System.Collections.Generic.IEnumerable`1<System.String> FindDirectory(System.String folder, System.String pattern = *, System.Boolean recursive = False)public System.Collections.Generic.IEnumerable`1<System.String> FindFile(System.String folder, System.String pattern = *, System.Boolean recursive = False)public System.UInt64 GetCrc(System.String filepath)public System.Threading.Tasks.Task`1<System.UInt64> GetCrcAsync(System.String filepath)public System.String GetFullPath(System.String path)public System.IO.Stream OpenRead(System.String path, System.IO.FileMode mode = 3)public System.IO.Stream OpenWrite(System.String path, System.IO.FileMode mode = 2)public System.Span`1<System.Byte> ReadAllBytes(System.String path)public System.Threading.Tasks.Task`1<System.Byte[]> ReadAllBytesAsync(System.String path)public System.String ReadAllText(System.String path)public System.Threading.Tasks.Task`1<System.String> ReadAllTextAsync(System.String path)public T ReadJson(System.String filename, T defaultValue = null)public T ReadJsonOrDefault(System.String filename, T returnOnError = null)public System.Void WriteAllBytes(System.String path, System.Byte[] contents)public System.Void WriteAllText(System.String path, System.String contents)public System.Void WriteJson(System.String filename, T data)Propertiespublic System.Boolean Sandbox.BaseFileSystem.IsReadOnly { get; set; }public System.Boolean Sandbox.BaseFileSystem.IsValid { get; set; }Metadata