blob: 6ae1fbee9cc2c60c1ebfcf1b79839f48f9defff4 (
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
44
45
46
47
48
49
50
51
52
53
54
55
|
#pragma once
#include <memory>
#include <Common/PODArray.h>
#include <IO/WriteBuffer.h>
#include <IO/BufferWithOwnMemory.h>
#include <Compression/ICompressionCodec.h>
#include <Compression/CompressionFactory.h>
namespace DB
{
class CompressedWriteBuffer final : public BufferWithOwnMemory<WriteBuffer>
{
public:
explicit CompressedWriteBuffer(
WriteBuffer & out_,
CompressionCodecPtr codec_ = CompressionCodecFactory::instance().getDefaultCodec(),
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
~CompressedWriteBuffer() override;
/// The amount of compressed data
size_t getCompressedBytes()
{
nextIfAtEnd();
return out.count();
}
/// How many uncompressed bytes were written to the buffer
size_t getUncompressedBytes()
{
return count();
}
/// How many bytes are in the buffer (not yet compressed)
size_t getRemainingBytes()
{
nextIfAtEnd();
return offset();
}
private:
void nextImpl() override;
WriteBuffer & out;
CompressionCodecPtr codec;
PODArray<char> compressed_buffer;
};
}
|