Skip to content

Commit

Permalink
refactor _unzOpen_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Coeur authored and nmoinvaz committed Nov 11, 2024
1 parent 34111e2 commit 8deb028
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions compat/unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "unzip.h"

unzFile _unzOpen_stream(const void *path, void *stream);

/***************************************************************************/

typedef struct mz_unzip_compat_s {
Expand All @@ -41,7 +43,6 @@ unzFile unzOpen64(const void *path) {
}

unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def) {
unzFile unz = NULL;
void *stream = NULL;

if (pzlib_filefunc_def) {
Expand All @@ -57,28 +58,10 @@ unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def) {
}
}

if (!stream) {
stream = mz_stream_os_create();
if (!stream)
return NULL;
}

if (mz_stream_open(stream, path, MZ_OPEN_MODE_READ) != MZ_OK) {
mz_stream_delete(&stream);
return NULL;
}

unz = unzOpen_MZ(stream);
if (!unz) {
mz_stream_close(stream);
mz_stream_delete(&stream);
return NULL;
}
return unz;
return _unzOpen_stream(path, stream);
}

unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def) {
unzFile unz = NULL;
void *stream = NULL;

if (pzlib_filefunc_def) {
Expand All @@ -94,6 +77,12 @@ unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def) {
}
}

return _unzOpen_stream(path, stream);
}

unzFile _unzOpen_stream(const void *path, void *stream) {
unzFile unz = NULL;

if (!stream) {
stream = mz_stream_os_create();
if (!stream)
Expand Down

0 comments on commit 8deb028

Please sign in to comment.