1 | #pragma once |
---|---|
2 | |
3 | #include <memory> |
4 | |
5 | #include <Common/PODArray.h> |
6 | |
7 | #include <IO/WriteBuffer.h> |
8 | #include <IO/BufferWithOwnMemory.h> |
9 | #include <Compression/ICompressionCodec.h> |
10 | #include <Compression/CompressionFactory.h> |
11 | |
12 | |
13 | namespace DB |
14 | { |
15 | |
16 | class CompressedWriteBuffer : public BufferWithOwnMemory<WriteBuffer> |
17 | { |
18 | private: |
19 | WriteBuffer & out; |
20 | CompressionCodecPtr codec; |
21 | |
22 | PODArray<char> compressed_buffer; |
23 | |
24 | void nextImpl() override; |
25 | |
26 | public: |
27 | CompressedWriteBuffer( |
28 | WriteBuffer & out_, |
29 | CompressionCodecPtr codec_ = CompressionCodecFactory::instance().getDefaultCodec(), |
30 | size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE); |
31 | |
32 | /// The amount of compressed data |
33 | size_t getCompressedBytes() |
34 | { |
35 | nextIfAtEnd(); |
36 | return out.count(); |
37 | } |
38 | |
39 | /// How many uncompressed bytes were written to the buffer |
40 | size_t getUncompressedBytes() |
41 | { |
42 | return count(); |
43 | } |
44 | |
45 | /// How many bytes are in the buffer (not yet compressed) |
46 | size_t getRemainingBytes() |
47 | { |
48 | nextIfAtEnd(); |
49 | return offset(); |
50 | } |
51 | |
52 | ~CompressedWriteBuffer() override; |
53 | }; |
54 | |
55 | } |
56 |