Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: build

permissions:
contents: read

on: [push, pull_request]

jobs:
Expand Down Expand Up @@ -72,3 +75,31 @@ jobs:
run: |
cd build
ctest -VV -C "Debug" --output-on-failure

compile-flags:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: no-inflate
flags: -DZIP_ENABLE_INFLATE=OFF
- name: no-deflate
flags: -DZIP_ENABLE_DEFLATE=OFF
- name: no-symlink
flags: -DZIP_HAVE_SYMLINK=OFF
- name: no-inflate-no-deflate
flags: -DZIP_ENABLE_INFLATE=OFF -DZIP_ENABLE_DEFLATE=OFF
- name: no-inflate-no-symlink
flags: -DZIP_ENABLE_INFLATE=OFF -DZIP_HAVE_SYMLINK=OFF
- name: no-deflate-no-symlink
flags: -DZIP_ENABLE_DEFLATE=OFF -DZIP_HAVE_SYMLINK=OFF
- name: all-disabled
flags: -DZIP_ENABLE_INFLATE=OFF -DZIP_ENABLE_DEFLATE=OFF -DZIP_HAVE_SYMLINK=OFF
name: compile-flags (${{ matrix.name }})
steps:
- uses: actions/checkout@v2
- name: Configure
run: cmake -DCMAKE_DISABLE_TESTING=ON ${{ matrix.flags }} -S . -B build
- name: Build
run: cmake --build build
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ option(ZIP_STATIC_PIC "Build static zip with PIC" ON)
option(ZIP_BUILD_DOCS "Generate API documentation with Doxygen" OFF)
option(ZIP_BUILD_FUZZ "Build fuzz targets" OFF)
option(ZIP_BUILD_TOOLS "Build command-line tools (zipcli, unzipcli)" OFF)
option(ZIP_ENABLE_INFLATE "Enable decompression / extraction support" ON)
option(ZIP_ENABLE_DEFLATE "Enable compression / archive creation support" ON)
option(ZIP_HAVE_SYMLINK "Enable symlink support during extraction" ON)

if(ZIP_ENABLE_SHARABLE_FILE_OPEN)
add_definitions(-DZIP_ENABLE_SHARABLE_FILE_OPEN)
endif()


if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# large file support
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64)
Expand Down Expand Up @@ -50,6 +54,16 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:include>
)

if(NOT ZIP_ENABLE_INFLATE)
target_compile_definitions(${PROJECT_NAME} PUBLIC ZIP_ENABLE_INFLATE=0)
endif()
if(NOT ZIP_ENABLE_DEFLATE)
target_compile_definitions(${PROJECT_NAME} PUBLIC ZIP_ENABLE_DEFLATE=0)
endif()
if(NOT ZIP_HAVE_SYMLINK)
target_compile_definitions(${PROJECT_NAME} PUBLIC ZIP_HAVE_SYMLINK=0)
endif()

# test
if (NOT CMAKE_DISABLE_TESTING)
enable_testing()
Expand Down
55 changes: 45 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ zip_stream_close(zip);
free(outbuf);
```

* Extract a zip entry into a memory (stream API).
* Extract a zip entry into memory (stream API).

```c
char *buf = NULL;
Expand Down Expand Up @@ -225,8 +225,6 @@ struct zip_t *zip = zip_open("foo.zip", 0, 'r');
zip_entry_close(zip);
}
zip_close(zip);

free(buf);
```

* List of all zip entries
Expand Down Expand Up @@ -756,21 +754,58 @@ data = zip.zip_stream_copy(z)
zip.zip_close(z)
```

### Optional features

The library supports three compile-time flags to strip unused functionality and reduce binary size.
All features are **enabled by default** -- if you just drop the source files into your project and compile, everything works as before.

| Flag | Default | Effect when disabled (`=0`) |
|---|---|---|
| `ZIP_ENABLE_DEFLATE` | `1` | Removes compression / archive-writing APIs (`zip_entry_write`, `zip_entry_fwrite`, `zip_create`, `zip_entries_delete`, …). Write and append modes (`'w'`, `'a'`, `'d'`) return an error. |
| `ZIP_ENABLE_INFLATE` | `1` | Removes decompression / extraction APIs (`zip_entry_read`, `zip_entry_fread`, `zip_entry_extract`, `zip_extract`, `zip_stream_extract`, …). Read mode (`'r'`) returns an error. |
| `ZIP_HAVE_SYMLINK` | `1` (Unix/macOS), `0` (Windows) | When disabled, symlink entries are extracted as regular file copies instead of creating actual symlinks. |

**With CMake:**

```shell
# Extract-only build (no compression)
cmake .. -DZIP_ENABLE_DEFLATE=OFF

# Compress-only build (no extraction)
cmake .. -DZIP_ENABLE_INFLATE=OFF

# Disable symlink support
cmake .. -DZIP_HAVE_SYMLINK=OFF
```

**Without CMake** (compiler flags):

```shell
cc -DZIP_ENABLE_DEFLATE=0 -c zip.c
```

Or define before including the header:

```c
#define ZIP_ENABLE_DEFLATE 0
#include "zip.h"
```

### No ZIP64

By default, opening an archive for writing with the literal mode character 'w' will enable ZIP64 output.
Internally the library sets a write flag when the mode equals the literal 'w':
By default, opening an archive for writing with the literal mode character `'w'` will enable ZIP64 output.
Internally the library sets a write flag when the mode equals the literal `'w'`:

```zip/src/zip.c#L948-956
```c
mz_uint wflags = (mode == 'w') ? MZ_ZIP_FLAG_WRITE_ZIP64 : 0;
```

To ensure the produced ZIP archive is _NOT ZIP64_, use the alternate mode value that selects the same semantic mode but does not compare equal to the literal 'w'.
The implementation accepts an alternate value in the switch labels (so the same behavior is selected), but only the literal 'w' triggers the automatic ZIP64 flag.
To ensure the produced ZIP archive is _NOT ZIP64_, use the alternate mode value that selects the same semantic mode but does not compare equal to the literal `'w'`.
The implementation accepts an alternate value in the switch labels (so the same behavior is selected), but only the literal `'w'` triggers the automatic ZIP64 flag.

Convention:
- Use 'w' - 64 (integer value 55) when calling zip_open, zip_stream_open, etc., to select write mode without enabling ZIP64.
- The same pattern applies to other modes: use 'r' - 64, 'a' - 64, 'd' - 64 to pick the non-ZIP64 variants.
- Use `'w' - 64` (integer value 55) when calling `zip_open`, `zip_stream_open`, etc., to select write mode without enabling ZIP64.
- The same pattern applies to other modes: use `'r' - 64`, `'a' - 64`, `'d' - 64` to pick the non-ZIP64 variants.

### Check out more cool projects which use this library

Expand Down
Loading
Loading