IFile
Description
- Derived from
-
IDisposableGeneric<IFile>
IFileOps
IFlushable
ICanReadWrite
IPathInfo - Extended by
-
FileBase abstract
Base interface for classes that represent persistent binary objects (i.e. files) with random-access semantics.
Public / Methods
Commit
Commits all pending file modifications as an atomic update if CanCommit returns true
or returns silently without performing any action otherwise.
A file may support a mechanism for ensuring file integrity, where file modifications are performed as usual and additional calls to Commit are made to group these modifications into a sequence of atomic updates:
Creation Modifications >__________M___M_________M___M_____M_M M_M___M__M__M__ C C C C Commits [--U--] [--U--] [---U---] [---U---] Atomic updates
Atomic updates are performed sequentially and each atomic update is either applied fully or not at all. In the case that a file cannot be closed properly (for example, the application crashes or the system malfunctions), all atomic updates that have not been included in a prior flush may be lost.
file.Flush(); // #1 ... file.Commit(true); // #2 ... file.Commit(false); // #3
Calling IFlushable.Flush (see #1) will implicitly call Commit with flush
set to true
and is thus equivalent to calling only Commit with flush (see #2). Committing without flush (see #3) is more efficient, but the atomic updates can still be lost (but not corrupted) if a subsequent flush fails.
- IOException
-
If an I/O error has occurred.
- See also
GetTimestamp
Returns the timestamp of the last file modification.
If SetTimestamp has been called, this method will return the provided timestamp value. Otherwise, the method will fetch the timestamp from the underlying filesystem each time is it called.
- IOException
-
If an I/O error has occurred.
Read
Reads a chunk of bytes from the file.
The actual number of read bytes may be lower than count opt when reading over the end of the file. The maximum number of bytes that can be read with a single call is 2^31-1
.
- IOException
-
If an I/O error has occurred.
ReadAll
Reads a chunk of bytes from the file.
The maximum number of bytes that can be read with a single call is 2^31-1
.
- IOException
-
If an I/O error has occurred.
SetLength
Sets the length of this file.
Setting the length of a file may cause additional management overhead by the OS and should only be done when absolutely necessary.
- IOException
-
If an I/O error has occurred.
SetTimestamp
Sets the timestamp of the last file modification.
Once called, the GetTimestamp will return timestamp in. The new timestamp may not become apparent to the underlying filesystem immediately, but it will when this file is disposed, at the latest.
- IOException
-
If an I/O error has occurred.
Write
Writes a chunk of bytes to the file.
The maximum number of bytes that can be written with a single call is 2^31-1
. Writing past the end of the file will cause it to grow automatically.
- IOException
-
If an I/O error has occurred.