aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/IO/SnappyWriteBuffer.h
blob: 73652f33a52922e1e44693193534ea6c48bc66ea (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
#pragma once

#include "clickhouse_config.h"

#if USE_SNAPPY
#include <IO/BufferWithOwnMemory.h>
#include <IO/WriteBuffer.h>

namespace DB
{
/// Performs compression using snappy library and write compressed data to the underlying buffer.
class SnappyWriteBuffer : public BufferWithOwnMemory<WriteBuffer>
{
public:
    explicit SnappyWriteBuffer(
        std::unique_ptr<WriteBuffer> out_,
        size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
        char * existing_memory = nullptr,
        size_t alignment = 0);

    ~SnappyWriteBuffer() override;

    void finalizeImpl() override { finish(); }

private:
    void nextImpl() override;

    void finishImpl();
    void finish();

    std::unique_ptr<WriteBuffer> out;
    bool finished = false;

    String uncompress_buffer;
    String compress_buffer;
};

}

#endif