2017-01-07 16:11:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
2019-02-13 20:54:12 +00:00
|
|
|
#include <IO/CompressionMethod.h>
|
2017-01-07 16:11:30 +00:00
|
|
|
|
|
|
|
#include <zlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Performs compression using zlib library and writes compressed data to out_ WriteBuffer.
|
|
|
|
class ZlibDeflatingWriteBuffer : public BufferWithOwnMemory<WriteBuffer>
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
ZlibDeflatingWriteBuffer(
|
2019-11-19 12:46:07 +00:00
|
|
|
std::unique_ptr<WriteBuffer> out_,
|
2019-02-13 20:54:12 +00:00
|
|
|
CompressionMethod compression_method,
|
2017-04-01 07:20:54 +00:00
|
|
|
int compression_level,
|
|
|
|
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
|
|
|
|
char * existing_memory = nullptr,
|
|
|
|
size_t alignment = 0);
|
2017-01-07 16:11:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Flush all pending data and write zlib footer to the underlying buffer.
|
|
|
|
/// After the first call to this function, subsequent calls will have no effect and
|
|
|
|
/// an attempt to write to this buffer will result in exception.
|
|
|
|
void finish();
|
2017-01-07 16:11:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~ZlibDeflatingWriteBuffer() override;
|
2017-01-07 16:11:30 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void nextImpl() override;
|
2017-01-07 16:11:30 +00:00
|
|
|
|
2019-11-19 12:46:07 +00:00
|
|
|
std::unique_ptr<WriteBuffer> out;
|
2017-04-01 07:20:54 +00:00
|
|
|
z_stream zstr;
|
|
|
|
bool finished = false;
|
2017-01-07 16:11:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|