Skip to content

Commit

Permalink
compressor: allowed to specify block size [#METR-2807].
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-milovidov committed Feb 24, 2014
1 parent 63cfb98 commit e1044ec
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions utils/compressor/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <iostream>

#include <boost/program_options.hpp>

#include <DB/IO/WriteBufferFromFileDescriptor.h>
#include <DB/IO/ReadBufferFromFileDescriptor.h>
#include <DB/IO/CompressedWriteBuffer.h>
Expand Down Expand Up @@ -36,24 +38,31 @@ void stat(DB::ReadBuffer & in, DB::WriteBuffer & out)

int main(int argc, char ** argv)
{
try
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("d,decompress", "decompress")
("block-size,b", boost::program_options::value<unsigned>()->default_value(DBMS_DEFAULT_BUFFER_SIZE), "compress in blocks of specified size")
("qlz", "use QuickLZ (level 1) instead of LZ4")
("stat", "print block statistics of compressed data")
;

boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);

if (options.count("help"))
{
bool decompress = false;
bool use_qlz = false;
bool stat_mode = false;
std::cout << "Usage: " << argv[0] << " [options] < in > out" << std::endl;
std::cout << desc << std::endl;
return 1;
}

if (argc == 2)
{
decompress = 0 == strcmp(argv[1], "-d");
use_qlz = 0 == strcmp(argv[1], "--qlz");
stat_mode = 0 == strcmp(argv[1], "--stat");
}

if (argc > 2 || (argc == 2 && !decompress && !use_qlz && !stat_mode))
{
std::cerr << "Usage: " << argv[0] << " [-d|--qlz|--stat] < in > out" << std::endl;
return 1;
}
try
{
bool decompress = options.count("d");
bool use_qlz = options.count("qlz");;
bool stat_mode = options.count("stat");
unsigned block_size = options["block-size"].as<unsigned>();

DB::CompressionMethod::Enum method = use_qlz ? DB::CompressionMethod::QuickLZ : DB::CompressionMethod::LZ4;

Expand All @@ -74,7 +83,7 @@ int main(int argc, char ** argv)
else
{
/// Сжатие
DB::CompressedWriteBuffer to(wb, method);
DB::CompressedWriteBuffer to(wb, method, block_size);
DB::copyData(rb, to);
}
}
Expand Down

0 comments on commit e1044ec

Please sign in to comment.