The VFS API hooks onto the fs API and allows "images" to be loaded into RAM and be treated as normal file systems. Any image that gets loaded will be given the "//" prefix instead of the normal "/" prefix. Example: If I loaded an image named "ext1", it will be accessible via "//ext1/".
Each image follows a certain format:
image = {
name = "name",
files = {
file = {
data = "",
isDir = bool,
isReadOnly = bool
}
}
}
name: The name of the image, ie. "ext1" in my example
files: A table of files.
Each file is a pair, the key is the relative name ("//ext1/directory/file" will be stored as "directory/file") and the value is table containing data associated with the file.
data: A string of hex (not pure ASCII) to preserve byte values due to LuaJ handling of strings
isDir: A boolean value representing if the file is a directory
isReadOnly: A boolean value representing if the file is readonly (most likely not)
Documentation:
Spoiler
Warning: This API modifies the functions of the fs API to allow virtual paths, so beware if you need to use the exact fs functionsIf you really do need the exact fs functions / having trouble using my modified ones, the original functions are avaliable at vfs.oldFS
vfs.mount( table image )
returns nil
Mounts image, allowing it to be accessed by the filesystem
vfs.unmount( string name )
returns nil
Unmounts a mounted image with the name of "name"
vfs.getMountedImage( string name )
returns table (image)
Returns a mounted image with the name of "name"
vfs.createImage( string name )
returns table (image)
Returns a blank image with the name of "name"
vfs.addFile( table image, string filePath )
returns nil
Opens the file at filePath and adds it to "image"
vfs.removeFile( table image, string path )
returns nil
Removes a file with the path of "path" from "image"
Doesn't error if the file doesn't exist
vfs.exportImage( string name )
returns table (image)
Returns an image with the name of "name" and has the contents of the entire HDD of the computer (excluding rom and any mounted images, but also includes any connected floppy disks (bug?))
vfs.importImage( table image, [ boolean append ] )
returns nil
Copies the contents of the image to the computer HDD, and if append is nil or false, it calls vfs.format()
vfs.format()
returns nil
Deletes all the contents of the HDD on the computer (including attached disks, is this a bug?)
vfs.isVirtual( string path )
returns boolean
Returns if the path is virtual
Other important variables:
vdrives: The global table that vfs uses to store mounted images
invalidNames: A list of names that vfs cannot use to retain compatibility with already-existing functions
oldFS: A table that contains the original (non-patched) fs functions
Link: http://pastebin.com/ZT1euz3x
Or alternatively (preferred):
pastebin get ZT1euz3x vfs
Please tell me any bugs or suggestions, as I have vigorously bugtested this myself but I cannot find all of the bugs in every scenario!