Proposal:
unzAttach/unzDetach function pair, to make unzip still more flexible.
This will break no existing code.
Details:
ioapi (zlib_filefunc_def) makes it possible to decompress zipfiles
stored in memory.
Such a file, a memory-file, is by definition always open - if you have
a memory-file then you also have a pointer to it. It's open.
To unzip the memory-file, you'll need to call unzOpen2, with a filename
argument (const char*).
What filename?!
You probably have a pointer ready, a 'handle', not a char pointer! You'd probably
prefer to just 'attach' the memory using unzAttach.
I'm providing two implementations of unzAttach/unzDetach:
1. Clean but intrusive implementation inside unzip.c: Very few extra
lines of code, overhead of one extra function call when calling
unzOpen2. See code below.
2. Messy implementation outside unzip.c, using zlib_filefunc_def. Much
overhead. (contrib/unzipx.c)
TRK 19/5 2004
/*
Clean but intrusive
implementation
inside unzip.c.
*/
unzFile ZEXPORT unzOpen2 (path,
pzlib_filefunc_def)
const char
*path;
zlib_filefunc_def* pzlib_filefunc_def;
{
voidpf stream;
unzFile unz = NULL;
zlib_filefunc_def
z_filefunc;
if
(pzlib_filefunc_def == NULL)
fill_fopen_filefunc(&z_filefunc);
else
z_filefunc = *pzlib_filefunc_def;
stream=
(*z_filefunc.zopen_file)(z_filefunc.opaque,
path,
ZLIB_FILEFUNC_MODE_READ |
ZLIB_FILEFUNC_MODE_EXISTING);
if (stream)
{
unz = unzAttach (stream, &z_filefunc);
if
(unz == NULL)
{
ZCLOSE(z_filefunc, stream); /* balance */
}
}
return unz;
}
unzFile ZEXPORT unzAttach (stream, pzlib_filefunc_def)
voidpf stream;
zlib_filefunc_def* pzlib_filefunc_def;
{
/* implementation is just like today's unzOpen2, except zopen_file/ZCLOSE is removed */
}