aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/Lz4DeflatingWriteBuffer.h
blob: 68873b5f8ee2755d73bb91759bcefc2a2e7c231c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include <IO/BufferWithOwnMemory.h>
#include <IO/CompressionMethod.h>
#include <IO/WriteBuffer.h>
#include <IO/WriteBufferDecorator.h>

#include <lz4.h>
#include <lz4frame.h>

namespace DB
{
/// Performs compression using lz4 library and writes compressed data to out_ WriteBuffer.
class Lz4DeflatingWriteBuffer : public WriteBufferWithOwnMemoryDecorator
{
public:
    Lz4DeflatingWriteBuffer(
        std::unique_ptr<WriteBuffer> out_,
        int compression_level,
        size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
        char * existing_memory = nullptr,
        size_t alignment = 0);

    ~Lz4DeflatingWriteBuffer() override;

private:
    void nextImpl() override;

    void finalizeBefore() override;
    void finalizeAfter() override;

    LZ4F_preferences_t kPrefs; /// NOLINT
    LZ4F_compressionContext_t ctx;

    void * in_data;
    void * out_data;

    size_t in_capacity;
    size_t out_capacity;

    bool first_time = true;
};
}