- alias File = T.FileImpl;
- Alias to allow for easy referencing the proper archive File member type for Policy.
- alias Directory = T.DirectoryImpl;
- Alias to allow for easy referencing the proper archive Directory member type for Policy.
- alias Properties = T.Properties;
- (Optional) Alias to allow for easy referencing the proper archive Properties type for Policy.
e.g. Tar archives do not have any archive-wide properties, while zip files have an archive comment.
- this(void[] data);
- Constructor for archives which initializes the archive with the contents of the serialized archive
stored in data.
Params:
void[] data |
serialized data of an archive in the proper format for the Policy. |
- this();
- Constructor for read/write archives which does not require serialized data to create.
- @property int delegate(int delegate(ref File)) files();
- Provides access to all files in the archive via a delegate method. This allows use in foreach loops.
Example:
foreach(file; archive.files)
{
// Use properties of file
}
- @property int delegate(int delegate(ref Directory)) directories();
- Provides access to all directories in the archive via a delegate method. This allows use in foreach loops.
Example:
foreach(dir; archive.directories)
{
// Use properties of dir
}
- @property int delegate(int delegate(ref ArchiveMember)) members();
- Provides access to all files and directories in the archive via a delegate method. This allows use in foreach loops.
Example:
foreach(member; archive.members)
{
if(member.isFile())
{
auto file = cast(archive.File)member;
// Use properties of file
}
else
{
auto dir = cast(archive.Directory)member;
// Use properties of dir
}
}
- File getFile(string path);
- Returns:
The file associated with the given path variable, or null if no such file exists in the archive.
- Directory getDirectory(string path);
- Returns:
The directory associated with the given path variable, the root for "/", or null if no such directory exists.
- size_t numFiles(size_t n = size_t.max);
- Returns:
the number of files in the archive which are up to n levels deep (inclusive).
- size_t numDirectories(size_t n = size_t.max);
- Returns:
The number of directories in the archive which are up to n levels deep (inclusive).
- size_t numMembers(size_t n = size_t.max);
- Returns:
The number of directories and files in the archive which are up to n levels deep (inclusive).
- void[] serialize();
- Serializes the archive.
Returns:
the archive in a void[] array which can be saved to a file, sent over a network connection, etc.
- void addFile(File member);
- Adds a file to the archive. If the path to the file contains directories that are not in the archive, they are added.
Throws:
IllegalPathException when an element in the given path is already used for a file/directory or the path is otherwise invalid.
Example:
// inserts apple.txt into the archive.
archive.addFile(new archive.File("apple.txt"));
// inserts directory animals (if not exists) and dogs.txt into the archive.
archive.addFile(new archive.File("animals/dogs.txt"));
- Directory addDirectory(string path);
- Adds a directory to the archive. If the path to the directory contains directories that are not in the archive, they are added.
If the directory already exists it is not replaced with an empty directory.
Returns:
the final Directory in the path. (e.g. "dlang" for "languages/dlang/")
Throws:
IllegalPathException when an element in the given path is already used for a file or the path is otherwise invalid.
Example:
// inserts animals/birds/ into the archive.
archive.addDirectory("animals/");
// inserts directory languages (if not exists) and dlang into the archive.
archive.addDirectory("languages/dlang/");
- bool removeFile(string path);
- Removes a file from the archive.
Returns:
true if the file was removed, false if it did not exist.
- bool removeDirectory(string path);
- Removes a directory (and all contained files and directories) from the archive.
Returns:
true if the directory was removed, false if it did not exist.
- void removeEmptyDirectories();
- Removes all directories in the archive with no direct files or files in subdirectories.
- Properties properties;
- (Optional) Archive-wide properties for the format associated with Policy.
e.g. Tar archives do not have any archive-wide properties, while zip files have an archive comment.
- Directory root;
- The root directory of the archive. Public here to allow for manual recursive algorithms.