-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSParch.cpp
52 lines (40 loc) · 1.41 KB
/
SParch.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
#include "SParch.h"
#include<vector>
#include <iostream>
using namespace std;
SParch::SParch() {
ar = new Archiver();
bH = new BHuffman();
}
SParch::~SParch() { }
void SParch::Compression(vector<string> files, string pathArch) {
vector<string> compressedFiles;
for (vector<string>::iterator it = files.begin(); it != files.end(); ++it) {
compressedFiles.push_back(bH->Compression(*(it)));
}
ar->Compression(compressedFiles, pathArch);
DeleteFiles(compressedFiles);
}
void SParch::DeleteFiles(vector<string> files) {
for (vector<string>::iterator it = files.begin(); it != files.end(); ++it) {
string fileName = *(it);
remove(fileName.c_str());
}
}
void SParch::Decompression(string cFilePath, string dFilePath) {
vector<string> cFiles;
cFiles = ar->Decompression(cFilePath, dFilePath);
for (vector<string>::iterator it = cFiles.begin(); it != cFiles.end(); ++it) {
string filePath = *(it);
cout << "Compressed files: " << endl;
cout << filePath << endl;
int l_pos = filePath.rfind("/");
int d_pos = filePath.rfind(".");
string fileName = filePath.substr(l_pos + 1, (d_pos - l_pos - 1));
string dFileName = dFilePath + fileName;
cout << "Decompressed files: " << endl;
cout << dFileName << endl;
bH->Decompression(filePath, dFilePath + fileName);
}
DeleteFiles(cFiles);
}