The RoseInputZipMember class is a subclass of RoseInputStream used to feed parsing code from a member of a Zip archive. This stream requires additional setup C code to open the archive, locate the member and initialize the stream.

The code below provides an outline that you can customize. Be sure to fopen() the zipfile in binary mode on Windows.

#include <rose.h>
#include <rose_zip.h>

void read_zip_member(
    FILE * f,
    const char * member_name
    // Set up the hook functions for zip
    zlib_filefunc_def io_funcs;

    fill_fopen_filefunc (&io_funcs);
    io_funcs.opaque = f;
    io_funcs.zopen_file = rose_iozip_open_stub;
    io_funcs.zclose_file = rose_iozip_close_stub;

    unzFile zf = unzOpen2(0, &io_funcs);
    if (!zf) {
	printf ("Could not scan zip file\n");

    // Return status is UNZ_OK zero if found, UNZ_END_OF_LIST_OF_FILE
    // if not found, or some other code if an error.
    if (unzLocateFile(zf, member_name, 2))
	printf("Could not find %s in zip\n", member_name);

    if (unzOpenCurrentFile(zf)) {
	printf("Could not open %s in zip\n", member_name);
    RoseInputZipMember stream (zf, member_name);
    while ((c=stream.get()) != EOF)
	// process the characters



	void * f,
	const char * nm = 0

The RoseInputFile() constructor has two versions. The default contructor leaves the name and zfile() zip handle fields unset, while the second constructor initializes both fields.

The zip file handle is typed as void*, but should be an unzFile value returned from an unzOpen function.


void * zfile();
void zfile (void* f);

The zfile() function gets and sets the underlying zip file handle that stream data will be read from. This handle is typed as void*, but should be an unzFile value returned from an unzOpen function and then set to a particular member by unzLocateFile() and unzOpenCurrentFile().


virtual size_t refill();

The refill() function reads data from the zip file and uncompresses at most io_size() characters into the I/0 buffer. It returns the number of characters copied.

This is called automatically by get() when it reaches the end of the buffer. This is a virtual function that is overridden by each stream subtype.