CSEngine
Loading...
Searching...
No Matches
zip.h
1/*
2 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
3 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
5 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
6 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
7 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
8 * OTHER DEALINGS IN THE SOFTWARE.
9 */
10
11#pragma once
12#ifndef ZIP_H
13#define ZIP_H
14
15#include <string.h>
16#include <sys/types.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#if !defined(_POSIX_C_SOURCE) && defined(_MSC_VER)
23// 64-bit Windows is the only mainstream platform
24// where sizeof(long) != sizeof(void*)
25#ifdef _WIN64
26typedef long long ssize_t; /* byte count or error */
27#else
28typedef long ssize_t; /* byte count or error */
29#endif
30#endif
31
32#ifndef MAX_PATH
33#define MAX_PATH 32767 /* # chars in a path name including NULL */
34#endif
35
50#define ZIP_DEFAULT_COMPRESSION_LEVEL 6
51
55#define ZIP_ENOINIT -1 // not initialized
56#define ZIP_EINVENTNAME -2 // invalid entry name
57#define ZIP_ENOENT -3 // entry not found
58#define ZIP_EINVMODE -4 // invalid zip mode
59#define ZIP_EINVLVL -5 // invalid compression level
60#define ZIP_ENOSUP64 -6 // no zip 64 support
61#define ZIP_EMEMSET -7 // memset error
62#define ZIP_EWRTENT -8 // cannot write data to entry
63#define ZIP_ETDEFLINIT -9 // cannot initialize tdefl compressor
64#define ZIP_EINVIDX -10 // invalid index
65#define ZIP_ENOHDR -11 // header not found
66#define ZIP_ETDEFLBUF -12 // cannot flush tdefl buffer
67#define ZIP_ECRTHDR -13 // cannot create entry header
68#define ZIP_EWRTHDR -14 // cannot write entry header
69#define ZIP_EWRTDIR -15 // cannot write to central dir
70#define ZIP_EOPNFILE -16 // cannot open file
71#define ZIP_EINVENTTYPE -17 // invalid entry type
72#define ZIP_EMEMNOALLOC -18 // extracting data using no memory allocation
73#define ZIP_ENOFILE -19 // file not found
74#define ZIP_ENOPERM -20 // no permission
75#define ZIP_EOOMEM -21 // out of memory
76#define ZIP_EINVZIPNAME -22 // invalid zip archive name
77#define ZIP_EMKDIR -23 // make dir error
78#define ZIP_ESYMLINK -24 // symlink error
79#define ZIP_ECLSZIP -25 // close archive error
80#define ZIP_ECAPSIZE -26 // capacity size too small
81#define ZIP_EFSEEK -27 // fseek error
82#define ZIP_EFREAD -28 // fread error
83#define ZIP_EFWRITE -29 // fwrite error
84
91extern const char *zip_strerror(int errnum);
92
99struct zip_t;
100
113extern struct zip_t *zip_open(const char *zipname, int level, char mode);
114
120extern void zip_close(struct zip_t *zip);
121
130extern int zip_is64(struct zip_t *zip);
131
144extern int zip_entry_open(struct zip_t *zip, const char *entryname);
145
156extern int zip_entry_openbyindex(struct zip_t *zip, int index);
157
165extern int zip_entry_close(struct zip_t *zip);
166
181extern const char *zip_entry_name(struct zip_t *zip);
182
190extern int zip_entry_index(struct zip_t *zip);
191
200extern int zip_entry_isdir(struct zip_t *zip);
201
209extern unsigned long long zip_entry_size(struct zip_t *zip);
210
218extern unsigned int zip_entry_crc32(struct zip_t *zip);
219
229extern int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize);
230
239extern int zip_entry_fwrite(struct zip_t *zip, const char *filename);
240
256extern ssize_t zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize);
257
274extern ssize_t zip_entry_noallocread(struct zip_t *zip, void *buf,
275 size_t bufsize);
276
285extern int zip_entry_fread(struct zip_t *zip, const char *filename);
286
297extern int
299 size_t (*on_extract)(void *arg, unsigned long long offset,
300 const void *data, size_t size),
301 void *arg);
302
311extern int zip_entries_total(struct zip_t *zip);
312
321extern int zip_entries_delete(struct zip_t *zip, char *const entries[],
322 size_t len);
323
341extern int zip_stream_extract(const char *stream, size_t size, const char *dir,
342 int (*on_extract)(const char *filename,
343 void *arg),
344 void *arg);
345
354extern struct zip_t *zip_stream_open(const char *stream, size_t size, int level,
355 char mode);
356
366extern ssize_t zip_stream_copy(struct zip_t *zip, void **buf, ssize_t *bufsize);
367
375extern void zip_stream_close(struct zip_t *zip);
376
386extern int zip_create(const char *zipname, const char *filenames[], size_t len);
387
404extern int zip_extract(const char *zipname, const char *dir,
405 int (*on_extract_entry)(const char *filename, void *arg),
406 void *arg);
407
409#ifdef __cplusplus
410}
411#endif
412
413#endif
int zip_is64(struct zip_t *zip)
Definition zip.cpp:849
unsigned long long zip_entry_size(struct zip_t *zip)
Definition zip.cpp:1201
ssize_t zip_stream_copy(struct zip_t *zip, void **buf, ssize_t *bufsize)
Definition zip.cpp:1517
int zip_entry_isdir(struct zip_t *zip)
Definition zip.cpp:1186
const char * zip_entry_name(struct zip_t *zip)
Definition zip.cpp:1168
struct zip_t * zip_open(const char *zipname, int level, char mode)
Definition zip.cpp:779
void zip_stream_close(struct zip_t *zip)
Definition zip.cpp:1533
int zip_entry_fread(struct zip_t *zip, const char *filename)
Definition zip.cpp:1346
int zip_entry_index(struct zip_t *zip)
Definition zip.cpp:1177
struct zip_t * zip_stream_open(const char *stream, size_t size, int level, char mode)
Definition zip.cpp:1481
int zip_entry_extract(struct zip_t *zip, size_t(*on_extract)(void *arg, unsigned long long offset, const void *data, size_t size), void *arg)
const char * zip_strerror(int errnum)
Definition zip.cpp:140
int zip_entry_fwrite(struct zip_t *zip, const char *filename)
Definition zip.cpp:1247
ssize_t zip_entry_noallocread(struct zip_t *zip, void *buf, size_t bufsize)
Definition zip.cpp:1324
unsigned int zip_entry_crc32(struct zip_t *zip)
Definition zip.cpp:1205
int zip_create(const char *zipname, const char *filenames[], size_t len)
Definition zip.cpp:1541
void zip_close(struct zip_t *zip)
Definition zip.cpp:836
int zip_entry_open(struct zip_t *zip, const char *entryname)
Definition zip.cpp:858
int zip_entry_openbyindex(struct zip_t *zip, int index)
Definition zip.cpp:1014
int zip_extract(const char *zipname, const char *dir, int(*on_extract_entry)(const char *filename, void *arg), void *arg)
Definition zip.cpp:1601
int zip_entries_total(struct zip_t *zip)
Definition zip.cpp:1417
int zip_entry_close(struct zip_t *zip)
Definition zip.cpp:1087
int zip_entry_write(struct zip_t *zip, const void *buf, size_t bufsize)
Definition zip.cpp:1209
ssize_t zip_entry_read(struct zip_t *zip, void **buf, size_t *bufsize)
Definition zip.cpp:1295
int zip_entries_delete(struct zip_t *zip, char *const entries[], size_t len)
Definition zip.cpp:1426
int zip_stream_extract(const char *stream, size_t size, const char *dir, int(*on_extract)(const char *filename, void *arg), void *arg)
Definition zip.cpp:1461
Definition zip.cpp:88