|
MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
|
A utility class for reading files in an efficient manner. 更多...
#include <ob_file_reader.h>
Public 成员函数 | |
| ObFileReader (const string &filename) | |
Constructs an ObFileReader object with the specified file name. 更多... | |
| RC | open_file () |
| Opens the file for reading. 更多... | |
| void | close_file () |
| Closes the file if it is currently open. 更多... | |
| string | read_pos (uint32_t pos, uint32_t size) |
| Reads a portion of the file from a specified position. 更多... | |
| uint32_t | file_size () |
| Returns the size of the file. 更多... | |
静态 Public 成员函数 | |
| static unique_ptr< ObFileReader > | create_file_reader (const string &filename) |
Creates a new ObFileReader instance. 更多... | |
Private 属性 | |
| string | filename_ |
| The name of the file to be read. 更多... | |
| int | fd_ = -1 |
| The file descriptor for the currently opened file. 更多... | |
A utility class for reading files in an efficient manner.
The ObFileReader class provides a simple interface for reading files. It allows opening, closing, and reading specific portions of a file while also exposing the file size for external use. This class is intended for use in scenarios where file-based data storage, such as SSTables, is accessed.
|
inline |
Constructs an ObFileReader object with the specified file name.
The file name is stored internally, but the file is not opened until open_file() is explicitly called.
| filename | The name of the file to be read. |
| void oceanbase::ObFileReader::close_file | ( | ) |
Closes the file if it is currently open.
This method releases the file descriptor (fd_) associated with the file.
|
static |
Creates a new ObFileReader instance.
This static factory method constructs a new ObFileReader object and initializes it with the specified file name.
| filename | The name of the file to be read. |
unique_ptr to the created ObFileReader object. | uint32_t oceanbase::ObFileReader::file_size | ( | ) |
Returns the size of the file.
This method retrieves the size of the file in bytes. It relies on the file being successfully opened.
| RC oceanbase::ObFileReader::open_file | ( | ) |
Opens the file for reading.
This method attempts to open the file specified during the construction of the object. If the file is successfully opened, the internal file descriptor (fd_) is updated.
| string oceanbase::ObFileReader::read_pos | ( | uint32_t | pos, |
| uint32_t | size | ||
| ) |
Reads a portion of the file from a specified position.
This method reads size bytes starting from position pos in the file.
| pos | The starting position (offset) in the file. |
| size | The number of bytes to read. |
|
private |
The file descriptor for the currently opened file.
This integer represents the file descriptor used for reading the file. If no file is open, it is set to -1.
|
private |
The name of the file to be read.
This string stores the file name specified during the construction of the ObFileReader object.