SharpFileSystemV2 1.0.1

dotnet add package SharpFileSystemV2 --version 1.0.1                
NuGet\Install-Package SharpFileSystemV2 -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpFileSystemV2" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpFileSystemV2 --version 1.0.1                
#r "nuget: SharpFileSystemV2, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SharpFileSystemV2 as a Cake Addin
#addin nuget:?package=SharpFileSystemV2&version=1.0.1

// Install SharpFileSystemV2 as a Cake Tool
#tool nuget:?package=SharpFileSystemV2&version=1.0.1                

SharpFileSystem

license

SharpFileSystem is a Virtual File System (VFS) implementation for .NET to allow access to different filesystems in the same way for normal files and directories.

Motivation

After looking a long time for a VFS for .NET, so that I could read files and directories in archives (zip and rar) the same way as any ordinary files and directories. I couldn't find any complete solution for this problem, so I decided to implement a VFS myself. Also what I didn't like in the ordinary filesystems was the path-system. It allowed relative paths (like ..), which can often lead to security issues without explicit checking. It allows referring to directories the same way as referring to files. This often leads to strange behavior, like copying a directory (source) to another directory (destination), here it is often vague whether the destination directory should be overwritten or if it should copy the source-directory inside the destination-directory.

Goals

  • Using multiple types of filesystems (ie. zip, rar, ftp, etc) in the same way.
  • A way to combine these systems to structure multiple parts of your program resources and configurations.
  • A way to restrict or hide parts of your filesystem to parts of your program.
  • A robust way of handling paths.

Features

At the moment the following filesystems are implemented:

  • PhysicalFileSystem: gives access to the real operating system filesystem (uses System.IO of .NET/Mono).
  • MemoryFileSystem: simulates a filesystem in-memory.
  • SevenZipFileSystem: gives access to any 7-Zip supported archive.

There are also filesystems that alter the exposed structure of existing filesystems. These allow you to mix different systems together to get the desired file-structure:

  • ReadOnlyFileSystem: Only allows read-operations on the wrapped filesystem.
  • MergedFileSystem: Merges multiple filesystems into a single file-structure.
  • FileSystemMounter: A unix-like mount system, which mounts other filesystems to a specified path.
  • SubFileSystem: Allows you to create a filesystem from a directory of another filesystem and therefore restricts access to parent-directories.
  • SeamlessSevenZipFileSystem: Allows access to 7-Zip archives as if they're directories.

Implementation

At the heart of the system there is the IFileSystem interface. This describes the operations that should be provided by every filesystem:

public interface IFileSystem : IDisposable
{
    ICollection<FileSystemPath> GetEntities(FileSystemPath path);
    bool Exists(FileSystemPath path);
    Stream CreateFile(FileSystemPath path);
    Stream OpenFile(FileSystemPath path, FileAccess access);
    void CreateDirectory(FileSystemPath path);
    void Delete(FileSystemPath path);
}

Normally in .NET/Mono we refer to files by their path coded as a string. This sometimes leads to inconsistencies, which is why I've created the type FileSystemPath to encapsulate the path in SharpFileSystem. There are operations that help create and alter the path, but the rules of using them are more strict, which creates a much more robust environment for the programmer:

  • Independent of the OS, the directory-separator is always /.
  • All paths always start with /. This means: there are no relative paths.
  • All paths that refer to a directory end with /.
  • All paths that refer to a file do not end with /.
  • The path cannot be manipulated as a string, only new paths can be created through a small set of operations (like System.IO.Path.Combine for .NET).

Some examples of using FileSystemPath:

Operation Result
var root = FileSystemPath.Root /
var mydir = root.AppendDirectory("mydir") /mydir/
var myfile = mydir.AppendFile("myfile") /mydir/myfile
myfile.AppendFile("myfile2") Error: The specified FileSystemPath is not a directory.
mydir.ParentPath /
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on SharpFileSystemV2:

Package Downloads
SharpFileSystemV2.SevenZip

Access archives supported by 7-zip as a virtual file system Support .NET Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0 Support .NET Framework 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

SharpFileSystemV2.SharpZipLib

Access a ZIP as a virtual file system Support .NET Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0 Support .NET Framework 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

SharpFileSystemV2.Resources

Access an assembly’s resources as a virtual file system Support .NET Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0 Support .NET Framework 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 422 7/18/2023
1.0.0 167 7/18/2023