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 mmapped sharedmem block representing a complete zip file. The functions show how to parse the structure, find files and return a decoded bytestream. zzip disk handleOther than with the fseeko alternative interface there is no need to have an actual disk handle to the zip archive. Instead you can use a bytewise copy of a file or even use a mmapped view of a file. This is generally the fastest way to get to the data contained in a zipped file. All it requires is enough of virtual memory space but a desktop computer with a a modern operating system will easily take care of that.
The zzipmmapped library provides a number of calls to create a
disk handle representing a zip archive in virtual memory. Per
default we use the sys/mmap.h (or MappedView) functionality
of the operating system. The ZZIP_DISK* zzip_disk_open(char* filename); int zzip_disk_close(ZZIP_DISK* disk); ZZIP_DISK* zzip_disk_new(void); ZZIP_DISK* zzip_disk_mmap(int fd); int zzip_disk_munmap(ZZIP_DISK* disk); int zzip_disk_init(ZZIP_DISK* disk, char* buffer, zzip_size_t buflen); reading the central directory
To get access to a zipped file, you need a pointer to an entry in the
mmapped zip disk known under the type extern ZZIP_ENTRY* zzip_disk_findfirst(FILE* disk); extern ZZIP_ENTRY* zzip_disk_findnext(ZZIP_ENTRY* entry);
These two 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/mmapped.h> void _zzip_dir(char* filename) { ZZIP_DISK* disk = zzip_disk_open (filename); if (! disk) return disk; for (ZZIP_DISK_ENTRY* entry = zzip_disk_findfirst (disk); entry ; entry = zzip_disk_findnext (entry)) { char* name = zzip_disk_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 ZZIP_DISK_ENTRY* zzip_disk_findfile(ZZIP_DISK* disk, char* filename, ZZIP_DISK_ENTRY* after, zzip_strcmp_fn_t compare); ZZIP_DISK_ENTRY* zzip_disk_findmatch(ZZIP_DISK* disk, char* filespec, ZZIP_ENTRY* after, zzip_fnmatch_fn_t compare, int flags);
In general only the first two arguments are non-null pointing to the
zip disk handle and the file name to look for. The "after" argument
is an old value and allows you to walk the zip directory similar to
If you do know a specific zzipped filename then you can just use
#include <zzip/mmapped.h> int _zzip_read(ZZIP_DISK* disk, char* filename, void* buffer, int bytes) { ZZIP_DISK_FILE* file = zzip_disk_fopen (disk, filename); if (! file) return -1; int bytes = zzip_disk_fread (buffer, 1, bytes, file); zzip_disk_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 zzipmmapped api is used to replace a few
system file routines that access a file. For that purpose we provide three
functions that look very similar to the stdio functions of
ZZIP_DISK_FILE* zzip_disk_entry_fopen (ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry); ZZIP_DISK_FILE* zzip_disk_fopen (ZZIP_DISK* disk, char* filename); zzip_size_t zzip_disk_fread (void* ptr, zzip_size_t sized, zzip_size_t nmemb, ZZIP_DISK_FILE* file); int zzip_disk_fclose (ZZIP_DISK_FILE* file); int zzip_disk_feof (ZZIP_DISK_FILE* file);
In all of the examples you need to remember that you provide a single
ZZIP_DISK_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);
Additionally the char* zzip_disk_entry_to_data(ZZIP_DISK* disk, struct zzip_disk_entry* entry); struct zzip_file_header* zzip_disk_entry_to_file_header(ZZIP_DISK* disk, struct zzip_disk_entry* entry);
|