Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor _unzOpen_stream #821

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading