Module: compress.zip
Source: ./compress/zip.reef
Overview
compress/zip - ZIP archive handling using libzip FFI
This module provides ZIP archive creation and extraction using the system's libzip library via FFI.
IMPORTANT: This module requires the libzip library (-lzip) to be linked. Install: apt install libzip-dev (Debian/Ubuntu)
Usage: import compress.zip unsafe // Create a zip archive let zip = zipfile_open("/tmp/test.zip", ZIPF_CREATE()) zipfile_add(zip, "hello.txt", data, len) zipfile_close(zip)
// Extract from a zip archive let zip = zipfile_open("/tmp/test.zip", 0) let count = zipfile_num_entries(zip) // ... iterate and read entries zipfile_close(zip) end unsafe
Functions
fn zip_open(path: pointer, flags: int, errorp: pointer): pointer
libzip FFI functions Note: These use libzip's API. Link with -lzip
fn zip_close(archive: pointer): int
fn zip_get_num_entries(archive: pointer, flags: int): int
fn zip_get_name(archive: pointer, index: int, flags: int): pointer
fn zip_source_buffer(archive: pointer, data: pointer, len: int, freep: int): pointer
fn zip_file_add(archive: pointer, name: pointer, source: pointer, flags: int): int
fn zip_fopen_index(archive: pointer, index: int, flags: int): pointer
fn zip_fread(file: pointer, buf: pointer, nbytes: int): int
fn zip_fclose(file: pointer): int
fn zip_stat_index(archive: pointer, index: int, flags: int, sb: pointer): int
fn ZIPF_CREATE(): int
fn ZIPF_EXCL(): int
fn ZIPF_TRUNCATE(): int
fn ZIPF_RDONLY(): int
fn zipfile_open(path: string, flags: int): pointer
Open a ZIP archive flags: combination of ZIPF_CREATE, ZIPF_EXCL, ZIPF_TRUNCATE, ZIPF_RDONLY Returns NULL on error
fn zipfile_close(zip: pointer): int
Close a ZIP archive, writing changes if any Returns 0 on success, -1 on error
fn zipfile_num_entries(zip: pointer): int
Get the number of entries in the archive
fn zipfile_entry_name(zip: pointer, index: int): string
Get the name of an entry by index
fn zipfile_add(zip: pointer, name: string, data: [uint8], len: int): int
Add a file to the archive from a buffer Returns the index of the new entry, or -1 on error
fn zipfile_entry_open(zip: pointer, index: int): pointer
Open an entry for reading by index
fn zipfile_entry_read(file: pointer, buf: [uint8], len: int): int
Read from an open entry Returns number of bytes read, or -1 on error
fn zipfile_entry_close(file: pointer): int
Close an entry
fn zipfile_entry_size(zip: pointer, index: int, size_out: [int]): int
Get the size of an entry size_out[0] will contain the uncompressed size Returns 0 on success, -1 on error
Procedures
proc zip_discard(archive: pointer)
proc zipfile_discard(zip: pointer)
Discard a ZIP archive without writing changes
Generated by reefc doc