-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecompressor.cpp
More file actions
80 lines (71 loc) · 1.62 KB
/
Copy pathDecompressor.cpp
File metadata and controls
80 lines (71 loc) · 1.62 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
/*
* Decompressor.cpp
*
* Created on: 17/05/2014
* Author: ari
*/
#include "Decompressor.h"
#include "DataBlock.h"
#include "BWT.h"
#include "MTF.h"
#include <iostream>
#include "RunLenght.h"
#include "FileWriter.h"
#include "CompressedFileReader.h"
#include "HUFFMAN.h"
namespace std {
Decompressor::Decompressor() {
this->extension=".cmp";
}
void Decompressor::decompress(string file) {
DataBlock *dbIn,*dbOut;
HUFFMAN * huffman = new HUFFMAN();
CompressedFileReader * fr = new CompressedFileReader(file);
BWT * bwt = new BWT();
RunLenght * rle = new RunLenght();
MTF * mtf = new MTF();
FileWriter * fw = new FileWriter(this->removeExtension(file));
while(fr->hasBlocksLeft()){
cerr << "Leo un bloque" << endl;
dbIn = fr->getBlock();
// Aca va huffman
cerr << "HUff" << endl;
dbOut = huffman->decompress(dbIn);
delete dbIn;
dbIn=dbOut;
cerr << "RLE" << endl;
dbOut = rle->decode(dbIn);
delete dbIn;
dbIn = dbOut;
cerr << "MTF" << endl;
dbOut = mtf->decode(dbIn);
delete dbIn;
// Aca va BWT
dbIn=dbOut;
cerr << "BWT" << endl;
dbOut=bwt->untransform(dbIn);
fw->writeBlock(dbOut);
delete dbOut;
delete dbIn;
}
fr->close();
fw->close();
delete huffman;
delete rle;
delete bwt;
delete mtf;
delete fw;
delete fr;
}
Decompressor::~Decompressor() {
// TODO Auto-generated destructor stub
}
string Decompressor::removeExtension(string path) {
if(path.compare(path.size()-this->extension.size(), this->extension.size(), this->extension, 0,this->extension.size())){
path.resize(path.size()-2);
return path;
}else
throw "Extensión equivocada";
return NULL;
}
} /* namespace std */