Skip to content

Commit 2d25730

Browse files
committed
Better README
1 parent e36fff2 commit 2d25730

1 file changed

Lines changed: 53 additions & 104 deletions

File tree

README.md

Lines changed: 53 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,152 +2,101 @@
22

33
[![CI](https://github.com/trufae/mzip/actions/workflows/ci.yml/badge.svg)](https://github.com/trufae/mzip/actions/workflows/ci.yml)
44

5-
This is a minimalistic implementation of the ZIP file format, designed to be small, portable, and dependency-free.
6-
7-
**NOTE** This code has been initially written by Claude Code
5+
A minimalistic, dependency-free ZIP implementation with support for multiple compression algorithms.
86

97
## Features
108

11-
- Small library with minimal dependencies
12-
- Full read/write support for ZIP archives
13-
- Zero dependencies (includes a tiny deflate implementation)
14-
- Simple API compatible with a subset of libzip
15-
- Suitable for embedded systems and small applications
16-
17-
## Configuration
18-
19-
The library can be configured by editing `config.h`. You can enable or disable specific compression algorithms based on your needs:
20-
21-
```c
22-
/* Enable/disable compression algorithms */
23-
#define MZIP_ENABLE_STORE 1 /* Always include store method */
24-
#define MZIP_ENABLE_DEFLATE 1 /* Include DEFLATE compression */
25-
#define MZIP_ENABLE_ZSTD 1 /* Include ZSTD compression */
26-
#define MZIP_ENABLE_LZFSE 1 /* LZFSE compression support */
27-
/* #define MZIP_ENABLE_LZ4 1 */ /* LZ4 compression (commented out by default) */
28-
#define MZIP_ENABLE_LZMA 1 /* LZMA compression support */
29-
#define MZIP_ENABLE_BROTLI 1 /* Brotli compression support */
30-
```
31-
32-
## Components
33-
34-
The implementation consists of the following main parts:
35-
36-
1. `mzip.c` - Minimalistic libzip subset replacement
37-
2. `deflate.inc.c` - Minimalistic deflate (RFC 1951) implementation compatible with zlib API
38-
3. `zstd.inc.c` - Minimalistic zstd implementation
39-
4. `lzma.inc.c` - Lightweight LZMA compression implementation
40-
5. `brotli.inc.c` - Brotli compression implementation
41-
6. `lzfse.inc.c` - Apple's LZFSE compression implementation
42-
7. `config.h` - Configuration options for enabling/disabling compression methods
9+
- Small, portable library with zero dependencies
10+
- Full ZIP read/write support
11+
- Multiple compression algorithms (DEFLATE, ZSTD, LZMA, Brotli, LZFSE)
12+
- Simple API compatible with libzip subset
13+
- Suitable for embedded systems
4314

4415
## Building
4516

46-
To build the library:
47-
4817
```bash
49-
# Configure which algorithms to include in config.h first
50-
# Edit config.h to enable or disable specific compression methods
18+
# Build default binary
19+
make
20+
21+
# Build with all compression algorithms
22+
make all-compression
23+
24+
# Install
25+
make install
5126

52-
# Then compile
53-
gcc -std=c99 -c -DMZIP_IMPLEMENTATION mzip.c
54-
gcc -o mzip mzip.o
27+
# Run tests
28+
make -C test
5529
```
5630

5731
## Usage
5832

33+
### Library API
34+
5935
```c
60-
#include "mzip.c" // This includes deflate.c internally
36+
#include "mzip.h"
6137

62-
// Open a zip file
63-
int err = 0;
38+
// Open ZIP file
6439
zip_t *za = zip_open("archive.zip", ZIP_RDONLY, &err);
6540

6641
// Read files
67-
zip_uint64_t n = zip_get_num_files(za);
68-
for (zip_uint64_t i = 0; i < n; ++i) {
42+
zip_uint64_t num_files = zip_get_num_files(za);
43+
for (zip_uint64_t i = 0; i < num_files; ++i) {
6944
zip_file_t *zf = zip_fopen_index(za, i, 0);
70-
// Use zf->data and zf->size
45+
// Process zf->data and zf->size
7146
zip_fclose(zf);
7247
}
7348

74-
// Add files
49+
// Create ZIP file
7550
zip_t *za_write = zip_open("new.zip", ZIP_CREATE, &err);
76-
void *buffer = malloc(size);
77-
// Fill buffer with data
7851
zip_source_t *src = zip_source_buffer(za_write, buffer, size, 1);
79-
zip_int64_t index = zip_file_add(za_write, "filename.txt", src, 0);
80-
81-
// Set compression method (you can use any supported method)
82-
zip_set_file_compression(za_write, index, MZIP_METHOD_ZSTD, 0); // For zstd compression
83-
// Other available methods:
84-
// zip_set_file_compression(za_write, index, MZIP_METHOD_LZMA, 0); // For LZMA compression
85-
// zip_set_file_compression(za_write, index, MZIP_METHOD_BROTLI, 0); // For Brotli compression
86-
// zip_set_file_compression(za_write, index, MZIP_METHOD_LZFSE, 0); // For LZFSE compression
87-
// zip_set_file_compression(za_write, index, MZIP_METHOD_STORE, 0); // For no compression
52+
zip_file_add(za_write, "file.txt", src, 0);
53+
zip_set_file_compression(za_write, index, MZIP_METHOD_ZSTD, 0);
8854
zip_close(za_write);
89-
90-
// Close when done
91-
zip_close(za);
9255
```
9356
94-
## Tool Usage
95-
96-
The included `mzip` tool demonstrates the library's functionality:
57+
### Command Line Tool
9758
9859
```bash
9960
# List contents
10061
./mzip -l archive.zip
10162
102-
# Extract all files
63+
# Extract files
10364
./mzip -x archive.zip
10465
105-
# Create new archive
66+
# Create archive
10667
./mzip -c archive.zip file1 file2
10768
108-
# Add files to existing archive
109-
./mzip -a archive.zip file3 file4
69+
# Add files
70+
./mzip -a archive.zip file3
11071
```
11172

112-
## Limitations
113-
114-
- No support for encryption, ZIP64, or data descriptors
115-
- Current implementation has limited support for extracting multiple files
116-
- Limited testing with third-party ZIP utilities when using non-standard compression methods
117-
118-
## License
119-
120-
MIT / 0-BSD – do whatever you want; attribution appreciated.
73+
## Configuration
12174

122-
## Compression
75+
Edit `config.h` to enable/disable compression algorithms:
12376

124-
mzip now supports the following compression algorithms used by Apple and Google for mobile app packaging:
77+
```c
78+
#define MZIP_ENABLE_DEFLATE 1
79+
#define MZIP_ENABLE_ZSTD 1
80+
#define MZIP_ENABLE_LZMA 1
81+
#define MZIP_ENABLE_BROTLI 1
82+
#define MZIP_ENABLE_LZFSE 1
83+
```
12584
126-
1. **DEFLATE** (Method ID: 8): Used in both APK and IPA files
127-
- Default ZIP compression algorithm
128-
- Good compatibility with all ZIP tools
129-
- Standard in most ZIP implementations
85+
## Supported Compression Algorithms
13086
131-
2. **Zstandard (zstd)** (Method ID: 93): Increasingly adopted by Google (Android 12+)
132-
- Better balance of compression ratio and speed
133-
- Significantly faster decompression than DEFLATE
134-
- Scalable compression levels
87+
- **DEFLATE** (ID: 8): Standard ZIP compression
88+
- **ZSTD** (ID: 93): Fast, high compression
89+
- **LZMA** (ID: 14): High compression ratio
90+
- **Brotli** (ID: 97): Better than DEFLATE for static content
91+
- **LZFSE** (ID: 100): Apple's mobile-optimized algorithm
92+
- **STORE** (ID: 0): No compression
13593
136-
3. **LZFSE** (Method ID: 100): Apple's proprietary algorithm used in newer IPA files
137-
- Optimized for mobile hardware
138-
- Battery efficient
139-
- Good balance of compression and speed
94+
## Limitations
14095
141-
4. **Brotli** (Method ID: 97): Used by Google in newer Android versions
142-
- Better compression ratios than DEFLATE (20-26% better)
143-
- Good for static content in apps
96+
- No encryption or ZIP64 support
97+
- Limited multi-file extraction
98+
- Non-standard methods may not work with all ZIP tools
14499
145-
5. **LZMA** (Method ID: 14): Occasionally used for specific resources
146-
- Higher compression ratios
147-
- Slower decompression
148-
149-
6. **STORE** (Method ID: 0): No compression
150-
- Raw file storage without compression
151-
- Used as a fallback when compression doesn't reduce file size
100+
## License
152101
153-
Support for **LZ4** (Method ID: 94) is included in the codebase but disabled by default. It can be enabled in config.h.
102+
MIT / 0-BSD

0 commit comments

Comments
 (0)