-
Notifications
You must be signed in to change notification settings - Fork 24
/
MCM.cpp
585 lines (561 loc) · 22.7 KB
/
MCM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/* MCM file compressor
Copyright (C) 2013, Google Inc.
Authors: Mathieu Chartier
LICENSE
This file is part of the MCM file compressor.
MCM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MCM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MCM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <chrono>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <sstream>
#include <thread>
#include "Archive.hpp"
#include "CM.hpp"
#include "DeltaFilter.hpp"
#include "Dict.hpp"
#include "File.hpp"
#include "Huffman.hpp"
#include "LZ-inl.hpp"
#include "ProgressMeter.hpp"
#include "Tests.hpp"
#include "TurboCM.hpp"
#include "X86Binary.hpp"
static constexpr bool kReleaseBuild = false;
static void printHeader() {
std::cout
<< "======================================================================" << std::endl
<< "mcm compressor v" << Archive::Header::kCurMajorVersion << "." << Archive::Header::kCurMinorVersion
<< ", by Mathieu Chartier (c)2016 Google Inc." << std::endl
<< "Experimental, may contain bugs. Contact mathieu.a.chartier@gmail.com" << std::endl
<< "Special thanks to: Matt Mahoney, Stephan Busch, Christopher Mattern." << std::endl
<< "======================================================================" << std::endl;
}
class Options {
public:
// Block size of 0 -> file size / #threads.
static const uint64_t kDefaultBlockSize = 0;
enum Mode {
kModeUnknown,
// Compress -> Decompress -> Verify.
// (File or directory).
kModeTest,
// Compress infinite times with different opt vars.
kModeOpt,
// In memory test.
kModeMemTest,
// Single file test.
kModeSingleTest,
// Add a single file.
kModeAdd,
kModeExtract,
kModeExtractAll,
// Single hand mode.
kModeCompress,
kModeDecompress,
// List & other
kModeList,
};
Mode mode = kModeUnknown;
bool opt_mode = false;
CompressionOptions options_;
Compressor* compressor = nullptr;
uint32_t threads = 1;
uint64_t block_size = kDefaultBlockSize;
FileInfo archive_file;
std::vector<FileInfo> files;
const std::string kDictArg = "-dict=";
const std::string kOutDictArg = "-out-dict=";
std::string dict_file;
int usage(const std::string& name) {
printHeader();
std::cout
<< "Caution: Experimental, use only for testing!" << std::endl
<< "Usage: " << name << " [commands] [options] <infile|dir> <outfile>(default infile.mcm)" << std::endl
<< "Options: d for decompress" << std::endl
<< "-{t|f|m|h|x}{1 .. 11} compression option" << std::endl
<< "t is turbo, f is fast, m is mid, h is high, x is max (default " << CompressionOptions::kDefaultLevel << ")" << std::endl
<< "0 .. 11 specifies memory with 32mb .. 5gb per thread (default " << CompressionOptions::kDefaultMemUsage << ")" << std::endl
<< "10 and 11 are only supported on 64 bits" << std::endl
<< "-test tests the file after compression is done" << std::endl
// << "-b <mb> specifies block size in MB" << std::endl
// << "-t <threads> the number of threads to use (decompression requires the same number of threads" << std::endl
<< "Examples:" << std::endl
<< "Compress: " << name << " -m9 enwik8 enwik8.mcm" << std::endl
<< "Decompress: " << name << " d enwik8.mcm enwik8.ref" << std::endl;
return 0;
}
int parse(int argc, char* argv[]) {
assert(argc >= 1);
std::string program(trimExt(argv[0]));
// Parse options.
int i = 1;
bool has_comp_args = false;
for (;i < argc;++i) {
const std::string arg(argv[i]);
Mode parsed_mode = kModeUnknown;
if (arg == "-test") parsed_mode = kModeSingleTest; // kModeTest;
else if (arg == "-memtest") parsed_mode = kModeMemTest;
else if (arg == "-opt") parsed_mode = kModeOpt;
else if (arg == "-stest") parsed_mode = kModeSingleTest;
else if (arg == "c") parsed_mode = kModeCompress;
else if (arg == "l") parsed_mode = kModeList;
else if (arg == "d") parsed_mode = kModeDecompress;
else if (arg == "a") parsed_mode = kModeAdd;
else if (arg == "e") parsed_mode = kModeExtract;
else if (arg == "x") parsed_mode = kModeExtractAll;
if (parsed_mode != kModeUnknown) {
if (mode != kModeUnknown) {
std::cerr << "Multiple commands specified" << std::endl;
return 2;
}
mode = parsed_mode;
switch (mode) {
case kModeAdd:
case kModeExtract:
case kModeExtractAll: {
if (++i >= argc) {
std::cerr << "Expected archive" << std::endl;
return 3;
}
// Archive is next.
archive_file = FileInfo(argv[i]);
break;
}
}
} else if (arg == "-opt") opt_mode = true;
else if (arg == "-filter=none") options_.filter_type_ = kFilterTypeNone;
else if (arg == "-filter=dict") options_.filter_type_ = kFilterTypeDict;
else if (arg == "-filter=x86") options_.filter_type_ = kFilterTypeX86;
else if (arg == "-filter=auto") options_.filter_type_ = kFilterTypeAuto;
else if (arg.substr(0, std::min(kDictArg.length(), arg.length())) == kDictArg) {
options_.dict_file_ = arg.substr(kDictArg.length());
} else if (arg.substr(0, std::min(kOutDictArg.length(), arg.length())) == kOutDictArg) {
options_.out_dict_file_ = arg.substr(kOutDictArg.length());
} else if (arg == "-lzp=auto") options_.lzp_type_ = kLZPTypeAuto;
else if (arg == "-lzp=true") options_.lzp_type_ = kLZPTypeEnable;
else if (arg == "-lzp=false") options_.lzp_type_ = kLZPTypeDisable;
else if (arg == "-b") {
if (i + 1 >= argc) {
return usage(program);
}
std::istringstream iss(argv[++i]);
iss >> block_size;
block_size *= MB;
if (!iss.good()) {
return usage(program);
}
} else if (arg == "-store") {
options_.comp_level_ = kCompLevelStore;
has_comp_args = true;
} else if (arg[0] == '-') {
if (arg[1] == 't') options_.comp_level_ = kCompLevelTurbo;
else if (arg[1] == 'f') options_.comp_level_ = kCompLevelFast;
else if (arg[1] == 'm') options_.comp_level_ = kCompLevelMid;
else if (arg[1] == 'h') options_.comp_level_ = kCompLevelHigh;
else if (arg[1] == 'x') options_.comp_level_ = kCompLevelMax;
else if (arg[1] == 's') options_.comp_level_ = kCompLevelSimple;
else {
std::cerr << "Unknown option " << arg << std::endl;
return 4;
}
has_comp_args = true;
const std::string mem_string = arg.substr(2);
if (mem_string == "0") options_.mem_usage_ = 0;
else if (mem_string == "1") options_.mem_usage_ = 1;
else if (mem_string == "2") options_.mem_usage_ = 2;
else if (mem_string == "3") options_.mem_usage_ = 3;
else if (mem_string == "4") options_.mem_usage_ = 4;
else if (mem_string == "5") options_.mem_usage_ = 5;
else if (mem_string == "6") options_.mem_usage_ = 6;
else if (mem_string == "7") options_.mem_usage_ = 7;
else if (mem_string == "8") options_.mem_usage_ = 8;
else if (mem_string == "9") options_.mem_usage_ = 9;
else if (mem_string == "10" || mem_string == "11") {
if (sizeof(void*) < 8) {
std::cerr << arg << " is only supported with 64 bit" << std::endl;
return usage(program);
}
options_.mem_usage_ = (mem_string == "10") ? 10 : 11;
} else if (!mem_string.empty()) {
std::cerr << "Unknown mem level " << mem_string << std::endl;
return 4;
}
} else if (!arg.empty()) {
if (mode == kModeAdd || mode == kModeExtract) {
files.push_back(FileInfo(argv[i])); // Read in files.
} else {
break; // Done parsing.
}
}
}
if (mode == kModeUnknown) {
const int remaining_args = argc - i;
// No args, need to figure out what to do:
// decompress: mcm <archive>
// TODO add files to archive: mcm <archive> <files>
// create archive: mcm <files>
mode = kModeCompress;
if (!has_comp_args && remaining_args == 1) {
// Try to open file.
File fin;
if (fin.open(argv[i], std::ios_base::in | std::ios_base::binary) == 0) {
Archive archive(&fin);
const auto& header = archive.getHeader();
if (header.isArchive()) {
mode = kModeDecompress;
}
}
}
}
const bool single_file_mode =
mode == kModeCompress || mode == kModeDecompress || mode == kModeSingleTest ||
mode == kModeMemTest || mode == kModeOpt || kModeList;
if (single_file_mode && i < argc) {
std::string in_file, out_file;
// Read in file and outfile.
in_file = argv[i++];
if (i < argc) {
out_file = argv[i++];
} else {
if (mode == kModeDecompress) {
out_file = in_file + ".decomp";
} else {
out_file = trimDir(in_file) + ".mcm";
}
}
if (mode == kModeMemTest) {
// No out file for memtest.
files.push_back(FileInfo(trimDir(in_file)));
} else if (mode == kModeCompress || mode == kModeSingleTest || mode == kModeOpt) {
archive_file = FileInfo(trimDir(out_file));
files.push_back(FileInfo(trimDir(in_file)));
} else {
archive_file = FileInfo(trimDir(in_file));
files.push_back(FileInfo(trimDir(out_file)));
}
}
if (mode != kModeMemTest &&
(archive_file.getName().empty() || (files.empty() && mode != kModeList))) {
std::cerr << "Error, input or output files missing" << std::endl;
usage(program);
return 5;
}
return 0;
}
};
extern void RunBenchmarks();
int main(int argc, char* argv[]) {
if (!kReleaseBuild) {
RunAllTests();
}
Options options;
auto ret = options.parse(argc, argv);
if (ret) {
std::cerr << "Failed to parse arguments" << std::endl;
return ret;
}
switch (options.mode) {
case Options::kModeMemTest: {
constexpr size_t kCompIterations = kIsDebugBuild ? 1 : 1;
constexpr size_t kDecompIterations = kIsDebugBuild ? 1 : 25;
// Read in the whole file.
std::vector<uint64_t> lengths;
uint64_t long_length = 0;
for (const auto& file : options.files) {
File f(file.getName());
lengths.push_back(f.length());
long_length += lengths.back();
}
auto length = static_cast<size_t>(long_length);
check(length < 300 * MB);
auto* in_buffer = new uint8_t[length];
// Read in the files.
uint32_t index = 0;
uint64_t read_pos = 0;
for (const auto& file : options.files) {
File f(file.getName(), std::ios_base::in | std::ios_base::binary);
size_t count = f.read(in_buffer + read_pos, static_cast<size_t>(lengths[index]));
check(count == lengths[index]);
index++;
}
// Create the memory compressor.
typedef SimpleEncoder<8, 16> Encoder;
// auto* compressor = new LZ4;
// auto* compressor = new LZSSE;
// auto* compressor = new MemCopyCompressor;
auto* compressor = new LZ16<FastMatchFinder<MemoryMatchFinder>>;
auto out_buffer = new uint8_t[compressor->getMaxExpansion(length)];
uint32_t comp_start = clock();
uint32_t comp_size;
static const bool opt_mode = false;
if (opt_mode) {
uint32_t best_size = 0xFFFFFFFF;
uint32_t best_opt = 0;
std::ofstream opt_file("opt_result.txt");
for (uint32_t opt = 0; ; ++opt) {
compressor->setOpt(opt);
comp_size = compressor->compress(in_buffer, out_buffer, length);
opt_file << "opt " << opt << " = " << comp_size << std::endl << std::flush;
std::cout << "Opt " << opt << " / " << best_opt << " = " << comp_size << "/" << best_size << std::endl;
if (comp_size < best_size) {
best_opt = opt;
best_size = comp_size;
}
}
} else {
for (uint32_t i = 0; i < kCompIterations; ++i) {
comp_size = compressor->compress(in_buffer, out_buffer, length);
}
}
const uint32_t comp_end = clock();
std::cout << "Done compressing " << length << " -> " << comp_size << " = " << float(double(length) / double(comp_size)) << " rate: "
<< prettySize(static_cast<uint64_t>(long_length * kCompIterations / clockToSeconds(comp_end - comp_start))) << "/s" << std::endl;
memset(in_buffer, 0, length);
const uint32_t decomp_start = clock();
for (uint32_t i = 0; i < kDecompIterations; ++i) {
compressor->decompress(out_buffer, in_buffer, length);
}
const uint32_t decomp_end = clock();
std::cout << "Decompression took: " << decomp_end - comp_end << " rate: "
<< prettySize(static_cast<uint64_t>(long_length * kDecompIterations / clockToSeconds(decomp_end - decomp_start))) << "/s" << std::endl;
index = 0;
for (const auto& file : options.files) {
File f(file.getName(), std::ios_base::in | std::ios_base::binary);
const auto count = static_cast<uint32_t>(f.read(out_buffer, static_cast<uint32_t>(lengths[index])));
check(count == lengths[index]);
for (uint32_t i = 0; i < count; ++i) {
if (out_buffer[i] != in_buffer[i]) {
std::cerr << "File" << file.getName() << " doesn't match at byte " << i << std::endl;
check(false);
}
}
index++;
}
std::cout << "Decompression verified" << std::endl;
break;
}
case Options::kModeSingleTest:
case Options::kModeOpt:
case Options::kModeCompress:
case Options::kModeTest: {
printHeader();
int err = 0;
std::string out_file = options.archive_file.getName();
File fout;
if (options.mode == Options::kModeOpt) {
std::cout << "Optimizing" << std::endl;
uint64_t best_size = std::numeric_limits<uint64_t>::max();
size_t best_var = 0;
std::ofstream opt_file("opt_result.txt");
// static const size_t kOpts = 10624;
static const size_t kOpts = 3;
// size_t opts[kOpts] = {0,1,2,3,15,14,4,6,7,8,9,17,12,11,13,5,10,18,20,19,21,26,22,28,23,24,16,25,27,29,31,32,36,33,34,35,37,30,38,39,};
// size_t opts[kOpts] = {}; for (size_t i = 0; i < kOpts; ++i) opts[i] = i;
size_t opts[kOpts] = {};
//size_t opts[] = {7,14,1,12,3,4,11,15,9,16,5,6,18,13,19,30,45,20,21,22,23,17,8,2,26,10,32,43,36,35,42,29,34,24,25,37,31,33,39,38,0,41,28,40,44,58,46,59,92,27,60,61,91,63,95,47,64,124,94,62,93,96,123,125,72,69,65,67,83,68,66,73,82,70,80,76,71,81,77,87,78,74,79,84,75,48,49,50,51,52,53,54,55,56,57,86,88,97,98,99,100,85,101,90,103,104,89,105,107,102,108,109,110,111,106,113,112,114,115,116,119,118,120,121,117,122,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,151,144,145,146,147,148,149,150,152,153,155,156,157,154,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,239,227,228,229,230,231,232,233,234,235,236,237,238,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,};
if (false) {
auto temp = ReadCSI<size_t>("optin.txt");
check(temp.size() == kOpts);
std::copy(temp.begin(), temp.end(), &opts[0]);
}
size_t best_opts[kOpts] = {};
srand(clock() + 291231);
size_t cur_index = 0;
size_t len = 1;
// size_t kMaxIndex = 128 - len;
// size_t kMaxIndex = cm::kModelCount;
size_t kMaxIndex = 12345;
size_t bads = 0;
size_t best_cur = 0;
static constexpr size_t kAvgCount = 2;
double total[kAvgCount] = {};
size_t count[kAvgCount] = {};
double min_time = std::numeric_limits<double>::max();
const bool kPerm = false;
if (kPerm) {
for (size_t i = 0;; ++i) {
if ((i & 255) == 255 && false) {
len -= len > 1;
kMaxIndex = 128 - len;
}
auto a = i % kMaxIndex;
auto b = (i + 1 + std::rand() % (kMaxIndex - 1)) % kMaxIndex;
VoidWriteStream fout;
Archive archive(&fout, options.options_);
if (i != 0) {
ReplaceSubstring(opts, a, len, b, kOpts);
}
if (!archive.setOpts(opts)) {
std::cerr << "Failed to set opts" << std::endl;
continue;
}
uint64_t in_bytes = archive.compress(options.files);
if (in_bytes == 0) continue;
const auto size = fout.tell();
std::cout << i << ": swap " << a << " to " << b << " " << size << std::endl;
if (size < best_size) {
std::cout << "IMPROVEMENT " << i << ": " << size << std::endl;
opt_file << i << ": " << size << " ";
for (auto opt : opts) opt_file << opt << ",";
opt_file << std::endl;
std::copy_n(opts, kOpts, best_opts);
best_size = size;
} else {
std::copy_n(best_opts, kOpts, opts);
}
}
} else {
for (auto o : opts) check(o <= kMaxIndex);
for (size_t i = 0;; ++i) {
const clock_t start = clock();
VoidWriteStream fout;
Archive archive(&fout, options.options_);
if (!archive.setOpts(opts)) {
continue;
}
uint64_t in_bytes = archive.compress(options.files);
if (in_bytes == 0) continue;
const double time = clockToSeconds(clock() - start);
total[i % kAvgCount] += time;
min_time = std::min(min_time, time);
const auto size = fout.tell();
opt_file << "opts ";
for (auto opt : opts) opt_file << opt << ",";
++count[i % kAvgCount];
auto before_index = cur_index;
auto before_opt = opts[before_index];
if (size < best_size) {
best_size = size;
std::copy_n(opts, kOpts, best_opts);
best_var = opts[cur_index];
bads = 0;
}
if (opts[cur_index] >= kMaxIndex) {
std::copy_n(best_opts, kOpts, opts);
cur_index = (cur_index + 1) % kOpts;
opts[cur_index] = 0;
} else {
++opts[cur_index];
}
std::ostringstream ss;
double avgs[kAvgCount] = {};
for (size_t i = 0; i < kAvgCount; ++i) {
if (count[i] != 0) avgs[i] = total[i] / double(count[i]);
}
double avg = std::accumulate(total, total + kAvgCount, 0.0) / double(std::accumulate(count, count + kAvgCount, 0u));
ss << " -> " << formatNumber(size) << " best " << best_var << " in " << time << "s avg "
<< avg << "(";
for (double d : avgs) ss << d << ",";
ss << ") min " << min_time;
opt_file << ss.str() << std::endl << std::flush;
std::cout << "opt[" << before_index << "]=" << before_opt << " best=" << best_var << "(" << formatNumber(best_size) << ") "
<< formatNumber(in_bytes) << ss.str() << std::endl;
}
}
} else {
const clock_t start = clock();
if (err = fout.open(out_file, std::ios_base::out | std::ios_base::binary)) {
std::cerr << "Error opening: " << out_file << " (" << errstr(err) << ")" << std::endl;
return 2;
}
std::cout << "Compressing to " << out_file << " mode=" << options.options_.comp_level_ << " mem=" << options.options_.mem_usage_ << std::endl;
Archive archive(&fout, options.options_);
uint64_t in_bytes = archive.compress(options.files);
clock_t time = clock() - start;
std::cout << "Done compressing " << formatNumber(in_bytes) << " -> " << formatNumber(fout.tell())
<< " in " << std::setprecision(3) << clockToSeconds(time) << "s"
<< " bpc=" << double(fout.tell()) * 8.0 / double(in_bytes) << std::endl;
fout.close();
if (options.mode == Options::kModeSingleTest) {
if (err = fout.open(out_file, std::ios_base::in | std::ios_base::binary)) {
std::cerr << "Error opening: " << out_file << " (" << errstr(err) << ")" << std::endl;
return 1;
}
Archive archive(&fout);
archive.list();
std::cout << "Verifying archive decompression" << std::endl;
archive.decompress("", true);
}
}
break;
}
case Options::kModeAdd: {
// Add a single file.
break;
}
case Options::kModeList: {
auto in_file = options.archive_file.getName();
File fin;
int err = 0;
if (err = fin.open(in_file, std::ios_base::in | std::ios_base::binary)) {
std::cerr << "Error opening: " << in_file << " (" << errstr(err) << ")" << std::endl;
return 1;
}
printHeader();
std::cout << "Listing files in archive " << in_file << std::endl;
Archive archive(&fin);
const auto& header = archive.getHeader();
if (!header.isArchive()) {
std::cerr << "Attempting to open non mcm compatible file" << std::endl;
return 1;
}
if (!header.isSameVersion()) {
std::cerr << "Attempting to open old version " << header.majorVersion() << "." << header.minorVersion() << std::endl;
return 1;
}
archive.list();
fin.close();
break;
}
case Options::kModeDecompress: {
auto in_file = options.archive_file.getName();
File fin;
File fout;
int err = 0;
if (err = fin.open(in_file, std::ios_base::in | std::ios_base::binary)) {
std::cerr << "Error opening: " << in_file << " (" << errstr(err) << ")" << std::endl;
return 1;
}
printHeader();
std::cout << "Decompresing archive " << in_file << std::endl;
Archive archive(&fin);
const auto& header = archive.getHeader();
if (!header.isArchive()) {
std::cerr << "Attempting to decompress non archive file" << std::endl;
return 1;
}
if (!header.isSameVersion()) {
std::cerr << "Attempting to decompress other version " << header.majorVersion() << "." << header.minorVersion() << std::endl;
return 1;
}
// archive.decompress(options.files.back().getName());
archive.decompress("");
fin.close();
// Decompress the single file in the archive to the output out.
break;
}
case Options::kModeExtract: {
// Extract a single file from multi file archive.
break;
}
case Options::kModeExtractAll: {
// Extract all the files in the archive.
// archive.ExtractAll();
break;
}
}
return 0;
}