userver: fs::blocking::CFile Class Reference
Loading...
Searching...
No Matches
fs::blocking::CFile Class Referencefinal

#include <userver/fs/blocking/c_file.hpp>

Detailed Description

A std::FILE* wrapper.

The file is closed in the destructor

Note
The operations on the file are blocking and not thread-safe

Definition at line 24 of file c_file.hpp.

Public Member Functions

 CFile ()
 Creates an empty file handle.
 
 CFile (CFile &&) noexcept
 
CFileoperator= (CFile &&) noexcept
 
 CFile (const std::string &path, OpenMode flags, boost::filesystem::perms perms=boost::filesystem::perms::owner_read|boost::filesystem::perms::owner_write)
 Opens the file.
 
 CFile (std::FILE *file) noexcept
 Adopt the std::FILE* directly.
 
bool IsOpen () const
 Checks if the file is open.
 
std::FILE * GetNative () &
 Returns the underlying file handle.
 
std::FILE * Release () &&
 Passes the ownership of the file to the caller.
 
void Close () &&
 Closes the file manually.
 
std::size_t Read (char *buffer, std::size_t max_size)
 Reads data from the file.
 
void Write (std::string_view data)
 Writes data to the file.
 
void Flush ()
 Synchronizes the written data with the file on disk.
 
void FlushLight ()
 Synchronizes the written data with the file on disk without fsync.
 
std::uint64_t GetPosition () const
 Fetches the current position in the file.
 
std::uint64_t GetSize () const
 Fetches the file size.
 

Constructor & Destructor Documentation

◆ CFile()

fs::blocking::CFile::CFile ( const std::string & path,
OpenMode flags,
boost::filesystem::perms perms = boost::filesystem::perms::owner_read|boost::filesystem::perms::owner_write )

Opens the file.

Exceptions
std::runtime_error

Member Function Documentation

◆ Close()

void fs::blocking::CFile::Close ( ) &&

Closes the file manually.

Exceptions
std::runtime_error

◆ Flush()

void fs::blocking::CFile::Flush ( )

Synchronizes the written data with the file on disk.

Exceptions
std::runtime_error

◆ FlushLight()

void fs::blocking::CFile::FlushLight ( )

Synchronizes the written data with the file on disk without fsync.

Exceptions
std::runtime_error

◆ GetPosition()

std::uint64_t fs::blocking::CFile::GetPosition ( ) const

Fetches the current position in the file.

Exceptions
std::runtime_error

◆ GetSize()

std::uint64_t fs::blocking::CFile::GetSize ( ) const

Fetches the file size.

Exceptions
std::runtime_error

◆ Read()

std::size_t fs::blocking::CFile::Read ( char * buffer,
std::size_t max_size )

Reads data from the file.

Returns
The amount of bytes actually acquired, which can be equal to max_size, or less on end-of-file
Exceptions
std::runtime_error

◆ Write()

void fs::blocking::CFile::Write ( std::string_view data)

Writes data to the file.

Warning
Unless Flush is called, there is no guarantee the file on disk is actually updated
Exceptions
std::runtime_error

The documentation for this class was generated from the following file: