#include <userver/fs/blocking/file_descriptor.hpp>
A file descriptor wrapper.
The file is closed in the destructor
- Note
- The operations on the file are blocking and not thread-safe
Definition at line 22 of file file_descriptor.hpp.
|
|
| FileDescriptor (FileDescriptor &&other) noexcept |
| |
|
FileDescriptor & | operator= (FileDescriptor &&other) noexcept |
| |
| bool | IsOpen () const |
| | Checks if the file is open.
|
| |
| void | Close () && |
| | Closes the file manually.
|
| |
|
int | GetNative () const |
| | Returns the native file handle.
|
| |
|
int | Release () && |
| | Passes the ownership of the file descriptor to the caller.
|
| |
| void | Write (std::string_view contents) |
| | Writes data to the file.
|
| |
| std::size_t | Read (char *buffer, std::size_t max_size) |
| | Reads data from the file at current offset.
|
| |
| void | Seek (std::size_t offset_in_bytes) |
| | Sets the file read/write offset from the beginning of the file.
|
| |
| void | FSync () |
| | Makes sure the written data is actually stored on disk.
|
| |
| std::size_t | GetSize () const |
| | Fetches the file size.
|
| |
|
| static FileDescriptor | Open (const std::string &path, OpenMode flags, boost::filesystem::perms perms=boost::filesystem::perms::owner_read|boost::filesystem::perms::owner_write) |
| | Open a file using ::open.
|
| |
| static FileDescriptor | OpenDirectory (const std::string &path) |
| | Open a directory node.
|
| |
|
static FileDescriptor | AdoptFd (int fd) noexcept |
| | Use the file descriptor directly.
|
| |
◆ Close()
| void fs::blocking::FileDescriptor::Close |
( |
| ) |
&& |
Closes the file manually.
- Exceptions
-
◆ FSync()
| void fs::blocking::FileDescriptor::FSync |
( |
| ) |
|
Makes sure the written data is actually stored on disk.
- Exceptions
-
◆ GetSize()
| std::size_t fs::blocking::FileDescriptor::GetSize |
( |
| ) |
const |
Fetches the file size.
- Exceptions
-
◆ IsOpen()
| bool fs::blocking::FileDescriptor::IsOpen |
( |
| ) |
const |
Checks if the file is open.
- Note
- Operations can only be performed on an open
FileDescriptor.
◆ Open()
| static FileDescriptor fs::blocking::FileDescriptor::Open |
( |
const std::string & | path, |
|
|
OpenMode | flags, |
|
|
boost::filesystem::perms | perms = boost::filesystem::perms::owner_read|boost::filesystem::perms::owner_write ) |
|
static |
Open a file using ::open.
- Exceptions
-
◆ OpenDirectory()
| static FileDescriptor fs::blocking::FileDescriptor::OpenDirectory |
( |
const std::string & | path | ) |
|
|
static |
Open a directory node.
- Note
- The only valid operation for such a
FileDescriptor is FSync.
- Exceptions
-
◆ Read()
| std::size_t fs::blocking::FileDescriptor::Read |
( |
char * | buffer, |
|
|
std::size_t | max_size ) |
Reads data from the file at current offset.
- Returns
- The amount of bytes actually acquired, which can be equal to
max_size, or less on end-of-file
- Exceptions
-
◆ Seek()
| void fs::blocking::FileDescriptor::Seek |
( |
std::size_t | offset_in_bytes | ) |
|
Sets the file read/write offset from the beginning of the file.
- Exceptions
-
◆ Write()
| void fs::blocking::FileDescriptor::Write |
( |
std::string_view | contents | ) |
|
Writes data to the file.
- Warning
- Unless
FSync is called, there is no guarantee the data is stored on disk safely.
- Exceptions
-
◆ TempFile
The documentation for this class was generated from the following file: