Search code examples
pythonpython-3.xfilesystemsvirtualsingle-file

Is there a library in Python which allows virtual file system management in single file?


I was working on a program. I do not think I need to show it here, but I was wondering is it possible to create virtual file system stored on a single file. for example I have a file named my_file_system.fs, is there a way to create virtual file system into that single file only. Basically:

/home/xcodz/
    |
    +--myfilesystem.fs
       |
       +--testdir
       +--test.txt
       +--downloads
          |
          +--example1.txt

I basically want basic filesystem interface. no owners, date or other metadata. Zip is a good idea to do that but it just reads the whole file in the system all at once and does not provide file like interface. So I rquired a very basic file system in single file, in which i am able to use files like normal IO objects.

EDIT The files stored in the file system will be as big as 3 GB for a single file, and I do not have that much of a ram. TarFiles doesn't seem to make my work any better

EDIT I really mean to say some filesystem just like the one with virtual box.


Solution

  • You can use SVFS package.

    SVFS allows to create virtual filesystem inside file on real filesystem. It can be used to store multiple files inside single file (with directory structure). Unlike archives, SVFS allows to modify files in-place. SVFS files use file-like interface, so they can be used (pretty much) like regular Python file objects. Finally, it’s implemented in pure python and doesn’t use any 3rd party modules, so it should be very portable. Tests show write speed to be around 10-12 MB/s and read speed to be around 26-28 MB/s.