mirror of
https://github.com/QuasarApp/zip.git
synced 2025-05-02 15:19:34 +00:00
Add example how to compress a folder.
This commit is contained in:
parent
529eef88ad
commit
59b7942cd8
32
README.md
32
README.md
@ -172,6 +172,38 @@ for (i = 0; i < n; ++i) {
|
|||||||
zip_close(zip);
|
zip_close(zip);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Compress folder (recursively)
|
||||||
|
```c
|
||||||
|
void zip_walk(struct zip_t *zip, const char *path) {
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *entry;
|
||||||
|
char fullpath[MAX_PATH];
|
||||||
|
struct stat s;
|
||||||
|
|
||||||
|
memset(fullpath, 0, MAX_PATH);
|
||||||
|
dir = opendir(path);
|
||||||
|
assert(dir);
|
||||||
|
|
||||||
|
while ((entry = readdir(dir))) {
|
||||||
|
// skip "." and ".."
|
||||||
|
if (!strcmp(entry->d_name, ".\0") || !strcmp(entry->d_name, "..\0"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
snprintf(fullpath, sizeof(fullpath), "%s/%s", path, entry->d_name);
|
||||||
|
stat(path, &s);
|
||||||
|
if (S_ISDIR(s.st_mode))
|
||||||
|
zip_walk(zip, fullpath);
|
||||||
|
else {
|
||||||
|
zip_entry_open(zip, fullpath);
|
||||||
|
zip_entry_fwrite(zip, fullpath);
|
||||||
|
zip_entry_close(zip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# Bindings
|
# Bindings
|
||||||
Compile zip library as a dynamic library.
|
Compile zip library as a dynamic library.
|
||||||
```shell
|
```shell
|
||||||
|
Loading…
x
Reference in New Issue
Block a user