-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuncompress.cpp
More file actions
68 lines (51 loc) · 1.15 KB
/
Copy pathuncompress.cpp
File metadata and controls
68 lines (51 loc) · 1.15 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
/*
* uncompress.cpp
* Author: saito
* Date: May 18, 2018
* About:
*/
#include<iostream>
#include "fstream"
#include <vector>
#include <string>
#include <cstdlib>
#include "HCTree.h"
using namespace std;
int main(int argc, char *argv[]) {
if (argc != 3){
return 1;
}
ifstream input;
BitInputStream in;
input.open(argv[1],ios::in);
in.connect(input);
if( !input )
return 1;
vector<int> characters = vector<int>(256, 0);
unsigned char current;
// Using the header, construct the number of symbols
HCTree Tree;
Tree.decodeHeader(in, characters);
int highestFreq = 0;
for(int index = 0; index < characters.size();index++){
if (characters[index] > highestFreq){
highestFreq = characters[index];
}
}
Tree.build(characters);
// Prepare output file to insert data
string outputfile = argv[2];
ofstream output(argv[2], ios::out);
int currentChar = 0;
//Read from input, then pass into decode to get current
while(currentChar < Tree.charCount){
char inputchar;
inputchar = (char)Tree.decode(in);
currentChar++;
if (!input.eof() || currentChar != Tree.charCount){
output<<inputchar;
}
}
output.close();
return 0;
}