mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-14 19:45:11 +00:00
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
|
#ifndef DBMS_COMMON_COMPRESSED_OUTPUT_STREAM_H
|
|||
|
#define DBMS_COMMON_COMPRESSED_OUTPUT_STREAM_H
|
|||
|
|
|||
|
#include <istream>
|
|||
|
#include <ostream>
|
|||
|
#include <vector>
|
|||
|
|
|||
|
#include <Poco/BufferedStreamBuf.h>
|
|||
|
|
|||
|
#include <quicklz/quicklz_level1.h>
|
|||
|
|
|||
|
#include <DB/IO/CompressedStream.h>
|
|||
|
|
|||
|
|
|||
|
namespace DB
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
/** Аналогично Poco::DeflatingStreamBuf, но используется библиотека QuickLZ,
|
|||
|
* а также поддерживается только ostream.
|
|||
|
*/
|
|||
|
class CompressingStreamBuf : public Poco::BufferedStreamBuf
|
|||
|
{
|
|||
|
public:
|
|||
|
CompressingStreamBuf(std::ostream & ostr);
|
|||
|
~CompressingStreamBuf();
|
|||
|
int close();
|
|||
|
|
|||
|
protected:
|
|||
|
int writeToDevice(const char * buffer, std::streamsize length);
|
|||
|
|
|||
|
private:
|
|||
|
std::ostream * p_ostr;
|
|||
|
std::vector<char> compressed_buffer;
|
|||
|
std::vector<char> scratch;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/** Базовый класс для CompressedOutputStream; содержит CompressingStreamBuf
|
|||
|
*/
|
|||
|
class CompressingIOS : public virtual std::ios
|
|||
|
{
|
|||
|
public:
|
|||
|
CompressingIOS(std::ostream & ostr);
|
|||
|
CompressingStreamBuf * rdbuf();
|
|||
|
|
|||
|
protected:
|
|||
|
CompressingStreamBuf buf;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
/** Сжимает всё с помощью алгоритма QuickLZ блоками не более DBMS_COMPRESSING_STREAM_BUFFER_SIZE.
|
|||
|
* Для записи последнего блока, следует вызвать метод close().
|
|||
|
*/
|
|||
|
class CompressedOutputStream : public CompressingIOS, public std::ostream
|
|||
|
{
|
|||
|
public:
|
|||
|
CompressedOutputStream(std::ostream & ostr);
|
|||
|
int close();
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endif
|