forked from ctabin/libzippp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
178 lines (123 loc) · 4.2 KB
/
README
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
= ======== =
= libzippp =
= ======== =
libzippp is a simple basic C++ wrapper around the libzip library.
It is meant to be a portable and easy-to-use library for Zip handling.
Compilation works with:
- gcc 4.7.3
- MS Visual Studio 2012
= ============ =
= Compilation =
= ============ =
-----
LINUX
-----
0) make sure you have the following commands: g++ make tar wget
1) download and compile de libzip library with the following command:
make libzip
2) then create the static and shared libraries of libzippp:
make
3) you may want to run the tests:
make tests
4) now you just have to include the src folder in your include path and
link against libzippp.a or libzippp.so (do not forget to also link
against libzip libraries in lib/libzip-0.11.2/lib/.libs/).
An example of compilation with g++ (note also the -lz at the end) :
g++ -I./lib/libzip-0.11.2/lib -I./src \
main.cpp libzippp.a \
lib/libzip-0.11.2/lib/.libs/libzip.a \
-lz
-------
WINDOWS
-------
0) make sure you have cmake (cmake.exe must be in the PATH) and MS Visual
Studio 2012. The dev command prompt path should be (defined in compile.bat):
<MSVS11>\Common7\Tools\VsDevCmd.bat
1) download libzip and zlib and extract them in a folder called 'lib'.
you should have the following structure:
libzippp/compile.bat
libzippp/lib/zlib-1.2.8
libzippp/lib/libzip-0.11.2
2) execute the compile.bat (simply double-click on it). the compilation should
go without error.
3) you'll have a 'dist' folder containing the 'release' and 'debug' folders
where you can now execute the libzippp tests.
4) you can either use libzippp.dll and libzippp.lib to link dynamically the
library or simply use libzippp_static.lib to link it statically. Unless you
also link zlib and libzippp statically, you'll need the dll packaged with
your executable.
= ===== =
= Usage =
= ===== =
The API is meant to be very straight forward. Some french explanations
can be found here: http://www.astorm.ch/blog
How to list and read files in an archive:
#include "libzippp.h"
using namespace libzippp;
ZipArchive zf("archive.zip");
zf.open(ZipArchive::READ_ONLY);
vector<ZipEntry> entries = zf.getEntries();
vector<ZipEntry>::iterator it;
for(it=entries.begin() ; it!=entries.end(); ++it) {
ZipEntry entry = *it;
string name = entry.getName();
int size = entry.getSize();
//the length of binaryData will be size
void* binaryData = entry.readAsBinary();
//the length of textData will be size
string textData = entry.readAsText();
//...
}
zf.close();
How to read a specific entry from an archive:
#include "libzippp.h"
using namespace libzippp;
ZipArchive zf("archive.zip");
zf.open(ZipArchive::READ_ONLY);
//direct way
char* data = (char*)zf.readEntry("myFile.txt", true);
string str1(data, entry.getSize());
//indirect way
ZipEntry entry = zf.getEntry("myFile.txt");
string str2 = entry.readAsText();
zf.close();
How to add data to an archive:
#include "libzippp.h"
using namespace libzippp;
ZipArchive zf("archive.zip");
zf.open(ZipArchive::WRITE);
zf.addEntry("folder/subdir/");
const char* textData = "Hello,World!";
zf.addData("helloworld.txt", textData, 12);
zf.close();
How to remove data from an archive:
#include "libzippp.h"
using namespace libzippp;
ZipArchive zf("archive.zip");
zf.open(ZipArchive::WRITE);
zf.deleteEntry("myFile.txt");
zf.deleteEntry("myDir/subDir/");
zf.close();
= ====== =
= TODO =
= ====== =
- Extra field handling
= ====== =
= ISSUES =
= ====== =
-----
LINUX
-----
You might already have libzip compiled elsewhere on your system. Hence, you
don't need to run 'make libzip'. Instead, just put the libzip location when
you compile libzipp:
make LIBZIP=path/to/libzip
-------
WINDOWS
-------
By default, MS Visual Studio 2012 is installed under the following path:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\
Be aware that non-virtual-only classes are shared within the DLL of libzippp.
Hence you'll need to use the same compiler for libzippp and the pieces of code
that will use it. To avoid this issue, you'll have to link the library statically.
More information: http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL