Skip to content

Atypical-Consulting/VirtualFileSystem

Virtual File System Sparkline

A virtual file system implementation in modern C#.


Atypical-Consulting - VirtualFileSystem License: BSD-3-Clause stars - VirtualFileSystem forks - VirtualFileSystem

GitHub tag issues - VirtualFileSystem GitHub pull requests GitHub contributors GitHub last commit codecov

NuGet NuGet


πŸ“ Table of Contents

πŸ“– Introduction

When writing applications in .NET, you often need to write or read the contents of a file. .NET provides System.IO namespace dedicated to this purpose. But how do we deal with the filesystem when testing our code?

Virtual File System is an attempt to solve this problem. Currently, this library is at an early stage of development. If you need additional functionality, I invite you to open an issue to discuss it.

🧐 What is a virtual file system and why should I use it?

A virtual file system is a data structure that represents a file system in memory. It is used to simulate a file system on a computer. It is useful for testing purposes, for example, when you want to test a file system without actually creating files on the hard drive.

πŸ“Œ Features

  • Create a virtual file system
  • Create a virtual file or directory
  • Print the contents of a virtual file system as a tree
  • Delete a virtual file or directory
  • Move a virtual file or directory
  • Rename a virtual file or directory
  • Read and write content to a virtual file
  • Copy a virtual file or directory (planned)
  • Check if a virtual file or directory exists (planned)
  • Get the size of a virtual file or directory (planned)
  • Get the creation, access, and modification times of a virtual file or directory
  • Support for events (file created, file deleted, etc.)
  • Support for custom metadata on files and directories
  • Support for file and directory permissions (planned)
  • Support for symbolic links (planned)
  • ...

πŸ“„ Documentation

Virtual File System provides a COMPLETE DOCUMENTATION of the library.

All summaries are written in English. If you want to help us translate the documentation, please open an issue to discuss it.

Note: The documentation is generated using Doraku/DefaultDocumentation tool. It is generated automatically when the project is built.

πŸ“₯ Installation

πŸ“‹ Prerequisites

  • .NET 6.0 (supported versions: 6.x to 8.x)
  • A C# IDE (Visual Studio, Rider, etc.)
  • A C# compiler (dotnet CLI, etc.)

πŸš€ We use the latest C# features

This library targets .NET 8.0 and uses the latest C# features. It is written in C# 12.0 and uses the new init properties, record types, switch expressions, using declarations and more.

I invite you to read the C# 12.0 documentation to learn more about these features.

πŸ“¦ NuGet

VirtualFileSystem is available on NuGet.

You can install it using the .NET CLI:

dotnet add package Atypical.VirtualFileSystem

or by adding a package reference to your project file:

<PackageReference Include="Atypical.VirtualFileSystem" Version="0.3.0" />

πŸ“ From source

You can also clone the repository and build the project yourself.

git clone
cd VirtualFileSystem
dotnet build

πŸ“š Use cases

Creating a virtual file system, add some files and print the content as an ASCII tree

// sample output (the order of the files is alphabetical)
string expected = """
    vfs://
    β”œβ”€β”€ superheroes
    β”‚   β”œβ”€β”€ batman.txt
    β”‚   β”œβ”€β”€ superman.txt
    β”‚   └── wonderwoman.txt
    β”œβ”€β”€ villains
    β”‚   β”œβ”€β”€ joker.txt
    β”‚   β”œβ”€β”€ lexluthor.txt
    β”‚   └── penguin.txt
    └── world
        β”œβ”€β”€ gotham.txt
        β”œβ”€β”€ metropolis.txt
        └── themyscira.txt
    """;

// create a virtual file system
IVirtualFileSystem vfs = new VFS()
    // add some files (directories are created automatically)
    .CreateFile("superheroes/batman.txt")
    .CreateFile("superheroes/superman.txt")
    .CreateFile("superheroes/wonderwoman.txt")
    .CreateFile("villains/joker.txt")
    .CreateFile("villains/lexluthor.txt")
    .CreateFile("villains/penguin.txt")
    .CreateFile("world/gotham.txt")
    .CreateFile("world/metropolis.txt")
    .CreateFile("world/themyscira.txt");

// get the string representation of the virtual file system
string tree = vfs.GetTree();

🀝 Contributing

Contributions are welcome! Please read the CONTRIBUTION GUIDELINES first.

πŸ“œ License

This project is licensed under the terms of the BSD-3-Clause license. If you use this library in your project, please consider adding a link to this repository in your project's README.

This project is maintained by Atypical Consulting. If you need help with this project, please contact us from this repository by opening an issue.

πŸ“¬ Contact

You can contact us by opening an issue on this repository.

πŸ™Œ Acknowledgements

πŸŽ‰ Change log

Please see RELEASES for more information what has changed recently.

✨ Contributors

Contributors