FileBase

A cross-platform wrapper around low-level file operations.

Constructors

this
this(const(char)[] name, FileFlags flags)

Opens or creates a file by name. By default, an existing file is opened in read-only mode.

this
this(Handle h)

Takes control of a file handle.

Destructor

~this
~this()

Closes the stream if it is open. Otherwise, it does nothing.

Postblit

this(this)
this(this)

Copying is disabled because references counting should be used instead.

Members

Aliases

Handle
alias Handle = int

Platform-specific file handle. On Posix systems, this is the file descriptor int. On Windows, this is a HANDLE.

Handle
alias Handle = HANDLE
Undocumented in source.
put
alias put = write
Undocumented in source.

Enums

LockType
enum LockType
Undocumented in source.

Functions

close
void close()

Closes the stream if it is open. Otherwise, it does nothing.

copyTo
size_t copyTo(File other, size_t n)

Copies the rest of this file to the other. The positions of both files are appropriately incremented, as if one called read()/write() to copy the file. The number of copied bytes is returned.

lock
void lock(LockType lockType, long start, long length)

Locks the specified file segment. If the file segment is already locked by another process, waits until the existing lock is released.

read
size_t read(ubyte[] buf)

Reads data from the file.

readv
size_t readv(ubyte[][] bufs)

Vectorized read.

seekTo
long seekTo(long offset, From from)

Seeks relative to a position.

sync
void sync()

Syncs all modified cached data of the file to disk. This includes data written to the file as well as meta data (e.g., last modified time, last access time).

tryLock
bool tryLock(LockType lockType, long start, long length)

Like lock, but returns false immediately if the lock is held by another process. Returns true if the specified region in the file was successfully locked.

unlock
void unlock(long start, long length)
Undocumented in source.
write
size_t write(ubyte[] data)

Writes data to the file.

writev
size_t writev(ubyte[][] bufs)

Vectorized write.

Properties

handle
Handle handle [@property getter]

Returns the internal file handle. On POSIX, this is a file descriptor. On Windows, this is an object handle.

isOpen
bool isOpen [@property getter]

Returns true if the file is open.

isTerminal
bool isTerminal [@property getter]

Checks if the file refers to a terminal.

length
long length [@property getter]

Gets the size of the file.

length
long length [@property setter]

Sets the length of the file. This can be used to truncate or extend the length of the file. If the file is extended, the new segment is not guaranteed to be initialized to zeros.

Static functions

dup
F dup(Handle h)

Duplicates the given platform-specific file handle. This is useful for taking non-exclusive control over a file handle.

Variables

InvalidHandle
enum Handle InvalidHandle;

Platform-specific file handle. On Posix systems, this is the file descriptor int. On Windows, this is a HANDLE.

InvalidHandle
enum Handle InvalidHandle;
Undocumented in source.
name
const(char)[] name;
Undocumented in source.

Meta