![]() |
Bitcoin Core 29.99.0
P2P Digital Currency
|
Non-refcounted RAII wrapper for FILE*. More...
#include <streams.h>
Public Member Functions | |
AutoFile (std::FILE *file, std::vector< std::byte > data_xor={}) | |
~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 | SetXor (std::vector< std::byte > data_xor) |
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 |
std::vector< std::byte > | m_xor |
std::optional< int64_t > | m_position |
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 file.fclose() instead of fclose(file).
|
explicit |
|
delete |
bool AutoFile::Commit | ( | ) |
Wrapper around FileCommit().
Definition at line 113 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 118 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 100 of file streams.cpp.