1 | #pragma once |
2 | |
3 | #include "CompressedReadBufferBase.h" |
4 | #include <IO/ReadBufferFromFileBase.h> |
5 | #include <time.h> |
6 | #include <memory> |
7 | #include <port/clock.h> |
8 | |
9 | |
10 | namespace DB |
11 | { |
12 | |
13 | |
14 | /// Unlike CompressedReadBuffer, it can do seek. |
15 | class CompressedReadBufferFromFile : public CompressedReadBufferBase, public BufferWithOwnMemory<ReadBuffer> |
16 | { |
17 | private: |
18 | /** At any time, one of two things is true: |
19 | * a) size_compressed = 0 |
20 | * b) |
21 | * - `working_buffer` contains the entire block. |
22 | * - `file_in` points to the end of this block. |
23 | * - `size_compressed` contains the compressed size of this block. |
24 | */ |
25 | std::unique_ptr<ReadBufferFromFileBase> p_file_in; |
26 | ReadBufferFromFileBase & file_in; |
27 | size_t size_compressed = 0; |
28 | |
29 | bool nextImpl() override; |
30 | |
31 | public: |
32 | CompressedReadBufferFromFile( |
33 | const std::string & path, size_t estimated_size, size_t aio_threshold, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE); |
34 | |
35 | void seek(size_t offset_in_compressed_file, size_t offset_in_decompressed_block); |
36 | |
37 | size_t readBig(char * to, size_t n) override; |
38 | |
39 | void setProfileCallback(const ReadBufferFromFileBase::ProfileCallback & profile_callback_, clockid_t clock_type_ = CLOCK_MONOTONIC_COARSE) |
40 | { |
41 | file_in.setProfileCallback(profile_callback_, clock_type_); |
42 | } |
43 | }; |
44 | |
45 | } |
46 | |