1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/common/serializer/buffered_file_reader.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/serializer/buffered_file_writer.hpp" |
12 | |
13 | namespace duckdb { |
14 | |
15 | class BufferedFileReader : public Deserializer { |
16 | public: |
17 | BufferedFileReader(FileSystem &fs, const char *path, optional_ptr<ClientContext> context, |
18 | FileLockType lock_type = FileLockType::READ_LOCK, optional_ptr<FileOpener> opener = nullptr); |
19 | |
20 | FileSystem &fs; |
21 | unsafe_unique_array<data_t> data; |
22 | idx_t offset; |
23 | idx_t read_data; |
24 | unique_ptr<FileHandle> handle; |
25 | |
26 | public: |
27 | void ReadData(data_ptr_t buffer, uint64_t read_size) override; |
28 | //! Returns true if the reader has finished reading the entire file |
29 | bool Finished(); |
30 | |
31 | idx_t FileSize() { |
32 | return file_size; |
33 | } |
34 | |
35 | void Seek(uint64_t location); |
36 | uint64_t CurrentOffset(); |
37 | |
38 | ClientContext &GetContext() override; |
39 | |
40 | optional_ptr<Catalog> GetCatalog() override; |
41 | void SetCatalog(Catalog &catalog); |
42 | |
43 | private: |
44 | idx_t file_size; |
45 | idx_t total_read; |
46 | optional_ptr<ClientContext> context; |
47 | optional_ptr<Catalog> catalog; |
48 | }; |
49 | |
50 | } // namespace duckdb |
51 |