2021-06-16 05:43:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
|
|
|
#include <IO/CompressionMethod.h>
|
|
|
|
#include <IO/WriteBuffer.h>
|
2021-11-10 22:58:56 +00:00
|
|
|
#include <IO/WriteBufferDecorator.h>
|
2021-06-16 05:43:07 +00:00
|
|
|
|
2021-06-17 08:31:37 +00:00
|
|
|
#include <lz4.h>
|
2021-07-05 06:19:07 +00:00
|
|
|
#include <lz4frame.h>
|
2021-06-16 05:43:07 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/// Performs compression using lz4 library and writes compressed data to out_ WriteBuffer.
|
2021-11-10 22:58:56 +00:00
|
|
|
class Lz4DeflatingWriteBuffer : public WriteBufferWithOwnMemoryDecorator
|
2021-06-16 05:43:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2024-01-03 16:47:15 +00:00
|
|
|
template<typename WriteBufferT>
|
2021-06-16 05:43:07 +00:00
|
|
|
Lz4DeflatingWriteBuffer(
|
2024-01-03 16:47:15 +00:00
|
|
|
WriteBufferT && out_,
|
2021-06-16 05:43:07 +00:00
|
|
|
int compression_level,
|
|
|
|
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
|
|
|
|
char * existing_memory = nullptr,
|
2024-01-03 16:47:15 +00:00
|
|
|
size_t alignment = 0,
|
|
|
|
bool compress_empty_ = true)
|
|
|
|
: WriteBufferWithOwnMemoryDecorator(std::move(out_), buf_size, existing_memory, alignment)
|
|
|
|
, tmp_memory(buf_size)
|
|
|
|
, compress_empty(compress_empty_)
|
|
|
|
{
|
|
|
|
initialize(compression_level);
|
|
|
|
}
|
2021-06-16 05:43:07 +00:00
|
|
|
|
|
|
|
~Lz4DeflatingWriteBuffer() override;
|
|
|
|
|
|
|
|
private:
|
2024-01-03 16:47:15 +00:00
|
|
|
void initialize(int compression_level);
|
|
|
|
|
2021-06-16 05:43:07 +00:00
|
|
|
void nextImpl() override;
|
|
|
|
|
2021-11-22 11:19:26 +00:00
|
|
|
void finalizeBefore() override;
|
|
|
|
void finalizeAfter() override;
|
2021-06-16 05:43:07 +00:00
|
|
|
|
2022-03-13 11:59:20 +00:00
|
|
|
LZ4F_preferences_t kPrefs; /// NOLINT
|
2021-07-05 06:19:07 +00:00
|
|
|
LZ4F_compressionContext_t ctx;
|
|
|
|
|
2023-11-17 16:26:53 +00:00
|
|
|
Memory<> tmp_memory;
|
2021-07-24 16:29:35 +00:00
|
|
|
|
2021-08-19 10:34:23 +00:00
|
|
|
bool first_time = true;
|
2024-01-03 16:47:15 +00:00
|
|
|
bool compress_empty = true;
|
2021-06-16 05:43:07 +00:00
|
|
|
};
|
|
|
|
}
|