-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddFile.hpp
120 lines (67 loc) · 2.37 KB
/
AddFile.hpp
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
//
// Created by Birkee o
//
#ifndef ADDFILE_HPP
#define ADDFILE_HPP
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <chrono>
#include <ctime>
#include <cstdio>
#include <cerrno>
#include <sys/stat.h>
#include <unistd.h>
#include <stdexcept>
#include <cmath> /* ceil */
//#include "Huffman.cpp"
//#include "huffman.h"
class AddFile
{
public:
explicit AddFile(std::vector<std::string> suffixes);
explicit AddFile(std::string &arch);
void add(std::string& filein);
AddFile& addFiles();
long blockSize = 1 * 20;
long pointerSize = 10;
inline static bool exists_test (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
void generateNewArchive(std::string& filein, std::string& content, long& length, std::string& filename,
std::string& time);
void addFileToArchive(std::string& filein, std::string& content, long& length, std::string& filename,
std::string& time);
/*
* void generateNewArchive(std::string& filein, std::string& content, long& length, std::string& filename,
std::string& time);
void addFileToArchive(std::string& filein, std::string& content, long& length, std::string& filename,
std::string& time);
static inline std::string tail(std::string const& source, size_t const length) {
if (length >= source.size()) { return source; }
return source.substr(source.size() - length);
} // tail
*/
protected:
std::string archive;
std::vector<std::string> files;
//std::string root = "./";
std::string generateLog(const std::string &filename, long &size, const std::string& block, std::string& time);
inline std::string generateHelper(const std::string& line);
};
class Header
{
public:
explicit Header(std::string& header);
std::vector<int> getBlockForFile(std::string &filename);
std::vector<int> getAvailableBlock();
std::string getInformationForFile(std::string& filename);
Header& parseAll();
std::vector<std::string> filenames;
std::string header;
};
#endif //ECE180_ADDFILE_HPP