-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
118 lines (96 loc) · 3.17 KB
/
Copy pathmain.cpp
File metadata and controls
118 lines (96 loc) · 3.17 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
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
#include <iostream>
#include "zlib.h"
#include "JlCompress.h"
#include <stdio.h>
#include <string.h>
using namespace std;
unsigned long file_size(char *filename) {
FILE *pFile = fopen(filename,"rb");
fseek (pFile, 0, SEEK_END);
unsigned long size = static_cast<unsigned long>(ftell(pFile));
fclose (pFile);
return size;
}
int decompress_one_file(char *infilename, char *outfilename) {
gzFile infile = gzopen(infilename, "rb");
FILE *outfile = fopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char buffer[128];
int num_read = 0;
while ((num_read = gzread(infile, buffer, sizeof(buffer))) > 0) {
fwrite(buffer, 1, static_cast<unsigned long long>(num_read), outfile);
}
gzclose(infile);
fclose(outfile);
return 0;
}
int compress_one_file(char *infilename, char *outfilename)
{
FILE *infile = fopen(infilename, "rb");
gzFile outfile = gzopen(outfilename, "wb");
if (!infile || !outfile) return -1;
char inbuffer[128];
int num_read = 0;
unsigned long total_read = 0;
//unsigned long total_wrote = 0;
while ((num_read = static_cast<int>(fread(inbuffer, 1, sizeof(inbuffer), infile))) > 0) {
total_read += static_cast<unsigned long>(num_read);
gzwrite(outfile, inbuffer, static_cast<unsigned int>(num_read));
}
fclose(infile);
gzclose(outfile);
printf("Read %ld bytes, Wrote %ld bytes,Compression factor %4.2f%%\n",
total_read, file_size(outfilename),
(1.0-file_size(outfilename)*1.0/total_read)*100.0);
return 0;
}
int main(int argc, char **argv)
{
//Byte *compr, *uncompr;
//uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
//uLong uncomprLen = comprLen;
//static const char* myVersion = ZLIB_VERSION;
//
//if (zlibVersion()[0] != myVersion[0]) {
// fprintf(stderr, "incompatible zlib version\n");
//
// exit(1);
//
//} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
// fprintf(stderr, "warning: different zlib version\n");
//
//} else {
// printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n", ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
//}
//
//compr = (Byte*)calloc((uInt)comprLen, 1);
//uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
///* compr and uncompr are cleared to avoid reading uninitialized
// * data and to ensure that uncompr compresses well.
// */
//if (compr == nullptr || uncompr == nullptr) {
// printf("out of memory\n");
// exit(1);
//}
//
if (argc == 3){
QString sZipName = argv[1];
sZipName += ".zip";
//QuaZip zip(sZipName);
////zip.setZip64Enabled(true);
////zip.setComment("By Lara");
//zip.open(QuaZip::mdCreate);
JlCompress::compressDir(sZipName , argv[2],true);
cout << "Si compressDir" << endl;
//zip.close();
return 0;
}
if (argc < 4) {
cout << "TestZipLib <fileToZip.txt> <zipName.zip> <decompressName.txt>" << endl;
exit(1);
}
compress_one_file(argv[1],argv[2]);
decompress_one_file(argv[2],argv[3]);
cout << "Hello World!" << endl;
return 0;
}