Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 27 additions & 1 deletion mz_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1631,11 +1631,37 @@ int32_t mz_zip_get_stream(void *handle, void **stream) {

int32_t mz_zip_set_cd_stream(void *handle, int64_t cd_start_pos, void *cd_stream) {
mz_zip *zip = (mz_zip *)handle;
if (!zip || !cd_stream)
int64_t saved_pos = 0;
int64_t stream_end = 0;
int32_t err = MZ_OK;
int32_t restore_err = MZ_OK;

if (!zip || !cd_stream || cd_start_pos < 0)
return MZ_PARAM_ERROR;

saved_pos = mz_stream_tell(cd_stream);
if (saved_pos < 0)
return (int32_t)saved_pos;

err = mz_stream_seek(cd_stream, 0, MZ_SEEK_END);
if (err == MZ_OK) {
stream_end = mz_stream_tell(cd_stream);
if (stream_end < 0)
err = (int32_t)stream_end;
}

restore_err = mz_stream_seek(cd_stream, saved_pos, MZ_SEEK_SET);
if (err != MZ_OK)
return err;
if (restore_err != MZ_OK)
return restore_err;
if (stream_end < cd_start_pos)
return MZ_PARAM_ERROR;

zip->cd_offset = 0;
zip->cd_stream = cd_stream;
zip->cd_start_pos = cd_start_pos;
zip->cd_size = stream_end - cd_start_pos;
return MZ_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion mz_zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int32_t mz_zip_get_stream(void *handle, void **stream);
/* Get a pointer to the stream used to open */

int32_t mz_zip_set_cd_stream(void *handle, int64_t cd_start_pos, void *cd_stream);
/* Sets the stream to use for reading the central dir */
/* Sets the stream to use for reading the central dir from start pos to the end of the stream */

int32_t mz_zip_get_cd_mem_stream(void *handle, void **cd_mem_stream);
/* Get a pointer to the stream used to store the central dir in memory */
Expand Down
Loading