tango.io.vfs.model.Vfs

License:
BSD style:

Version:
Jul 2007: Initial version

author:
Lars Ivar, Kris

alias VfsFilterInfo;
alias FileInfo for filtering

struct VfsStats;


abstract interface VfsHost: tango.io.vfs.model.Vfs.VfsFolder;


abstract VfsHost mount(VfsFolder folder, const(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).

abstract 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.

abstract VfsHost dismount(VfsFolder folder);
Unhook a child folder

abstract VfsHost map(VfsFile target, const(char)[] name);
Add a symbolic link to another file. These are referenced by file() alone, and do not show up in tree traversals

abstract VfsHost map(VfsFolderEntry target, const(char)[] name);
Add a symbolic link to another folder. These are referenced by folder() alone, and do not show up in tree traversals

abstract interface VfsFolder;
Supports a model a bit like CSS selectors, where a selection of operands is made before applying some operation. For example:
        // 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:
        // 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:
        // 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:
        // 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:
        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:
        root.folder("myNewFolder").create;

        root.folder("myExistingFolder").open;
File manipulation is handled in much the same way:
        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

abstract @property const(char)[] name();
Return a short name

abstract string toString();
Return a long name

abstract @property VfsFile file(const(char)[] path);
Return a contained file representation

abstract @property VfsFolderEntry folder(const(char)[] path);
Return a contained folder representation

abstract @property VfsFolders self();
Returns a folder set containing only this one. Statistics are inclusive of entries within this folder only

abstract @property VfsFolders tree();
Returns a subtree of folders. Statistics are inclusive of files within this folder and all others within the tree

abstract int opApply(scope int delegate(ref VfsFolder) dg);
Iterate over the set of immediate child folders. This is useful for reflecting the hierarchy

abstract VfsFolder clear();
Clear all content from this folder and subordinates

abstract @property bool writable();
Is folder writable?

abstract 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

abstract 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

abstract interface VfsFolders;
Operations upon a set of folders

abstract int opApply(scope int delegate(ref VfsFolder) dg);
Iterate over the set of contained VfsFolder instances

abstract @property size_t files();
Return the number of files

abstract @property size_t folders();
Return the number of folders

abstract @property size_t entries();
Return the total number of entries (files + folders)

abstract @property ulong bytes();
Return the total size of contained files

abstract VfsFolders subset(const(char)[] pattern);
Return a subset of folders matching the given pattern

abstract @property VfsFiles catalog(const(char)[] pattern);
Return a set of files matching the given pattern

abstract @property VfsFiles catalog(VfsFilter filter = null);
Return a set of files matching the given filter

abstract interface VfsFiles;
Operations upon a set of files

abstract int opApply(scope int delegate(ref VfsFile) dg);
Iterate over the set of contained VfsFile instances

abstract @property size_t files();
Return the total number of entries

abstract @property ulong bytes();
Return the total size of all files

abstract interface VfsFile;
A specific file representation

abstract @property const(char)[] name();
Return a short name

abstract immutable(char)[] toString();
Return a long name

abstract @property bool exists();
Does this file exist?

abstract @property ulong size();
Return the file size

abstract VfsFile copy(VfsFile source);
Create and copy the given source

abstract VfsFile move(VfsFile source);
Create and copy the given source, and remove the source

abstract VfsFile create();
Create a new file instance

abstract VfsFile create(InputStream stream);
Create a new file instance and populate with stream

abstract VfsFile remove();
Remove this file

abstract @property InputStream input();
Return the input stream. Don't forget to close it

abstract @property OutputStream output();
Return the output stream. Don't forget to close it

abstract @property VfsFile dup();
Duplicate this entry

abstract @property Time modified();
The modified time of the folder

abstract interface VfsFolderEntry;
Handler for folder operations. Needs some work ...

abstract VfsFolder open();
Open a folder

abstract VfsFolder create();
Create a new folder

abstract @property bool exists();
Test to see if a folder exists

abstract 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).

abstract VfsFolder sync();



Page generated by Ddoc. Copyright (c) 2007 Tango. All rights reserved