• Stars
    star
    258
  • Rank 157,513 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A virtual file system for .NET written in C#

SharpFileSystem

AppVeyor Travis 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 /

More Repositories

1

probot-auto-merge

A GitHub App built with Probot that automatically merges pull requests
TypeScript
198
star
2

nixpkgs-ruby

A Nix repository with all Ruby versions being kept up-to-date automatically
Nix
113
star
3

nixos-config

My personal NixOS and home-manager configuration
Nix
52
star
4

nix-home

My Nix home-manager configuration
Nix
27
star
5

distscraper

A scraper that retrieves install/live images (.iso files) from different distributions
JavaScript
18
star
6

combine-pull-requests

A GitHub action that combines multiple labelled pull requests onto the current working copy
Shell
11
star
7

mbrfs

A FUSE-filesystem that provides the partitions from a disk device or image.
CMake
8
star
8

pocnix

A proof-of-concept cli for Nix
JavaScript
6
star
9

harhar

A CLI tool to record, replay, manipulate and analyze HTTP archive (HAR) files
JavaScript
6
star
10

streamingwindowsinstall-livecd

An experimental way to install Windows by lazily mounting the Windows ISO from Microsoft.com
Shell
4
star
11

nixpkgs-ruby-updater

JavaScript
3
star
12

templates

Nix
3
star
13

hakkathon

Kotlin
2
star
14

fruit-mamba

A game about a snake that likes fruit for Ludum Dare 45
JavaScript
2
star
15

touchlogo-cap1188

C++
2
star
16

node-machinetalk

A client-side Node API for remotely controlling/monitoring Machinekit instances through Machinetalk
JavaScript
2
star
17

semantic-release-pull-request-analyzer

A plugin for semantic-release that analyzes GitHub pull request labels
JavaScript
2
star
18

sweethomewebxr

SweetHome3D Viewer using WebXR
TypeScript
2
star
19

cycle-remote

An experiment using Cycle.JS and synchronizing state/actions between peers
JavaScript
1
star
20

webinker

JavaScript
1
star
21

browsegpt

Chrome-extension that gives OpenAI GPT control over your browser session
TypeScript
1
star
22

serioussurgery-godot

A Godot implementation of Serious Surgery
GDScript
1
star
23

google-spotify-transfer

A tool to copy favorites from Google Music to Spotify.
JavaScript
1
star
24

mitmproxy2har

Python
1
star
25

vrb

Mirror of http://vrb.sourceforge.net/ with cross-platform additions
C
1
star