我在做一个节目。我不认为我需要在这里展示它,但我想知道是否有可能创建存储在单个文件中的虚拟文件系统。例如,我有一个名为my_file_system.fs
的文件,有没有办法只将虚拟文件系统创建到单个文件中。基本上:
/home/xcodz/
|
+--myfilesystem.fs
|
+--testdir
+--test.txt
+--downloads
|
+--example1.txt
我基本上想要基本的文件系统接口。没有所有者、日期或其他元数据。Zip是一个好主意,但它只是一次读取系统中的整个文件,不提供类似文件的接口。因此,我需要一个非常基本的单文件文件文件系统,在这个系统中,我可以像普通IO对象一样使用文件
编辑 存储在文件系统中的文件对于单个文件将有3GB的大小,而我没有那么多的ram。TarFiles似乎并没有让我的工作变得更好
编辑 我的意思是说一些文件系统,就像有虚拟盒的文件系统一样
您可以使用SVFS包
解决方案#1-TAR文件
TAR文件基本上是单个文件中的unix文件系统。您可以使用tarfile在python中使用它们
优点:
缺点:
解决方案#2-环回文件系统
如果为了运行您的程序,您可以要求完成装载,您可以use a loopback filesystem:
优点:
缺点:
解决方案#3-DYI文件系统
因为您最关心文件I/O,所以可以使用BytesIO实现它。要支持文件系统层次结构中的多个文件,可以将这些文件放在trie中。您需要序列化和反序列化所有这些,您可以使用pickle
优点:
缺点:
选择什么
因为您的需求非常基本,所以选择1-TAR文件
相关问题 更多 >
编程相关推荐