![]() |
Bitcoin Core 30.99.0
P2P Digital Currency
|
Non-refcounted RAII wrapper for FILE*. More...
#include <streams.h>
Public Member Functions | |
AutoFile (std::FILE *file, const Obfuscation &obfuscation={}) | |
~AutoFile () | |
AutoFile (const AutoFile &)=delete | |
AutoFile & | operator= (const AutoFile &)=delete |
bool | feof () const |
int | fclose () |
std::FILE * | release () |
Get wrapped FILE* with transfer of ownership. More... | |
bool | IsNull () const |
Return true if the wrapped FILE* is nullptr, false otherwise. More... | |
void | SetObfuscation (const Obfuscation &obfuscation) |
Continue with a different XOR key. More... | |
std::size_t | detail_fread (std::span< std::byte > dst) |
Implementation detail, only used internally. More... | |
void | seek (int64_t offset, int origin) |
Wrapper around fseek(). More... | |
int64_t | tell () |
Find position within the file. More... | |
bool | Commit () |
Wrapper around FileCommit(). More... | |
bool | Truncate (unsigned size) |
Wrapper around TruncateFile(). More... | |
void | write_buffer (std::span< std::byte > src) |
Write a mutable buffer more efficiently than write(), obfuscating the buffer in-place. More... | |
void | read (std::span< std::byte > dst) |
void | ignore (size_t nSize) |
void | write (std::span< const std::byte > src) |
template<typename T > | |
AutoFile & | operator<< (const T &obj) |
template<typename T > | |
AutoFile & | operator>> (T &&obj) |
Protected Attributes | |
std::FILE * | m_file |
Obfuscation | m_obfuscation |
std::optional< int64_t > | m_position |
bool | m_was_written {false} |
Non-refcounted RAII wrapper for FILE*.
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).
fclose()
method, check if it returns an error and treat such an error as if the write()
method failed. The OS's fclose(3)
may fail to flush to disk data that has been previously written, rendering the file corrupt.
|
explicit |
|
inline |
|
delete |
bool AutoFile::Commit | ( | ) |
Wrapper around FileCommit().
Definition at line 115 of file streams.cpp.
std::size_t AutoFile::detail_fread | ( | std::span< std::byte > | dst | ) |
Implementation detail, only used internally.
Definition at line 21 of file streams.cpp.
|
inline |
|
inline |
void AutoFile::ignore | ( | size_t | nSize | ) |
Definition at line 67 of file streams.cpp.
|
inline |
void AutoFile::read | ( | std::span< std::byte > | dst | ) |
Definition at line 60 of file streams.cpp.
|
inline |
void AutoFile::seek | ( | int64_t | offset, |
int | origin | ||
) |
Wrapper around fseek().
Will throw if seeking is not possible.
Definition at line 33 of file streams.cpp.
|
inline |
int64_t AutoFile::tell | ( | ) |
Find position within the file.
Will throw if unknown.
Definition at line 54 of file streams.cpp.
bool AutoFile::Truncate | ( | unsigned | size | ) |
Wrapper around TruncateFile().
Definition at line 120 of file streams.cpp.
void AutoFile::write | ( | std::span< const std::byte > | src | ) |
Definition at line 81 of file streams.cpp.
void AutoFile::write_buffer | ( | std::span< std::byte > | src | ) |
Write a mutable buffer more efficiently than write(), obfuscating the buffer in-place.
Definition at line 101 of file streams.cpp.
|
protected |