https://github.com/purifetchi/nano.vfs
Simple modular in-memory virtual file system.
https://github.com/purifetchi/nano.vfs
csharp dotnet vfs
Last synced: 2 months ago
JSON representation
Simple modular in-memory virtual file system.
- Host: GitHub
- URL: https://github.com/purifetchi/nano.vfs
- Owner: purifetchi
- License: mit
- Created: 2020-11-13T10:56:05.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-14T13:13:48.000Z (over 5 years ago)
- Last Synced: 2025-03-15T21:48:23.198Z (over 1 year ago)
- Topics: csharp, dotnet, vfs
- Language: C#
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nano.VFS
Nano.VFS is a simple and modular implementation of an in-memory virtual file system. It allows you to create custom entry wrappers that mount into a centralized VFS class, meaning that you can mix different storage formats.
# Provided VFS entry backends
- OSFileEntry (Can mount directories and files from the FS)
- ZipFileEntry (Can mount directories and files from ZIP archives)
# Usage
**Mounting a zip archive**
```cs
// Create a new VirtualFileSystem instance
var vfs = new VirtualFileSystem();
// Create a file stream for the zip archive and open it with System.IO.Compression's ZipArchive
var fileStream = new FileStream("archive.zip", FileMode.Open);
var archive = new ZipArchive(fileStream, ZipArchiveMode.Read);
// Add every entry from the archive into the VFS
// This already creates the folder structure
foreach (var entry in archive.Entries)
{
vfs.Add(entry);
}
```
**Mounting files from the filesystem**
```cs
var path = "C://";
// Create a new VirtualFileSystem instance
var vfs = new VirtualFileSystem();
// Iterate over every single file in the directory, recursively
foreach (var file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
{
// Remove the actual root path part from the given path
var relative = file.Replace(path, "");
vfs.Add(file, relative);
}
```
**Get all the files in the VFS**
```cs
foreach (var file in vfs.GetAllEntries())
{
// Write out the path of every file
Console.WriteLine($"{file.Path}");
}
```
**Get all the files in a directory**
```cs
foreach (var file in vfs.GetEntriesInDirectory("\\SomeDirectory"))
{
Console.WriteLine($"{file.Name}");
}
```
**Read a file**
```cs
var byteArray = vfs.ReadFile("\\SomeDirectory\\SomeFile.txt");
var text = vfs.ReadFileAsString("\\SomeDirectory\\SomeFile.txt");
```