[#AutoFile]
= AutoFile
:mrdocs:

Non&hyphen;refcounted RAII wrapper for FILE&ast;

== Synopsis

Declared in `&lt;streams&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class AutoFile;
----

== Description

Will automatically close the file when it goes out of scope if not null&period; If you&apos;re returning the file pointer, return file&period;release()&period; If you need to close the file early, use autofile&period;fclose() instead of fclose(underlying&lowbar;FILE)&period;

[NOTE]
====
If the file has been written to, then the caller must close it explicitly with the `fclose()` method, check if it returns an error and treat such an error as if the `write()` method failed&period; The OS&apos;s `fclose(3)` may fail to flush to disk data that has been previously written, rendering the file corrupt&period;

====

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:AutoFile/2constructor-0e.adoc[`AutoFile`]         [.small]#[constructor]#
| Constructors
| xref:AutoFile/2destructor.adoc[`&#126;AutoFile`] [.small]#[destructor]#
| Close the wrapped file if still open, logging any close error&period;
| xref:AutoFile/operator_assign.adoc[`operator&equals;`]  [.small]#[deleted]#
| Deleted copy assignment&semi; AutoFile is non&hyphen;copyable&period;
| xref:AutoFile/Commit.adoc[`Commit`] 
| Wrapper around FileCommit()&period;
| xref:AutoFile/IsNull.adoc[`IsNull`] 
| Return true if the wrapped FILE&ast; is nullptr, false otherwise&period;
| xref:AutoFile/SetObfuscation.adoc[`SetObfuscation`] 
| Continue with a different XOR key
| xref:AutoFile/Truncate.adoc[`Truncate`] 
| Wrapper around TruncateFile()&period;
| xref:AutoFile/detail_fread.adoc[`detail&lowbar;fread`] 
| Implementation detail, only used internally&period;
| xref:AutoFile/fclose.adoc[`fclose`] 
| Close the wrapped file early and return the C `fclose` result&period;
| xref:AutoFile/feof.adoc[`feof`] 
| Return true if the end&hyphen;of&hyphen;file indicator is set on the wrapped file&period;
| xref:AutoFile/ignore.adoc[`ignore`] 
| Skip `nSize` bytes from the file&period;
| xref:AutoFile/operator_rshift.adoc[`operator&gt;&gt;`] 
| Deserialize an object from the file and return this wrapper&period;
| xref:AutoFile/read.adoc[`read`] 
| Read raw bytes from the file into `dst`, applying deobfuscation&period;
| xref:AutoFile/release.adoc[`release`] 
| Get wrapped FILE&ast; with transfer of ownership&period;
| xref:AutoFile/seek.adoc[`seek`] 
| Wrapper around fseek()&period; Will throw if seeking is not possible&period;
| xref:AutoFile/size.adoc[`size`] 
| Return the size of the file&period; Will throw if unknown&period;
| xref:AutoFile/tell.adoc[`tell`] 
| Find position within the file&period; Will throw if unknown&period;
| xref:AutoFile/write.adoc[`write`] 
| Write raw bytes from `src` to the file, applying obfuscation&period;
| xref:AutoFile/write_buffer.adoc[`write&lowbar;buffer`] 
| Write a mutable buffer more efficiently than write(), obfuscating the buffer in&hyphen;place&period;
| xref:AutoFile/operator_lshift.adoc[`operator&lt;&lt;`] 
| Serialize an object to the file and return this wrapper&period;
|===


== Protected Data Members

[cols="1,4"]
|===
| Name| Description
| xref:AutoFile/m_file.adoc[`m&lowbar;file`] 
| Wrapped C file handle, or nullptr once released or closed&period;
| xref:AutoFile/m_obfuscation.adoc[`m&lowbar;obfuscation`] 
| XOR key applied to data as it is read or written&period;
| xref:AutoFile/m_position.adoc[`m&lowbar;position`] 
| Cached current file position, if known&period;
| xref:AutoFile/m_was_written.adoc[`m&lowbar;was&lowbar;written`] 
| True once any data has been written through this wrapper&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
