Code Monkey home page Code Monkey logo

nano.vfs's Introduction

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");

nano.vfs's People

Contributors

purifetchi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.