0.13.68 Library - ZIP Access - Transparently - SDLrwops Example - ext/io Customization xor/io Obfuscation zip/no Encryption (2) - Library API basics extras =Parsing ZIPs - 64on32 extras - Next To Come fseeko mmapped memdisk - Config Helpers - Making a zip/exe =Hints And Links - Referentials - Functions List.. - zziplib.* - zzipmmapped.* - zzipfseeko.* - unix man pages   faq notes zip-php Download Area Developer Area GitHub Project Old SF Project zziplib.sf.net Home ChangeLog LGPL/MPL license -sitemap-
generated 2018-02-05
formatted by mksite.sh as xml: Library - 64on32 extras - Next To Come |
Now hosted on github.com/gdraheim/zziplib
These routines are fully independent from the traditional zzip implementation. They assume a readonly seekable stdio handle representing a complete zip file. The functions show how to parse the structure, find files and return a decoded bytestream. stdio disk handle
Other than with the mmapped alternative
interface there is no need to build special handle for the zip
disk file. The normal stdio file handle (of type
To get access to a zipped file, you need a zip archive entry known
under the type extern ZZIP_ENTRY* zzip_entry_findfirst(FILE* disk); extern ZZIP_ENTRY* zzip_entry_findnext(ZZIP_ENTRY* entry); extern int zzip_entry_free(ZZIP_ENTRY* entry);
These three calls will allow to walk all zip archive members in the
order listed in the zip central directory. To actually implement a
directory lister ("zzipdir"), you need to get the name string of the
zzip entry. This is not just a pointer: the zzip disk entry is not
null terminated actually. Therefore we have a helper function that
will #include <zzip/fseeko.h> void _zzip_dir(FILE* disk) { for (ZZIP_ENTRY* entry = zzip_findfirst (disk); entry ; entry = zzip_findnext (entry)) { char* name = zzip_entry_strdup_name (entry); puts (name); free (name); } } find a zipped file
The central directory walk can be used to find any file in the
zip archive. The extern ZZIP_ENTRY* zzip_entry_findfile(FILE* disk, char* filename, ZZIP_ENTRY* _zzip_restrict entry, zzip_strcmp_fn_t compare); extern ZZIP_ENTRY* zzip_entry_findmatch(FILE* disk, char* filespec, ZZIP_ENTRY* _zzip_restrict entry, zzip_fnmatch_fn_t compare, int flags);
In general only the first two arguments are non-null pointing to the
stdio disk handle and the file name to look for. The "entry" argument
is an old value and allows you to walk the zip directory similar to
If you do know a specific filename then you can just use
#include <zzip/fseeko.h> /* zzipfseeko already exports this convenience function: */ ZZIP_ENTRY_FILE* zzip_entry_ffile(FILE* disk, char* filename) { return zzip_entry_fopen (zzip_entry_findfile (filename, 0, 0), 1); } int _zzip_read(FILE* disk, char* filename, void* buffer, int bytes) { ZZIP_ENTRY_FILE* file = zzip_entry_ffile (disk, filename); if (! file) return -1; int bytes = zzip_entry_fread (buffer, 1, bytes, file); zzip_entry_fclose (file); return bytes; } reading bytes
The example has shown already how to read some bytes off the head of
a zipped file. In general the zzipfseeko api is used to replace a few
stdio routines that access a file. For that purpose we provide three
functions that look very similar to the stdio functions of
ZZIP_ENTRY_FILE* zzip_entry_ffile (FILE* disk, char* filename); ZZIP_ENTRY_FILE* zzip_entry_fopen (ZZIP_ENTRY* entry, int takeover); zzip_size_t zzip_entry_fread (void* ptr, zzip_size_t sized, zzip_size_t nmemb, ZZIP_ENTRY_FILE* file); int zzip_entry_fclose (ZZIP_ENTRY_FILE* file); int zzip_entry_feof (ZZIP_ENTRY_FILE* file);
In all of the examples you need to remember that you provide a single
stdio ZZIP_ENTRY inspection
The
In reality however it is not a good idea to actually read the bytes
in the extern uint16_t zzip_disk_entry_get_flags( zzip_disk_entry* entry); extern uint16_t zzip_disk_entry_get_compr( zzip_disk_entry* entry); extern uint32_t zzip_disk_entry_get_crc32( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_csize( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_usize( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_namlen( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_extras( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_comment( zzip_disk_entry* entry); extern int zzip_disk_entry_diskstart( zzip_disk_entry* entry); extern int zzip_disk_entry_filetype( zzip_disk_entry* entry); extern int zzip_disk_entry_filemode( zzip_disk_entry* entry); extern zzip_off_t zzip_disk_entry_fileoffset( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_sizeof_tail( zzip_disk_entry* entry); extern zzip_size_t zzip_disk_entry_sizeto_end( zzip_disk_entry* entry); extern char* zzip_disk_entry_skipto_end( zzip_disk_entry* entry);
|