| 1 | #pragma once | 
|---|---|
| 2 | |
| 3 | #include <IO/ReadBuffer.h> | 
| 4 | #include <IO/BufferWithOwnMemory.h> | 
| 5 | #include <IO/CompressionMethod.h> | 
| 6 | |
| 7 | #include <zlib.h> | 
| 8 | |
| 9 | |
| 10 | namespace DB | 
| 11 | { | 
| 12 | |
| 13 | namespace ErrorCodes | 
| 14 | { | 
| 15 | extern const int ZLIB_INFLATE_FAILED; | 
| 16 | } | 
| 17 | |
| 18 | /// Reads compressed data from ReadBuffer in_ and performs decompression using zlib library. | 
| 19 | /// This buffer is able to seamlessly decompress multiple concatenated zlib streams. | 
| 20 | class ZlibInflatingReadBuffer : public BufferWithOwnMemory<ReadBuffer> | 
| 21 | { | 
| 22 | public: | 
| 23 | ZlibInflatingReadBuffer( | 
| 24 | std::unique_ptr<ReadBuffer> in_, | 
| 25 | CompressionMethod compression_method, | 
| 26 | size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, | 
| 27 | char * existing_memory = nullptr, | 
| 28 | size_t alignment = 0); | 
| 29 | |
| 30 | ~ZlibInflatingReadBuffer() override; | 
| 31 | |
| 32 | private: | 
| 33 | bool nextImpl() override; | 
| 34 | |
| 35 | std::unique_ptr<ReadBuffer> in; | 
| 36 | z_stream zstr; | 
| 37 | bool eof; | 
| 38 | }; | 
| 39 | |
| 40 | } | 
| 41 | 
