ClickHouse/utils/compressor/main.cpp

65 lines
1.4 KiB
C++
Raw Normal View History

#include <iostream>
#include <Poco/SharedPtr.h>
2011-12-28 20:15:56 +00:00
#include <DB/IO/WriteBufferFromFileDescriptor.h>
#include <DB/IO/ReadBufferFromFileDescriptor.h>
#include <DB/IO/CompressedWriteBuffer.h>
#include <DB/IO/CompressedReadBuffer.h>
#include <DB/IO/copyData.h>
int main(int argc, char ** argv)
{
2012-01-05 18:35:22 +00:00
try
{
2012-01-05 18:35:22 +00:00
bool decompress = false;
2012-04-14 00:18:07 +00:00
bool use_qlz = false;
2012-01-05 18:35:22 +00:00
if (argc == 2)
{
decompress = 0 == strcmp(argv[1], "-d");
2012-04-14 00:18:07 +00:00
use_qlz = 0 == strcmp(argv[1], "--qlz");
2012-01-05 18:35:22 +00:00
}
2012-04-14 00:18:07 +00:00
if (argc > 2 || (argc == 2 && !decompress && !use_qlz))
2012-01-05 18:35:22 +00:00
{
2012-04-14 00:18:07 +00:00
std::cerr << "Usage: " << argv[0] << " [-d|--qlz] < in > out" << std::endl;
2012-01-05 18:35:22 +00:00
return 1;
}
2012-04-14 00:18:07 +00:00
DB::CompressionMethod::Enum method = use_qlz ? DB::CompressionMethod::QuickLZ : DB::CompressionMethod::LZ4;
2012-01-05 18:35:22 +00:00
Poco::SharedPtr<DB::ReadBuffer> rb = new DB::ReadBufferFromFileDescriptor(STDIN_FILENO);
Poco::SharedPtr<DB::WriteBuffer> wb = new DB::WriteBufferFromFileDescriptor(STDOUT_FILENO);
Poco::SharedPtr<DB::ReadBuffer> from;
Poco::SharedPtr<DB::WriteBuffer> to;
if (!decompress)
{
/// Сжатие
from = rb;
to = new DB::CompressedWriteBuffer(*wb, method);
}
else
{
/// Разжатие
from = new DB::CompressedReadBuffer(*rb);
to = wb;
}
DB::copyData(*from, *to);
}
2012-01-05 18:35:22 +00:00
catch (const DB::Exception & e)
{
2012-01-05 18:35:22 +00:00
std::cerr << e.what() << ", " << e.message() << std::endl
<< std::endl
<< "Stack trace:" << std::endl
<< e.getStackTrace().toString()
<< std::endl;
throw;
}
return 0;
}