Non‐refcounted RAII wrapper for FILE*
Synopsis
Declared in <streams.h>
class AutoFile;
Description
Will automatically close the file when it goes out of scope if not null. If you're returning the file pointer, return file.release(). If you need to close the file early, use autofile.fclose() instead of fclose(underlying_FILE).
|
Note
|
If the file has been written to, then the caller must close it explicitly with the |
Member Functions
Name |
Description |
|
Constructors |
|
Close the wrapped file if still open, logging any close error. |
|
Deleted copy assignment; AutoFile is non‐copyable. |
Wrapper around FileCommit(). |
|
Return true if the wrapped FILE* is nullptr, false otherwise. |
|
Continue with a different XOR key |
|
Wrapper around TruncateFile(). |
|
Implementation detail, only used internally. |
|
Close the wrapped file early and return the C |
|
Return true if the end‐of‐file indicator is set on the wrapped file. |
|
Skip |
|
Deserialize an object from the file and return this wrapper. |
|
Read raw bytes from the file into |
|
Get wrapped FILE* with transfer of ownership. |
|
Wrapper around fseek(). Will throw if seeking is not possible. |
|
Return the size of the file. Will throw if unknown. |
|
Find position within the file. Will throw if unknown. |
|
Write raw bytes from |
|
Write a mutable buffer more efficiently than write(), obfuscating the buffer in‐place. |
|
Serialize an object to the file and return this wrapper. |
Protected Data Members
Name |
Description |
Wrapped C file handle, or nullptr once released or closed. |
|
XOR key applied to data as it is read or written. |
|
Cached current file position, if known. |
|
True once any data has been written through this wrapper. |
Created with MrDocs