Skip to content
Auto
Products

Custom file system

The FileSystem class allows to create custom file system by passing instance of class implemented IFileSystemReadOperations or IFileSystemOperations operations.

Example implementation:

var fileSystem = new FileSystem(new CustomFileSystemOperations());
internal class CustomFileSystemOperations : IFileSystemOperations, IFileSystemHistoryOperations
{
// Implementation
}

All operations interfaces are optional except IFileSystemOperations - implement only the ones relevant to what your storage supports; FileSystem checks at runtime which interfaces an operations object implements and reports NotSupportedException for missing capabilities.

InterfaceDescription
IFileSystemOperationsThe base interface every operations class must implement. Exposes Kind and Name of the file system.
IFileSystemReadOperationsProvides methods for reading files / directories, e.g. ReadFile, GetLinkInfo, GetLinks.
IFileSystemWriteOperationsProvides methods for writing, moving or deleting files; create, move or delete directories and update metadata files / directories.
IFileSystemDirectReadWriteOperationsProvides OpenFileStream for opening a file directly as a read/write/read-write Stream, instead of going through ReadFile/WriteFile.
IFileSystemCustomPathOperationsLets a file system provide its own DirectorySeparator and normalize/correct paths via CorrectPath.
IFileSystemFeatureSupportDeclares optional features through FileSystemOperationsFeatures - which metadata the storage keeps (HiddenAttribute, ReadOnlyAttribute, LastWriteTimeAttributes), whether it accepts ConcurrentWriteOperations, and whether directories are real objects (HierarchicalDirectories). Operations that do not implement this interface support no optional feature. What a consumer sees is described in provider capabilities.
IFileSystemPermissionsOperationsProvides methods HasReadAccess and HasWriteAccess for checking files permissions.
IFileSystemWatchOperationsProvides methods CreateFileWatcher and CreateDirectoryWatcher to watch files/directories changes, see change notifications and watching.
IFileSystemHistoryOperationsProvides files/directories history methods e.g. ReadFileVersion, DeleteFileVersion, GetFileVersionInfo, GetFileVersions, see file history and versioning.
IFileSystemAsyncReadOperationsProvides asynchronous equivalents of IFileSystemReadOperations methods.
IFileSystemAsyncWriteOperationsProvides asynchronous equivalents of IFileSystemWriteOperations methods.
IFileSystemAsyncDirectReadWriteOperationsProvides an asynchronous equivalent of IFileSystemDirectReadWriteOperations (OpenFileStreamAsync).
IFileSystemAsyncHistoryOperationsProvides asynchronous equivalents of IFileSystemHistoryOperations methods.

Built-in async-to-sync and sync-to-async wrappers (in TagBites.IO.Operations.Wrappers) let a file system that only implements the synchronous (or only the asynchronous) interfaces be used through the other API as well.