2012-01-05 10:22:02 +00:00
|
|
|
#pragma once
|
2010-06-04 18:25:25 +00:00
|
|
|
|
2016-08-19 01:54:23 +00:00
|
|
|
#include <memory>
|
2011-06-24 20:18:09 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/PODArray.h>
|
2010-06-04 18:25:25 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
2017-10-12 23:56:28 +00:00
|
|
|
#include <IO/CompressionSettings.h>
|
2010-06-04 18:25:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2011-06-27 18:22:14 +00:00
|
|
|
class CompressedWriteBuffer : public BufferWithOwnMemory<WriteBuffer>
|
2010-06-04 18:25:25 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBuffer & out;
|
2017-10-12 23:56:28 +00:00
|
|
|
CompressionSettings compression_settings;
|
2010-06-04 18:25:25 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
PODArray<char> compressed_buffer;
|
2016-03-07 04:31:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void nextImpl() override;
|
2011-05-05 19:10:17 +00:00
|
|
|
|
2011-06-26 21:30:59 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
CompressedWriteBuffer(
|
|
|
|
WriteBuffer & out_,
|
2017-10-12 23:56:28 +00:00
|
|
|
CompressionSettings compression_settings = CompressionSettings(),
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// The amount of compressed data
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t getCompressedBytes()
|
|
|
|
{
|
|
|
|
nextIfAtEnd();
|
|
|
|
return out.count();
|
|
|
|
}
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// How many uncompressed bytes were written to the buffer
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t getUncompressedBytes()
|
|
|
|
{
|
|
|
|
return count();
|
|
|
|
}
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// How many bytes are in the buffer (not yet compressed)
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t getRemainingBytes()
|
|
|
|
{
|
|
|
|
nextIfAtEnd();
|
|
|
|
return offset();
|
|
|
|
}
|
|
|
|
|
|
|
|
~CompressedWriteBuffer() override;
|
2010-06-04 18:25:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|