How to create virtual file and put content (a Stream) into it with Platform.VirtualFileSystem?

1.7k Views Asked by At

Firstly I don't completely have a clue if the so-called Platform.VirtualFileSystem can do this. What I want for a virtual file system is somehow create a virtual file from a Stream (that I've already had). The system (OS) will be able to access that virtual file as if it was a real file (transparently).

After browsing the classes hierarchy of the Platform.VirtualFileSystem, I could not completely find anything related to what I want. It looks just like that I can link an actual system file to the virtual file but here I don't even have the actual system file, what I have is just a Stream.

Does anyone have a simple example to illustrate this? As I said before, I did not even know if that library is what can help me. So if you have another alternative ones that could solve my problem, please suggest.

1

There are 1 best solutions below

6
On

I'll say that you are looking at the wrong tool. The Platform.VirtualFileSystem is an abstraction of various fs for the program that links to Platform.VirtualFileSystem,. It doesn't seem to export this abstraction to other programs.

What you need is a full file system. But note that a full file system is a full disk. You don't create a file, you create a virtual disk with a file. See for example dokan.

One of the things it can do is:

Data as file

Easily mount any kind of data as a virtual file and access it transparently from all your Windows applications. It can literally be anything: files from other locations, stored locally or remotely in the cloud... Creativity will be your limit.

Note that using Dokan seems to be quite complex. Normal persons don't go around writing file systems. For sure it is at least a little over my level. You can probably begin with the example read-only file system for the Registry and trim from there.