-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (66 loc) · 2.26 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (66 loc) · 2.26 KB
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
#include <iostream>
#include "include/Huffman/Huffman.h"
#include "include/Parser.h"
#include "include/LZW/LZW.h"
void tester() {
std::ofstream file("numbers.bin", std::ios::binary);
for (int i = 1; i <= 20000000; i++) {
file.write(reinterpret_cast<char *>(&i), sizeof(i));
}
file.close();
}
void test_bit_buffer() {
std::ifstream file("files/1.png", std::ios::binary);
auto reader = BitBuffer(file);
std::ofstream out("files/1.copy.png", std::ios::binary);
auto writer = BitBuffer(out);
while (!reader.eof()) {
int bit = reader.read_bit();
writer.write_bit(bit);
}
writer.flush();
}
int main(int argc, char *argv[]) {
tester();
comp::Parser parser;
try {
std::string commandLine;
for (size_t i = 1; i < argc; i++) {
commandLine += argv[i];
commandLine += " ";
}
std::cout << commandLine << std::endl;
parser.parse(commandLine);
for (const auto &file_name: parser.getInputFiles()) {
if (parser.getCompressionMethod() == "--huffman") {
std::cout << "Algorithm chosen: Huffman" << std::endl;
auto file = Huffman(file_name);
if (file.get_extension() == "groza") {
file.decompress();
} else {
file.compress();
}
} else if (parser.getCompressionMethod() == "--lzw") {
std::cout << "Algorithm chosen: LZW" << std::endl;
auto file = lzw(file_name);
if (file.get_extension() == "groza") {
file.decompress();
} else {
file.compress();
}
}
}
std::cout << "\nCompression Method: " << parser.getCompressionMethod() << "\n";
std::cout << "Item type: " << parser.getFileFolder() << "\n";
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << "\n";
return 1;
}
// std::ifstream file("test.groza", std::ios::binary);
// int value;
// while (file.read(reinterpret_cast<char*>(&value), sizeof(value))) {
// std::cout << "Output Code: " << value << std::endl;
// }
// file.close();
return 0;
}