Skip to content

naomiEve/Nano.VFS

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

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

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

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

foreach (var file in vfs.GetAllEntries())
{
	// Write out the path of every file
	Console.WriteLine($"{file.Path}");
}

Get all the files in a directory

foreach (var file in vfs.GetEntriesInDirectory("\\SomeDirectory"))
{
	Console.WriteLine($"{file.Name}");
}

Read a file

var byteArray = vfs.ReadFile("\\SomeDirectory\\SomeFile.txt");
var text = vfs.ReadFileAsString("\\SomeDirectory\\SomeFile.txt");

About

Simple modular in-memory virtual file system.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages