-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (45 loc) · 1.6 KB
/
main.cpp
File metadata and controls
52 lines (45 loc) · 1.6 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
#include <zippuccino/zipper.h>
int main(int argc, char **argv) {
zippuccino::Zipper zipper;
zipper.add("../example");
zipper.add("../include");
zipper.add("../lib");
zipper.add("../src");
zipper.add("../CMakeLists.txt");
zipper.add("../README.md");
zipper.add("../LICENSE");
zipper.add("../.gitignore");
zipper.add("../.gitmodules");
zipper.zip();
const std::string zipPath = "../zippuccino.zip";
std::ofstream zipFile(zipPath, std::ios::binary);
if (!zipFile.is_open()) {
std::cerr << "Unable to open output file" << std::endl;
return EXIT_FAILURE;
}
logger::success("Creating zip file " + zipPath);
logger::success("Estimated size: " + std::to_string(zipper.getSize()) +
" bytes");
while (!zipper.isFinished()) {
const std::string header = zipper.getHeader();
zipFile.write(header.c_str(), header.size());
std::string path = zipper.getCurrentFile();
std::ifstream file(path, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Unable to open file: " << path << std::endl;
return EXIT_FAILURE;
}
std::copy(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(zipFile));
file.close();
logger::info("Added file: " + path);
}
const std::string footer = zipper.getFooter();
zipFile.write(footer.c_str(), footer.size());
zipFile.close();
logger::success("Zip file created successfully");
logger::success("Final zip size: " +
std::to_string(brewtils::os::file::size(zipPath)) + " bytes");
return EXIT_SUCCESS;
}