tango.io.vfs.model.Vfs

License:

BSD style: see license.txt

Version:

Jul 2007: Initial version

Author:

Lars Ivar, Kris
alias FileInfo VfsFilterInfo #
alias FileInfo for filtering.
struct VfsStats #
ulong bytes #
Byte count of files.
uint files #
Number of files.
uint folders #
Number of folders.
interface VfsHost : VfsFolder #
VfsHost mount(VfsFolder folder, char[] name = null) #
Add a child folder. The child cannot 'overlap' with others in the tree of the same type. Circular references across a tree of virtual folders are detected and trapped.
The second argument represents an optional name that the mount should be known as, instead of the name exposed by the provided folder (it is not an alias.)
VfsHost mount(VfsFolders group) #
Add a set of child folders. The children cannot 'overlap' with others in the tree of the same type. Circular references are detected and trapped.
VfsHost dismount(VfsFolder folder) #
Unhook a child folder.
VfsHost map(VfsFile target, char[] name) #
Add a symbolic link to another file. These are referenced by file() alone, and do not show up in tree traversals.
VfsHost map(VfsFolderEntry target, char[] name) #
Add a symbolic link to another folder. These are referenced by folder() alone, and do not show up in tree traversals.
interface VfsFolder #
Supports a model a bit like CSS selectors, where a selection of operands is made before applying some operation. For example:
1
2
3
4
5
6
7
8
// count of files in this folder
auto count = folder.self.files;

// accumulated file byte-count
auto bytes = folder.self.bytes;

// a group of one folder (itself)
auto folders = folder.self;
The same approach is used to select the subtree descending from a folder:
1
2
3
4
5
6
7
8
// count of files in this tree
auto count = folder.tree.files;

// accumulated file byte-count
auto bytes = folder.tree.bytes;

// the group of child folders
auto folders = folder.tree;

Filtering can be applied to the tree resulting in a sub-group. Group operations remain applicable. Note that various wildcard characters may be used in the filtering:

1
2
3
4
5
// select a subset of the resultant tree
auto folders = folder.tree.subset("install");

// get total file bytes for a tree subset, using wildcards
auto bytes = folder.tree.subset("foo*").bytes;

Files are selected from a set of folders in a similar manner:

1
2
3
4
5
6
7
8
9
10
11
// files called "readme.txt" in this folder
auto count = folder.self.catalog("readme.txt").files;

// files called "read*.*" in this tree
auto count = folder.tree.catalog("read*.*").files;

// all txt files belonging to folders starting with "ins"
auto count = folder.tree.subset("ins*").catalog("*.txt").files;

// custom-filtered files within a subtree
auto count = folder.tree.catalog(&filter).files;

Sets of folders and files support iteration via foreach:

1
2
3
4
5
6
7
8
foreach (folder; root.tree)
         Stdout.formatln ("folder name:{}", folder.name);

foreach (folder; root.tree.subset("ins*"))
         Stdout.formatln ("folder name:{}", folder.name);

foreach (file; root.tree.catalog("*.d"))
         Stdout.formatln ("file name:{}", file.name);

Creating and opening a sub-folder is supported in a similar manner, where the single instance is 'selected' before the operation is applied. Open differs from create in that the folder must exist for the former:

1
2
3
root.folder("myNewFolder").create;

root.folder("myExistingFolder").open;

File manipulation is handled in much the same way:

1
2
3
4
root.file("myNewFile").create;

auto source = root.file("myExistingFile");
root.file("myCopiedFile").copy(source);

The principal benefits of these approaches are twofold: 1) it turns out to be notably more efficient in terms of traversal, and 2) there's no casting required, since there is a clean separation between files and folders.

See VfsFile for more information on file handling.

char[] name() #
Return a short name.
char[] toString() #
Return a long name.
VfsFile file(char[] path) #
Return a contained file representation.
VfsFolderEntry folder(char[] path) #
Return a contained folder representation.
VfsFolders self() #
Returns a folder set containing only this one. Statistics are inclusive of entries within this folder only.
VfsFolders tree() #
Returns a subtree of folders. Statistics are inclusive of files within this folder and all others within the tree.
int opApply(int delegate(ref VfsFolder) dg) #
Iterate over the set of immediate child folders. This is useful for reflecting the hierarchy.
VfsFolder clear() #
Clear all content from this folder and subordinates.
bool writable() #
Is folder writable?
VfsFolder close(bool commit = true) #
Close and/or synchronize changes made to this folder. Each driver should take advantage of this as appropriate, perhaps combining multiple files together, or possibly copying to a remote location.
void verify(VfsFolder folder, bool mounting) #
A folder is being added or removed from the hierarchy. Use this to test for validity (or whatever) and throw exceptions as necessary.
interface VfsFolders #
Operations upon a set of folders.
int opApply(int delegate(ref VfsFolder) dg) #
Iterate over the set of contained VfsFolder instances.
uint files() #
Return the number of files.
uint folders() #
Return the number of folders.
uint entries() #
Return the total number of entries (files + folders.)
ulong bytes() #
Return the total size of contained files.
VfsFolders subset(char[] pattern) #
Return a subset of folders matching the given pattern.
VfsFiles catalog(char[] pattern) #
Return a set of files matching the given pattern.
VfsFiles catalog(VfsFilter filter = null) #
Return a set of files matching the given filter.
interface VfsFiles #
Operations upon a set of files.
int opApply(int delegate(ref VfsFile) dg) #
Iterate over the set of contained VfsFile instances.
uint files() #
Return the total number of entries.
ulong bytes() #
Return the total size of all files.
interface VfsFile #
A specific file representation.
char[] name() #
Return a short name.
char[] toString() #
Return a long name.
bool exists() #
Does this file exist?
ulong size() #
Return the file size.
VfsFile copy(VfsFile source) #
Create and copy the given source.
VfsFile move(VfsFile source) #
Create and copy the given source, and remove the source.
VfsFile create() #
Create a new file instance.
VfsFile create(InputStream stream) #
Create a new file instance and populate with stream.
VfsFile remove() #
Remove this file.
InputStream input() #
Return the input stream. Don't forget to close it.
OutputStream output() #
Return the output stream. Don't forget to close it.
VfsFile dup() #
Duplicate this entry.
Time modified() #
The modified time of the folder.
interface VfsFolderEntry #
Handler for folder operations. Needs some work ...
VfsFolder open() #
Open a folder.
VfsFolder create() #
Create a new folder.
bool exists() #
Test to see if a folder exists.
interface VfsSync #
Would be used for things like zip files, where the implementation mantains the contents in memory or on disk, and where the actual zip file isn't/shouldn't be written until one is finished filling it up (for zip due to inefficient file format).
VfsFolder sync() #