MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
ob_file_reader.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11#pragma once
12
13#include "common/lang/fstream.h"
14#include "common/lang/memory.h"
15#include "common/lang/sstream.h"
16#include "common/lang/string.h"
17#include "common/sys/rc.h"
18#include "common/lang/mutex.h"
19
20namespace oceanbase {
21
32{
33public:
42 ObFileReader(const string &filename) : filename_(filename) {}
43
45
55 RC open_file();
56
62 void close_file();
63
73 string read_pos(uint32_t pos, uint32_t size);
74
83 uint32_t file_size();
84
94 static unique_ptr<ObFileReader> create_file_reader(const string &filename);
95
96private:
103 string filename_;
104
111 int fd_ = -1;
112};
113
114} // namespace oceanbase
A utility class for reading files in an efficient manner.
Definition: ob_file_reader.h:32
string read_pos(uint32_t pos, uint32_t size)
Reads a portion of the file from a specified position.
Definition: ob_file_reader.cpp:22
static unique_ptr< ObFileReader > create_file_reader(const string &filename)
Creates a new ObFileReader instance.
Definition: ob_file_reader.cpp:40
ObFileReader(const string &filename)
Constructs an ObFileReader object with the specified file name.
Definition: ob_file_reader.h:42
uint32_t file_size()
Returns the size of the file.
Definition: ob_file_reader.cpp:35
int fd_
The file descriptor for the currently opened file.
Definition: ob_file_reader.h:111
void close_file()
Closes the file if it is currently open.
Definition: ob_file_reader.cpp:61
string filename_
The name of the file to be read.
Definition: ob_file_reader.h:103
RC open_file()
Opens the file for reading.
Definition: ob_file_reader.cpp:50