VFSFile

A file in the VFS.

Provides basic file information and access to I/O.

File names in the VFS can contain any characters except /, which is used as directory separator, and the :: sequence, which is used for explicit package lookup (see StackDir).

Constructors

this
this(VFSDir parent, string pathInParent)

Constructor to initialize state common for VFSFile implementations.

this
this(string absolutePath)

Constructor to initialize a VFSFile without a parent.

Members

Enums

Mode
enum Mode

File mode (used by implementations);

Functions

close
void close()

Close the file, finalizing any file operations.

openRead
void openRead()

Open the file for reading.

openWrite
void openWrite(Flag!"append" append)

Open the file for writing/appending.

read
void[] read(void[] target)

Read up to target.length bytes to target from current file position.

seek
void seek(long offset, Seek origin)

Seek offset bytes from origin within the file.

write
void write(in void[] data)

Write data.length bytes to file from current file position.

Properties

bytes
ulong bytes [@property getter]

Get file size in bytes.

exists
bool exists [@property getter]

Does the file exist?

input
VFSFileInput input [@property getter]

Open the file and get reading access.

name
string name [@property getter]

Get name of the file.

open
bool open [@property getter]

Is the file open?

output
Flag!"append" output [@property setter]

Open the file and get writing access. Must not already be open.

path
string path [@property getter]

Get full path of the file in the VFS.

writable
bool writable [@property getter]

Is it possible to write to this file?

Static functions

closeProxy
void closeProxy(VFSFile file)

Proxies to for derived VFSFiles to call protected members of other VFSFiles.

openReadProxy
void openReadProxy(VFSFile file)
openWriteProxy
void openWriteProxy(VFSFile file, Flag!"append" append)
readProxy
void[] readProxy(VFSFile file, void[] target)
seekProxy
void seekProxy(VFSFile file, long offset, Seek origin)
writeProxy
void writeProxy(VFSFile file, const void[] data)

Proxies to for derived VFSFiles to call protected members of other VFSFiles.

Examples

1 VFSDir dir = new FSDir("main", "./user_data/main", Yes.writable);
2 
3 //Get the file from a directory.
4 VFSFile file = dir.file("logs/memory.log");
5 
6 //Print information about the file (note that we can only get file size of an existing file):
7 writeln("name: ", file.name, ", full path: ", file.path,
8        ", writable: ", file.writable, ", exists: ", file.exists,
9        ", size in bytes: ", file.bytes);
10 
11 //Get access to read from the file:
12 auto input = file.input;
13 
14 //Simply read the file to a buffer:
15 auto buffer = new ubyte[file.bytes];
16 file.input.read(buffer);
17 
18 //Get access to write to the file:
19 auto output = file.output;
20 
21 //Simply write a buffer to the file:
22 file.output.write(cast(const void[])"The answer is 42");

Meta